[FIX] board, bus, web: replace deprecated test-utils calls

A number of functions from `web.test_utils` have been deprecated at
the module root and should be called through submodules.

Fix a bunch of remaining cases. Also add a few missing `await`s on
`triggerMouseEvent` calls. Don't bother rewriting the imports in
unpacking style as for most updating the imports is unnecessary. Do so
for `field_one2many_tests.js` where we have to rewrite the imports
anyway:

* recursively import controlPanel, createView, mock.patch and
  mock.unpatch
* remove the aliasing of controlPanel to cpHelpers
This commit is contained in:
Xavier Morel
2021-06-29 05:34:17 +00:00
parent 7d90cfac55
commit 32062a3bbb
9 changed files with 33 additions and 33 deletions
+2 -2
View File
@@ -702,7 +702,7 @@ QUnit.test('dashboard intercepts custom events triggered by sub controllers', as
QUnit.test("save actions to dashboard", async function (assert) {
assert.expect(6);
testUtils.patch(ListController, {
testUtils.mock.patch(ListController, {
getOwnedQueryParams: function () {
var result = this._super.apply(this, arguments);
result.context = {
@@ -773,7 +773,7 @@ QUnit.test("save actions to dashboard", async function (assert) {
await testUtils.fields.editInput($(".o_add_to_board input"), "a name");
await testUtils.dom.click($(".o_add_to_board div button"));
testUtils.unpatch(ListController);
testUtils.mock.unpatch(ListController);
});
QUnit.test("save two searches to dashboard", async function (assert) {
+4 -4
View File
@@ -316,7 +316,7 @@ QUnit.module('Bus', {
assert.expect(5);
let id = 1;
testUtils.patch(CrossTabBus, {
testUtils.mock.patch(CrossTabBus, {
init: function () {
this._super.apply(this, arguments);
this.__tabId__ = id++;
@@ -333,7 +333,7 @@ QUnit.module('Bus', {
let pollPromise;
const parentTab1 = new Widget();
await testUtils.addMockEnvironment(parentTab1, {
await testUtils.mock.addMockEnvironment(parentTab1, {
data: {},
services: {
local_storage: LocalStorageServiceMock,
@@ -350,7 +350,7 @@ QUnit.module('Bus', {
}
});
const parentTab2 = new Widget();
await testUtils.addMockEnvironment(parentTab2, {
await testUtils.mock.addMockEnvironment(parentTab2, {
data: {},
services: {
local_storage: LocalStorageServiceMock,
@@ -382,7 +382,7 @@ QUnit.module('Bus', {
"Tab 2: addChannel beta",
]);
testUtils.unpatch(CrossTabBus);
testUtils.mock.unpatch(CrossTabBus);
parentTab1.destroy();
parentTab2.destroy();
});
@@ -147,7 +147,7 @@ odoo.define('web.datepicker_tests', function (require) {
QUnit.test("Date format is correctly set", async function (assert) {
assert.expect(2);
testUtils.patch(time, { getLangDateFormat: () => "YYYY/MM/DD" });
testUtils.mock.patch(time, { getLangDateFormat: () => "YYYY/MM/DD" });
const picker = await createComponent(DatePicker, {
props: { date: moment('1997-01-09') },
});
@@ -161,7 +161,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.strictEqual(input.value, '1997/01/09');
picker.destroy();
testUtils.unpatch(time);
testUtils.mock.unpatch(time);
});
QUnit.module('DateTimePicker');
@@ -331,7 +331,7 @@ odoo.define('web.datepicker_tests', function (require) {
QUnit.test("Date time format is correctly set", async function (assert) {
assert.expect(2);
testUtils.patch(time, { getLangDatetimeFormat: () => "hh:mm:ss YYYY/MM/DD" });
testUtils.mock.patch(time, { getLangDatetimeFormat: () => "hh:mm:ss YYYY/MM/DD" });
const picker = await createComponent(DateTimePicker, {
props: { date: moment('1997-01-09 12:30:01') },
});
@@ -345,7 +345,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.strictEqual(input.value, '12:30:01 1997/01/09');
picker.destroy();
testUtils.unpatch(time);
testUtils.mock.unpatch(time);
});
});
});
@@ -3910,7 +3910,7 @@ QUnit.module('basic_fields', {
assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 0,
"datepicker should be closed initially");
testUtils.openDatepicker(form.$('.o_datepicker'));
testUtils.dom.openDatepicker(form.$('.o_datepicker'));
assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 1,
"datepicker should be opened");
@@ -4375,7 +4375,7 @@ QUnit.module('basic_fields', {
var dateViewForm = form.$('.o_field_date').text();
await testUtils.dom.click(form.$buttons.find('.o_form_button_edit'));
await testUtils.openDatepicker(form.$('.o_datepicker'));
await testUtils.dom.openDatepicker(form.$('.o_datepicker'));
assert.strictEqual(form.$('.o_datepicker_input').val(), dateViewForm,
"input date field should be the same as it was in the view form");
@@ -7564,7 +7564,7 @@ QUnit.module('basic_fields', {
var top = $progressBarEl.offset().top + 5;
var left = $progressBarEl.offset().left + 5;
try {
testUtils.triggerPositionalMouseEvent(left, top, "click");
testUtils.dom.triggerPositionalMouseEvent(left, top, "click");
} catch (e) {
form.destroy();
$view.remove();
@@ -7611,7 +7611,7 @@ QUnit.module('basic_fields', {
var top = $progressBarEl.offset().top + 5;
var left = $progressBarEl.offset().left + 5;
try {
testUtils.triggerPositionalMouseEvent(left, top, "click");
testUtils.dom.triggerPositionalMouseEvent(left, top, "click");
} catch (e) {
form.destroy();
$view.remove();
@@ -9702,7 +9702,7 @@ QUnit.module('fields', {}, function () {
assert.expect(2);
let o2m;
testUtils.patch(FieldOne2Many, {
testUtils.mock.patch(FieldOne2Many, {
init() {
this._super(...arguments);
o2m = this;
@@ -9729,7 +9729,7 @@ QUnit.module('fields', {}, function () {
assert.strictEqual(o2m.recordData.display_name, "val");
form.destroy();
testUtils.unpatch(FieldOne2Many);
testUtils.mock.unpatch(FieldOne2Many);
});
QUnit.test('nested one2many, onchange, no command value', async function (assert) {
@@ -873,7 +873,7 @@ QUnit.module('relational_fields', {
</form>`,
config: {device: {isMobile: false}},
});
testUtils.intercept(form, 'call_service', function (ev) {
testUtils.mock.intercept(form, 'call_service', function (ev) {
assert.strictEqual(ev.data.service, 'notification',
"should display an 'invalid fields' notification");
}, true);
@@ -1482,7 +1482,7 @@ QUnit.module('relational_fields', {
assert.containsN(list, '.o_field_many2manytags .badge', 2, "there should be 2 tags");
assert.containsNone(list, '.badge.dropdown-toggle', "the tags should not be dropdowns");
testUtils.intercept(list, 'switch_view', function (event) {
testUtils.mock.intercept(list, 'switch_view', function (event) {
assert.strictEqual(event.data.view_type, "form", "should switch to form view");
});
// click on the tag: should do nothing and open the form view
@@ -2972,7 +2972,7 @@ QUnit.module('Views', {
assert.strictEqual(calendar.$('.o_field_widget[name="start"]').text(), "12/16/2016 16:00:00");
// Move event 6 as on first day of month view (27th november 2016)
await testUtils.dragAndDrop(
await testUtils.dom.dragAndDrop(
calendar.$('.fc-event').eq(5),
calendar.$('.fc-day-top').first()
);
@@ -3023,8 +3023,8 @@ QUnit.module('Views', {
// Create event (on 20 december)
var $cell = calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day:eq(2)');
await testUtils.triggerMouseEvent($cell, "mousedown");
await testUtils.triggerMouseEvent($cell, "mouseup");
await testUtils.dom.triggerMouseEvent($cell, "mousedown");
await testUtils.dom.triggerMouseEvent($cell, "mouseup");
await testUtils.nextTick();
var $input = $('.modal-body input:first');
await testUtils.fields.editInput($input, "An event");
@@ -3036,7 +3036,7 @@ QUnit.module('Views', {
assert.strictEqual(calendar.$('.o_cw_popover .o_cw_popover_fields_secondary .list-group-item:last .o_field_date').text(), '12/20/2016', "should have correct start date");
// Move event to another day (on 27 november)
await testUtils.dragAndDrop(
await testUtils.dom.dragAndDrop(
calendar.$('.fc-event').first(),
calendar.$('.fc-day-top').first()
);
@@ -3047,7 +3047,7 @@ QUnit.module('Views', {
assert.strictEqual(calendar.$('.o_cw_popover .o_cw_popover_fields_secondary .list-group-item:last .o_field_date').text(), '11/27/2016', "should have correct start date");
// Move event to last day (on 7 january)
await testUtils.dragAndDrop(
await testUtils.dom.dragAndDrop(
calendar.$('.fc-event').first(),
calendar.$('.fc-day-top').last()
);
@@ -3077,8 +3077,8 @@ QUnit.module('Views', {
// Create event (on 20 december)
var $cell = calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day:eq(2)');
testUtils.triggerMouseEvent($cell, "mousedown");
testUtils.triggerMouseEvent($cell, "mouseup");
await testUtils.dom.triggerMouseEvent($cell, "mousedown");
await testUtils.dom.triggerMouseEvent($cell, "mouseup");
await testUtils.nextTick();
var $input = $('.modal-body input:first');
await testUtils.fields.editInput($input, "An event");
@@ -3086,7 +3086,7 @@ QUnit.module('Views', {
await testUtils.nextTick();
// Move event to another day (on 19 december)
await testUtils.dragAndDrop(
await testUtils.dom.dragAndDrop(
calendar.$('.fc-event:contains("An event")'),
calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day-top:eq(1)')
);
@@ -3121,8 +3121,8 @@ QUnit.module('Views', {
// Create event (on 20 december)
var $cell = calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day:eq(2)');
testUtils.triggerMouseEvent($cell, "mousedown");
testUtils.triggerMouseEvent($cell, "mouseup");
await testUtils.dom.triggerMouseEvent($cell, "mousedown");
await testUtils.dom.triggerMouseEvent($cell, "mouseup");
await testUtils.nextTick();
var $input = $('.modal-body input:first');
await testUtils.fields.editInput($input, "An event");
@@ -3190,8 +3190,8 @@ QUnit.module('Views', {
// Create event (on 20 december)
var $cell = calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day:eq(2)');
await testUtils.triggerMouseEvent($cell, "mousedown");
await testUtils.triggerMouseEvent($cell, "mouseup");
await testUtils.dom.triggerMouseEvent($cell, "mousedown");
await testUtils.dom.triggerMouseEvent($cell, "mouseup");
await testUtils.nextTick();
var $input = $('.modal-body input:first');
await testUtils.fields.editInput($input, "An event");
@@ -3199,7 +3199,7 @@ QUnit.module('Views', {
await testUtils.nextTick();
// Move event to another day (on 27 november)
await testUtils.dragAndDrop(
await testUtils.dom.dragAndDrop(
calendar.$('.fc-event').first(),
calendar.$('.fc-day-top').first()
);
@@ -2987,7 +2987,7 @@ QUnit.module('Views', {
// drag&drop a record in another column
var $record = kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record:first');
var $group = kanban.$('.o_kanban_group:nth-child(2)');
await testUtils.dragAndDrop($record, $group);
await testUtils.dom.dragAndDrop($record, $group);
// should not drag&drop record
assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length , 2,
@@ -182,7 +182,7 @@ QUnit.module('ModelFieldSelector', {
readonly: false,
debugMode: true,
});
await testUtils.addMockEnvironment(fieldSelector, {data: this.data});
await testUtils.mock.addMockEnvironment(fieldSelector, {data: this.data});
await fieldSelector.appendTo($target);
// Focusing the field selector input should open a field selector popover