You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6 KiB

  1. "use strict";
  2. odoo.define_section('web_duplicate_visibility',
  3. ['web.data', 'web.FormView'],
  4. function(test, mock){
  5. function assertDuplicate(data, FormView, form_tag, visible){
  6. mock.add('test.model:read', function () {
  7. return [{ id: 1, a: 'foo', b: 'bar', c: 'baz' }];
  8. });
  9. mock.add('test.model:fields_view_get', function () {
  10. return {
  11. type: 'form',
  12. fields: {
  13. a: {type: 'char', string: "A"},
  14. b: {type: 'char', string: "B"},
  15. c: {type: 'char', string: "C"}
  16. },
  17. arch: form_tag +
  18. ' <field name="a"/>' +
  19. ' <field name="b"/>' +
  20. ' <field name="c"/>' +
  21. '</form>',
  22. };
  23. });
  24. var ds = new data.DataSetStatic(null, 'test.model', null, [1]);
  25. ds.index = 0;
  26. var $fix = $( "#qunit-fixture");
  27. var form = new FormView(
  28. {},
  29. ds,
  30. false,
  31. {
  32. sidebar: true,
  33. }
  34. );
  35. form.appendTo($fix);
  36. form.do_show();
  37. form.render_sidebar();
  38. var $fix = $( "#qunit-fixture");
  39. var actions = $fix.find('.oe_sidebar a[data-section="other"]').filter(
  40. function(i, obj){
  41. return obj.text.trim() == "Duplicate";
  42. }
  43. );
  44. strictEqual(
  45. actions.length, visible, "duplicate state is not as expected"
  46. );
  47. };
  48. test('Duplicate button visible when nothing set',
  49. function(assert, data, FormView){
  50. assertDuplicate(data, FormView, '<form>', 1);
  51. });
  52. test('Duplicate button visible when create="1"',
  53. function(assert, data, FormView){
  54. assertDuplicate(data, FormView, '<form create="1">', 1);
  55. });
  56. test('Duplicate button visible when duplicate="1"',
  57. function(assert, data, FormView){
  58. assertDuplicate(data, FormView, '<form duplicate="1">', 1);
  59. });
  60. test('Duplicate button not displayed when create="0"',
  61. function(assert, data, FormView){
  62. assertDuplicate(data, FormView, '<form create="0">', 0);
  63. });
  64. test('Duplicate button not displayed when create="1" duplicate="0"',
  65. function(assert, data, FormView){
  66. assertDuplicate(data, FormView, '<form create="1" duplicate="0">', 0);
  67. });
  68. test('Duplicate button not displayed when duplicate="0"',
  69. function(assert, data, FormView){
  70. assertDuplicate(data, FormView, '<form duplicate="0">', 0);
  71. });
  72. });