summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/widgets
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-03-11 09:38:30 +0000
committerJulien Mougenot <jum@odoo.com>2020-03-13 14:08:33 +0000
commit804507ef4925cafdf5349a3b7fa1e41dbca87ff7 (patch)
tree09a097ffb347dae1c9dc7879be261ec734f70d4f /addons/web/static/tests/widgets
parentbb8eb766a84b9fd06007d3fb4ab9a29b70097738 (diff)
[REF] *: Adapt all module tests to the new control panel
Use of the new control panel helpers to increase consistency and change the assertions according to the new DOM/behaviour (e.g. components removed instead of turning invisible). Part of task 2196029 Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/tests/widgets')
-rw-r--r--addons/web/static/tests/widgets/data_export_tests.js38
-rw-r--r--addons/web/static/tests/widgets/dropdown_menu_tests.js203
2 files changed, 22 insertions, 219 deletions
diff --git a/addons/web/static/tests/widgets/data_export_tests.js b/addons/web/static/tests/widgets/data_export_tests.js
index c9c51219571..2d3488f5891 100644
--- a/addons/web/static/tests/widgets/data_export_tests.js
+++ b/addons/web/static/tests/widgets/data_export_tests.js
@@ -1,12 +1,13 @@
odoo.define('web.data_export_tests', function (require) {
"use strict";
-var framework = require('web.framework');
-var ListView = require('web.ListView');
-var testUtils = require('web.test_utils');
-var data = require('web.data');
+const framework = require('web.framework');
+const ListView = require('web.ListView');
+const testUtils = require('web.test_utils');
+const data = require('web.data');
-var createView = testUtils.createView;
+const cpHelpers = testUtils.controlPanel;
+const createView = testUtils.createView;
QUnit.module('widgets', {
beforeEach: function () {
@@ -63,7 +64,7 @@ QUnit.module('widgets', {
data: this.data,
arch: '<tree><field name="foo"/></tree>',
viewOptions: {
- hasSidebar: true,
+ hasActionMenus: true,
},
mockRPC: function (route) {
if (route === '/web/export/formats') {
@@ -104,9 +105,11 @@ QUnit.module('widgets', {
},
});
+
await testUtils.dom.click(list.$('thead th.o_list_record_selector input'));
- await testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)'));
- await testUtils.dom.click(list.sidebar.$('a:contains(Export)'));
+
+ await cpHelpers.toggleActionMenu(list);
+ await cpHelpers.toggleMenuItem(list, 'Export');
assert.strictEqual($('.modal').length, 1, "a modal dialog should be open");
assert.strictEqual($('div.o_tree_column:contains(Activities)').length, 1,
@@ -144,7 +147,7 @@ QUnit.module('widgets', {
data: this.data,
arch: '<tree><field name="foo"/></tree>',
viewOptions: {
- hasSidebar: true,
+ hasActionMenus: true,
},
mockRPC: function (route) {
if (route === '/web/export/formats') {
@@ -179,10 +182,12 @@ QUnit.module('widgets', {
},
});
+
// Open the export modal
await testUtils.dom.click(list.$('thead th.o_list_record_selector input'));
- await testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)'));
- await testUtils.dom.click(list.sidebar.$('a:contains(Export)'));
+ await cpHelpers.toggleActionMenu(list);
+ await cpHelpers.toggleMenuItem(list, 'Export');
+
assert.strictEqual($('.modal').length, 1,
"a modal dialog should be open");
@@ -214,7 +219,7 @@ QUnit.module('widgets', {
data: this.data,
arch: '<tree><field name="foo"/></tree>',
viewOptions: {
- hasSidebar: true,
+ hasActionMenus: true,
},
mockRPC: function (route) {
if (route === '/web/export/formats') {
@@ -248,10 +253,12 @@ QUnit.module('widgets', {
return this._super.apply(this, arguments);
},
});
+
+
// Open the export modal
- await testUtils.dom.click(list.$('thead .o_list_record_selector input'));
- await testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)'));
- await testUtils.dom.click(list.sidebar.$('a:contains(Export)'));
+ await testUtils.dom.click(list.$('thead th.o_list_record_selector input'));
+ await cpHelpers.toggleActionMenu(list);
+ await cpHelpers.toggleMenuItem(list, 'Export');
assert.strictEqual($('.modal .o_export_tree_item:visible').length, 2, "There should be only two items visible");
await testUtils.dom.click($('.modal .o_export_search_input'));
@@ -333,7 +340,6 @@ QUnit.module('widgets', {
View: ListView,
model: 'partner',
data: this.data,
- debug: true,
arch: `
<tree>
<field name="foo"/>
diff --git a/addons/web/static/tests/widgets/dropdown_menu_tests.js b/addons/web/static/tests/widgets/dropdown_menu_tests.js
deleted file mode 100644
index ff53b3d77e8..00000000000
--- a/addons/web/static/tests/widgets/dropdown_menu_tests.js
+++ /dev/null
@@ -1,203 +0,0 @@
-odoo.define('web.dropdown_menu_tests', function (require) {
-"use strict";
-
-var DropdownMenu = require('web.DropdownMenu');
-var testUtils = require('web.test_utils');
-
-function createDropdownMenu(items, params) {
- params = params || {};
- var target = params.debug ? document.body : $('#qunit-fixture');
- var menu = new DropdownMenu(null, items);
- testUtils.mock.addMockEnvironment(menu, params);
- return menu.appendTo(target).then(function() {
- return menu;
- });
-}
-
-QUnit.module('Web', {
- beforeEach: function () {
- this.items = [
- {
- isActive: false,
- description: 'Some Item',
- id: 1,
- groupId: 1,
- groupNumber: 1,
- },
- {
- isActive: true,
- description: 'Some other Item',
- id: 2,
- groupId: 2,
- groupNumber: 2,
- },
- ];
- },
-}, function () {
- QUnit.module('DropdownMenu');
-
- QUnit.test('simple rendering', async function (assert) {
- assert.expect(4);
-
- 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',
- 'first element should have "Some Item" description');
- assert.ok(!dropdownMenu.$('.o_menu_item > .dropdown-item').eq(0).hasClass('selected'),
- 'first element should not be selected');
- assert.ok(dropdownMenu.$('.o_menu_item > .dropdown-item').eq(1).hasClass('selected'),
- 'second element should be selected');
-
- dropdownMenu.destroy();
- });
-
- QUnit.test('click on an item without options should toggle it', async function (assert) {
- assert.expect(7);
-
- var self = this;
- var dropdownMenu = await createDropdownMenu(this.items, {
- intercepts: {
- menu_item_clicked: function (ev) {
- assert.strictEqual(ev.data.id, 1);
- self.items[0].isActive = !self.items[0].isActive;
- dropdownMenu.update(self.items);
- },
- },
- });
- await testUtils.dom.click(dropdownMenu.$('button:first'));
- assert.doesNotHaveClass(dropdownMenu.$('.o_menu_item:first > .dropdown-item').first(), 'selected');
- 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');
- 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', async function (assert) {
- assert.expect(0);
-
- 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');
- });
- await testUtils.dom.click(dropdownMenu.$('.o_menu_item a').first());
-
- dropdownMenu.destroy();
- });
-
- QUnit.test('options rendering', async function (assert) {
- assert.expect(3);
-
- this.items[0].hasOptions = true;
- this.items[0].options = [
- {optionId: 1, description: "First Option", groupId: 1},
- {optionId: 2, description: "Second Option", groupId: 1}
- ];
- this.items[0].currentOptionIds = new Set();
- 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
- await testUtils.dom.click(dropdownMenu.$('span.fa-caret-right'));
- assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 7);
- // close options menu
- 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', async function (assert) {
- assert.expect(2);
-
- this.items[0].hasOptions = true;
- this.items[0].options = [
- {optionId: 1, description: "First Option"},
- {optionId: 2, description: "Second Option"}
- ];
- this.items[0].currentOptionIds = new Set();
- var dropdownMenu = await createDropdownMenu(this.items);
- // open dropdown menu
- testUtils.dom.click(dropdownMenu.$('button:first'));
- // open options menu
- await testUtils.dom.click(dropdownMenu.$('span.fa-caret-right'));
- assert.containsN(dropdownMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 7);
- 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', async function (assert) {
- assert.expect(18);
-
- var self = this;
- var eventNumber = 0;
- this.items[0].hasOptions = true;
- this.items[0].options = [
- {optionId: 1, description: "First Option"},
- {optionId: 2, description: "Second Option"}
- ];
- this.items[0].currentOptionIds = new Set();
- var dropdownMenu = await createDropdownMenu(this.items, {
- intercepts: {
- item_option_clicked: function (ev) {
- eventNumber++;
- assert.strictEqual(ev.data.id, 1);
- if (eventNumber === 1) {
- assert.strictEqual(ev.data.optionId, 1);
- self.items[0].isActive = true;
- self.items[0].currentOptionIds.add(1);
- }
- if (eventNumber === 2) {
- assert.strictEqual(ev.data.optionId, 2);
- self.items[0].currentOptionIds = new Set([1,2]);
- }
- if (eventNumber === 3) {
- assert.strictEqual(ev.data.optionId, 1);
- self.items[0].currentOptionIds = new Set([2]);
- }
- if (eventNumber === 4) {
- assert.strictEqual(ev.data.optionId, 2);
- self.items[0].isActive = false;
- self.items[0].currentOptionIds.clear();
- }
- dropdownMenu.update(self.items);
- },
- },
- });
- await testUtils.nextTick();
- // open dropdown menu
- await testUtils.dom.click(dropdownMenu.$('button:first'));
- assert.containsN(dropdownMenu, '.dropdown-divider, .o_menu_item', 4);
- await testUtils.dom.clickFirst(dropdownMenu.$('.o_menu_item'));
- // click on first option
- 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
- await testUtils.dom.click($('.o_item_option > .dropdown-item').eq(1));
- assert.hasClass(dropdownMenu.$('.o_menu_item > .dropdown-item').first(), 'selected');
- assert.hasClass(dropdownMenu.$('.o_item_option > .dropdown-item').eq(0), 'selected');
- assert.hasClass(dropdownMenu.$('.o_item_option > .dropdown-item').eq(1), 'selected');
- // click again on first option
- await testUtils.dom.click(dropdownMenu.$('.o_item_option > .dropdown-item').eq(0));
- // click again on second option
- 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');
-
- dropdownMenu.destroy();
- });
-});
-});