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.

78 lines
2.5 KiB

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