|
| 1 | +"use strict"; |
| 2 | +odoo.define_section('web_duplicate_visibility', |
| 3 | + ['web.data', 'web.FormView'], |
| 4 | + function(test, mock){ |
| 5 | + |
| 6 | + function assertDuplicate(data, FormView, form_tag, visible){ |
| 7 | + mock.add('test.model:read', function () { |
| 8 | + return [{ id: 1, a: 'foo', b: 'bar', c: 'baz' }]; |
| 9 | + }); |
| 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 | + |
| 27 | + var ds = new data.DataSetStatic(null, 'test.model', null, [1]); |
| 28 | + ds.index = 0; |
| 29 | + var $fix = $( "#qunit-fixture"); |
| 30 | + var form = new FormView( |
| 31 | + {}, |
| 32 | + ds, |
| 33 | + false, |
| 34 | + { |
| 35 | + sidebar: true, |
| 36 | + } |
| 37 | + ); |
| 38 | + form.appendTo($fix); |
| 39 | + form.do_show(); |
| 40 | + form.render_sidebar(); |
| 41 | + |
| 42 | + var $fix = $( "#qunit-fixture"); |
| 43 | + var actions = $fix.find('.oe_sidebar a[data-section="other"]').filter( |
| 44 | + function(i, obj){ |
| 45 | + return obj.text.trim() == "Duplicate"; |
| 46 | + } |
| 47 | + ); |
| 48 | + strictEqual( |
| 49 | + actions.length, visible, "duplicate state is not as expected" |
| 50 | + ); |
| 51 | + }; |
| 52 | + |
| 53 | + test('Duplicate button visible when nothing set', |
| 54 | + function(assert, data, FormView){ |
| 55 | + assertDuplicate(data, FormView, '<form>', 1); |
| 56 | + }); |
| 57 | + |
| 58 | + test('Duplicate button visible when create="1"', |
| 59 | + function(assert, data, FormView){ |
| 60 | + assertDuplicate(data, FormView, '<form create="1">', 1); |
| 61 | + }); |
| 62 | + |
| 63 | + test('Duplicate button visible when duplicate="1"', |
| 64 | + function(assert, data, FormView){ |
| 65 | + assertDuplicate(data, FormView, '<form duplicate="1">', 1); |
| 66 | + }); |
| 67 | + |
| 68 | + test('Duplicate button not displayed when create="0"', |
| 69 | + function(assert, data, FormView){ |
| 70 | + assertDuplicate(data, FormView, '<form create="0">', 0); |
| 71 | + }); |
| 72 | + |
| 73 | + test('Duplicate button not displayed when create="1" duplicate="0"', |
| 74 | + function(assert, data, FormView){ |
| 75 | + assertDuplicate(data, FormView, '<form create="1" duplicate="0">', 0); |
| 76 | + }); |
| 77 | + |
| 78 | + test('Duplicate button not displayed when duplicate="0"', |
| 79 | + function(assert, data, FormView){ |
| 80 | + assertDuplicate(data, FormView, '<form duplicate="0">', 0); |
| 81 | + }); |
| 82 | +}); |
0 commit comments