diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2019-03-06 14:02:32 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-03-06 20:07:17 +0100 |
| commit | ab56e637b7f97ddcdbcc9baea99ae097e342409c (patch) | |
| tree | 4cb47da9f7ef89b19d18429220a7507470ec12a9 /addons/web/static/tests/widgets/dropdown_menu_tests.js | |
| parent | eeed894fd50e477135e1ac9a82f6e98ce063ab90 (diff) | |
[REF] web: adapt code after jQuery update
Part of task 1896658
Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
Diffstat (limited to 'addons/web/static/tests/widgets/dropdown_menu_tests.js')
| -rw-r--r-- | addons/web/static/tests/widgets/dropdown_menu_tests.js | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/addons/web/static/tests/widgets/dropdown_menu_tests.js b/addons/web/static/tests/widgets/dropdown_menu_tests.js index 709651c7cb1..c632d1b7307 100644 --- a/addons/web/static/tests/widgets/dropdown_menu_tests.js +++ b/addons/web/static/tests/widgets/dropdown_menu_tests.js @@ -9,8 +9,9 @@ function createDropdownMenu(items, params) { var target = params.debug ? document.body : $('#qunit-fixture'); var menu = new DropdownMenu(null, items); testUtils.mock.addMockEnvironment(menu, params); - menu.appendTo(target); - return menu; + return menu.appendTo(target).then(function() { + return menu; + }); } QUnit.module('Web', { @@ -35,10 +36,10 @@ QUnit.module('Web', { }, function () { QUnit.module('DropdownMenu'); - QUnit.test('simple rendering', function (assert) { + QUnit.test('simple rendering', async function (assert) { assert.expect(4); - var dropdownMenu = createDropdownMenu(this.items); + var dropdownMenu = await createDropdownMenu(this.items); assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 4, 'should have 4 elements counting the dividers'); assert.strictEqual(dropdownMenu.$('.o_menu_item').first().text().trim(), 'Some Item', @@ -51,11 +52,11 @@ QUnit.module('Web', { dropdownMenu.destroy(); }); - QUnit.test('click on an item without options should toggle it', function (assert) { + QUnit.test('click on an item without options should toggle it', async function (assert) { assert.expect(7); var self = this; - var dropdownMenu = createDropdownMenu(this.items, { + var dropdownMenu = await createDropdownMenu(this.items, { intercepts: { menu_item_clicked: function (ev) { assert.strictEqual(ev.data.id, 1); @@ -64,34 +65,34 @@ QUnit.module('Web', { }, }, }); - testUtils.dom.click(dropdownMenu.$('button:first')); + await testUtils.dom.click(dropdownMenu.$('button:first')); assert.doesNotHaveClass(dropdownMenu.$('.o_menu_item:first > .dropdown-item').first(), 'selected'); - testUtils.dom.click(dropdownMenu.$('.o_menu_item a').first()); + await testUtils.dom.click(dropdownMenu.$('.o_menu_item a').first()); assert.hasClass(dropdownMenu.$('.o_menu_item:first > .dropdown-item'), 'selected'); assert.ok(dropdownMenu.$('.o_menu_item:first').is(':visible'), 'item should still be visible'); - testUtils.dom.click(dropdownMenu.$('.o_menu_item a').first()); + await testUtils.dom.click(dropdownMenu.$('.o_menu_item a').first()); assert.doesNotHaveClass(dropdownMenu.$('.o_menu_item:first > .dropdown-item').first(), 'selected'); assert.ok(dropdownMenu.$('.o_menu_item:first').is(':visible'), 'item should still be visible'); dropdownMenu.destroy(); }); - QUnit.test('click on an item should not change url', function (assert) { + QUnit.test('click on an item should not change url', async function (assert) { assert.expect(0); - var dropdownMenu = createDropdownMenu(this.items); - testUtils.dom.click(dropdownMenu.$('.o_dropdown_toggler_btn')); + var dropdownMenu = await createDropdownMenu(this.items); + await testUtils.dom.click(dropdownMenu.$('.o_dropdown_toggler_btn')); dropdownMenu.$el.click(function () { // we do not want a click to get out and change the url, for example throw new Error('No click should get out of the dropdown menu'); }); - testUtils.dom.click(dropdownMenu.$('.o_menu_item a').first()); + await testUtils.dom.click(dropdownMenu.$('.o_menu_item a').first()); dropdownMenu.destroy(); }); - QUnit.test('options rendering', function (assert) { + QUnit.test('options rendering', async function (assert) { assert.expect(3); this.items[0].hasOptions = true; @@ -99,20 +100,20 @@ QUnit.module('Web', { {optionId: 1, description: "First Option", groupId: 1}, {optionId: 2, description: "Second Option", groupId: 1} ]; - var dropdownMenu = createDropdownMenu(this.items); + var dropdownMenu = await createDropdownMenu(this.items); testUtils.dom.click(dropdownMenu.$('button:first')); assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 4); // open options menu - testUtils.dom.click(dropdownMenu.$('span.fa-caret-right')); + await testUtils.dom.click(dropdownMenu.$('span.fa-caret-right')); assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 7); // close options menu - testUtils.dom.click(dropdownMenu.$('span.fa-caret-down')); + await testUtils.dom.click(dropdownMenu.$('span.fa-caret-down')); assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 4); dropdownMenu.destroy(); }); - QUnit.test('close menu closes also submenus', function (assert) { + QUnit.test('close menu closes also submenus', async function (assert) { assert.expect(2); this.items[0].hasOptions = true; @@ -120,20 +121,20 @@ QUnit.module('Web', { {optionId: 1, description: "First Option"}, {optionId: 2, description: "Second Option"} ]; - var dropdownMenu = createDropdownMenu(this.items); + var dropdownMenu = await createDropdownMenu(this.items); // open dropdown menu testUtils.dom.click(dropdownMenu.$('button:first')); // open options menu - testUtils.dom.click(dropdownMenu.$('span.fa-caret-right')); + await testUtils.dom.click(dropdownMenu.$('span.fa-caret-right')); assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 7); - testUtils.dom.click(dropdownMenu.$('button:first')); - testUtils.dom.click(dropdownMenu.$('button:first')); + await testUtils.dom.click(dropdownMenu.$('button:first')); + await testUtils.dom.click(dropdownMenu.$('button:first')); assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 4); dropdownMenu.destroy(); }); - QUnit.test('click on an option should trigger the event "item_option_clicked" with appropriate data', function (assert) { + QUnit.test('click on an option should trigger the event "item_option_clicked" with appropriate data', async function (assert) { assert.expect(16); var self = this; @@ -143,7 +144,7 @@ QUnit.module('Web', { {optionId: 1, description: "First Option"}, {optionId: 2, description: "Second Option"} ]; - var dropdownMenu = createDropdownMenu(this.items, { + var dropdownMenu = await createDropdownMenu(this.items, { intercepts: { item_option_clicked: function (ev) { eventNumber++; @@ -166,22 +167,23 @@ QUnit.module('Web', { }, }, }); + await testUtils.nextTick(); // open dropdown menu - testUtils.dom.click(dropdownMenu.$('button:first')); + await testUtils.dom.click(dropdownMenu.$('button:first')); assert.containsN(dropdownMenu, '.dropdown-divider, .o_menu_item', 4); - testUtils.dom.clickFirst(dropdownMenu.$('.o_menu_item')); + await testUtils.dom.clickFirst(dropdownMenu.$('.o_menu_item')); // click on first option - testUtils.dom.click(dropdownMenu.$('.o_item_option > .dropdown-item').eq(0)); + await testUtils.dom.click(dropdownMenu.$('.o_item_option > .dropdown-item').eq(0)); assert.hasClass(dropdownMenu.$('.o_menu_item > .dropdown-item').first(), 'selected'); assert.hasClass(dropdownMenu.$('.o_item_option> .dropdown-item').eq(0),'selected'); assert.doesNotHaveClass(dropdownMenu.$('.o_item_option > .dropdown-item').eq(1), 'selected'); // click on second option - testUtils.dom.click($('.o_item_option > .dropdown-item').eq(1)); + await testUtils.dom.click($('.o_item_option > .dropdown-item').eq(1)); assert.hasClass(dropdownMenu.$('.o_menu_item > .dropdown-item').first(), 'selected'); assert.doesNotHaveClass(dropdownMenu.$('.o_item_option > .dropdown-item').eq(0), 'selected'); assert.hasClass(dropdownMenu.$('.o_item_option > .dropdown-item').eq(1), 'selected'); // click again on second option - testUtils.dom.click($('.o_item_option > .dropdown-item').eq(1)); + await testUtils.dom.click($('.o_item_option > .dropdown-item').eq(1)); assert.doesNotHaveClass(dropdownMenu.$('.o_menu_item > .dropdown-item').first(), 'selected'); assert.doesNotHaveClass(dropdownMenu.$('.o_item_option > .dropdown-item').eq(0), 'selected'); assert.doesNotHaveClass(dropdownMenu.$('.o_item_option > .dropdown-item').eq(1), 'selected'); |
