Skip to content

Commit 771d72e

Browse files
committed
fixup! [REF] *: adapt code to new owl webclient
closes #723 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
1 parent 44301e2 commit 771d72e

File tree

8 files changed

+719
-602
lines changed

8 files changed

+719
-602
lines changed

addons/board/static/tests/dashboard_tests.js

Lines changed: 185 additions & 159 deletions
Large diffs are not rendered by default.

addons/bus/static/tests/assets_watchdog_tests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,5 @@ QUnit.module("Bus Assets WatchDog", (hooks) => {
8282
// reload by clicking on the reload button
8383
await click(webClient.el, ".o_notification_buttons .btn-primary");
8484
assert.verifySteps(["reloadPage"]);
85-
webClient.destroy();
8685
});
8786
});

addons/calendar/static/tests/calendar_notification_tests.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ QUnit.module("Calendar Notification", (hooks) => {
9898
await click(webClient.el.querySelector(".o_notification_buttons .btn"));
9999
assert.verifySteps(["notifyAck"]);
100100
assert.containsNone(webClient.el, ".o_notification");
101-
102-
webClient.destroy();
103101
}
104102
);
105103

@@ -171,8 +169,6 @@ QUnit.module("Calendar Notification", (hooks) => {
171169
await click(webClient.el.querySelectorAll(".o_notification_buttons .btn")[1]);
172170
assert.verifySteps(["calendar.action_calendar_event_notify"]);
173171
assert.containsNone(webClient.el, ".o_notification");
174-
175-
webClient.destroy();
176172
}
177173
);
178174

@@ -232,8 +228,6 @@ QUnit.module("Calendar Notification", (hooks) => {
232228
await click(webClient.el.querySelectorAll(".o_notification_buttons .btn")[2]);
233229
assert.verifySteps([], "should only close the notification withtout calling a rpc");
234230
assert.containsNone(webClient.el, ".o_notification");
235-
236-
webClient.destroy();
237231
}
238232
);
239233
});

addons/mail/static/src/utils/test_utils.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ import AbstractStorageService from 'web.AbstractStorageService';
1818
import NotificationService from 'web.NotificationService';
1919
import RamStorage from 'web.RamStorage';
2020
import {
21-
createActionManager,
2221
createView,
2322
makeTestPromise,
2423
mock,
2524
} from 'web.test_utils';
2625
import Widget from 'web.Widget';
26+
import {
27+
createWebClient,
28+
getActionManagerTestConfig,
29+
} from "@web/../tests/webclient/actions/helpers";
30+
import { ComponentAdapter } from "web.OwlCompatibility";
31+
import LegacyMockServer from "web.MockServer";
2732

2833
const {
2934
addMockEnvironment,
@@ -546,8 +551,36 @@ async function start(param0 = {}) {
546551
}
547552
});
548553
} else if (hasActionManager) {
549-
throw new Error("This is deprecated, should be adapted");
550-
widget = await createActionManager(kwargs);
554+
let testConfig;
555+
if (!kwargs.testConfig) {
556+
testConfig = getActionManagerTestConfig();
557+
} else {
558+
testConfig = kwargs.testConfig;
559+
delete kwargs.testConfig;
560+
}
561+
562+
if (kwargs.actions) {
563+
const actions = {};
564+
kwargs.actions.forEach((act) => {
565+
actions[act.xml_id || act.id] = act;
566+
});
567+
Object.assign(testConfig.serverData.actions, actions);
568+
delete kwargs.actions;
569+
}
570+
571+
Object.assign(testConfig.serverData.views, kwargs.archs);
572+
delete kwargs.archs;
573+
574+
Object.assign(testConfig.serverData.models, kwargs.data);
575+
delete kwargs.data;
576+
577+
const mockRPC = kwargs.mockRPC;
578+
delete kwargs.mockRPC;
579+
580+
const legacyParams = kwargs;
581+
legacyParams.withLegacyMockServer = true;
582+
const widget = await createWebClient({ testConfig, mockRPC, legacyParams });
583+
551584
legacyPatch(widget, {
552585
destroy() {
553586
destroyCallbacks.forEach(callback => callback({ widget }));

addons/mail/static/tests/activity_tests.js

Lines changed: 110 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import ActivityView from '@mail/js/views/activity/activity_view';
44
import testUtils from 'web.test_utils';
5+
import { createWebClient } from "@web/../tests/webclient/actions/helpers";
56

6-
var createActionManager = testUtils.createActionManager;
7+
import { legacyExtraNextTick } from "@web/../tests/helpers/utils";
8+
import { doAction, getActionManagerTestConfig } from "@web/../tests/webclient/actions/helpers";
9+
import { registry } from "@web/core/registry";
10+
import { makeFakeUserService } from "@web/../tests/helpers/mock_services";
11+
12+
let testConfig;
713

814
var createView = testUtils.createView;
915

@@ -108,6 +114,8 @@ QUnit.module('activity view', {
108114
],
109115
},
110116
};
117+
testConfig = getActionManagerTestConfig();
118+
Object.assign(testConfig.serverData.models, this.data);
111119
}
112120
});
113121

@@ -350,49 +358,68 @@ QUnit.test('activity view: activity widget', async function (assert) {
350358

351359
activity.destroy();
352360
});
353-
QUnit.skip('activity view: no group_by_menu and no comparison_menu', async function (assert) {
361+
362+
QUnit.test("activity view: no group_by_menu and no comparison_menu", async function (assert) {
354363
assert.expect(4);
355364

356-
var actionManager = await createActionManager({
357-
actions: [{
358-
id: 1,
359-
name: 'Task Action',
360-
res_model: 'task',
361-
type: 'ir.actions.act_window',
362-
views: [[false, 'activity']],
363-
}],
364-
archs: {
365-
'task,false,activity': '<activity string="Task">' +
366-
'<templates>' +
367-
'<div t-name="activity-box">' +
368-
'<field name="foo"/>' +
369-
'</div>' +
370-
'</templates>' +
371-
'</activity>',
372-
'task,false,search': '<search></search>',
373-
},
374-
data: this.data,
375-
session: {
376-
user_context: {lang: 'zz_ZZ'},
377-
},
378-
mockRPC: function(route, args) {
379-
if (args.method === 'get_activity_data') {
380-
assert.deepEqual(args.kwargs.context, {lang: 'zz_ZZ'},
381-
'The context should have been passed');
382-
}
383-
return this._super.apply(this, arguments);
384-
},
385-
});
365+
testConfig.serverData.actions[1] = {
366+
id: 1,
367+
name: "Task Action",
368+
res_model: "task",
369+
type: "ir.actions.act_window",
370+
views: [[false, "activity"]],
371+
};
386372

387-
await actionManager.doAction(1);
373+
testConfig.serverData.views = {
374+
"task,false,activity":
375+
'<activity string="Task">' +
376+
"<templates>" +
377+
'<div t-name="activity-box">' +
378+
'<field name="foo"/>' +
379+
"</div>" +
380+
"</templates>" +
381+
"</activity>",
382+
"task,false,search": "<search></search>",
383+
};
384+
385+
const mockRPC = (route, args) => {
386+
if (args.method === "get_activity_data") {
387+
assert.strictEqual(
388+
args.kwargs.context.lang,
389+
"zz_ZZ",
390+
"The context should have been passed"
391+
);
392+
}
393+
};
388394

389-
assert.containsN(actionManager, '.o_search_options .o_dropdown button:visible', 2,
390-
"only two elements should be available in view search");
391-
assert.isVisible(actionManager.$('.o_search_options .o_dropdown.o_filter_menu > button'),
392-
"filter should be available in view search");
393-
assert.isVisible(actionManager.$('.o_search_options .o_dropdown.o_favorite_menu > button'),
394-
"favorites should be available in view search");
395-
actionManager.destroy();
395+
registry.category("services").add(
396+
"user",
397+
makeFakeUserService({
398+
session_info: {
399+
user_context: { lang: "zz_ZZ" },
400+
},
401+
}),
402+
{ force: true }
403+
);
404+
405+
const webClient = await createWebClient({ testConfig, mockRPC , legacyParams: {withLegacyMockServer: true}});
406+
407+
await doAction(webClient, 1);
408+
409+
assert.containsN(
410+
webClient,
411+
".o_search_options .o_dropdown button:visible",
412+
2,
413+
"only two elements should be available in view search"
414+
);
415+
assert.isVisible(
416+
$(webClient.el).find(".o_search_options .o_dropdown.o_filter_menu > button"),
417+
"filter should be available in view search"
418+
);
419+
assert.isVisible(
420+
$(webClient.el).find(".o_search_options .o_dropdown.o_favorite_menu > button"),
421+
"favorites should be available in view search"
422+
);
396423
});
397424

398425
QUnit.test('activity view: search more to schedule an activity for a record of a respecting model', async function (assert) {
@@ -458,63 +485,54 @@ QUnit.test('activity view: search more to schedule an activity for a record of a
458485
activity.destroy();
459486
});
460487

461-
QUnit.skip('Activity view: discard an activity creation dialog', async function (assert) {
488+
QUnit.test("Activity view: discard an activity creation dialog", async function (assert) {
462489
assert.expect(2);
463490

464-
var actionManager = await createActionManager({
465-
actions: [{
466-
id: 1,
467-
name: 'Task Action',
468-
res_model: 'task',
469-
type: 'ir.actions.act_window',
470-
views: [[false, 'activity']],
471-
}],
472-
archs: {
473-
'task,false,activity': `
474-
<activity string="Task">
475-
<templates>
476-
<div t-name="activity-box">
477-
<field name="foo"/>
478-
</div>
479-
</templates>
480-
</activity>`,
481-
'task,false,search': '<search></search>',
482-
'mail.activity,false,form': `
483-
<form>
484-
<field name="display_name"/>
485-
<footer>
486-
<button string="Discard" class="btn-secondary" special="cancel"/>
487-
</footer>
488-
</form>`
489-
},
490-
data: this.data,
491-
intercepts: {
492-
do_action(ev) {
493-
actionManager.doAction(ev.data.action, ev.data.options);
494-
}
495-
},
496-
async mockRPC(route, args) {
497-
if (args.method === 'check_access_rights') {
498-
return true;
499-
}
500-
return this._super(...arguments);
501-
},
502-
});
503-
await actionManager.doAction(1);
491+
testConfig.serverData.actions[1] = {
492+
id: 1,
493+
name: "Task Action",
494+
res_model: "task",
495+
type: "ir.actions.act_window",
496+
views: [[false, "activity"]],
497+
};
498+
499+
testConfig.serverData.views = {
500+
"task,false,activity": `
501+
<activity string="Task">
502+
<templates>
503+
<div t-name="activity-box">
504+
<field name="foo"/>
505+
</div>
506+
</templates>
507+
</activity>`,
508+
"task,false,search": "<search></search>",
509+
"mail.activity,false,form": `
510+
<form>
511+
<field name="display_name"/>
512+
<footer>
513+
<button string="Discard" class="btn-secondary" special="cancel"/>
514+
</footer>
515+
</form>`,
516+
};
517+
518+
const mockRPC = (route, args) => {
519+
if (args.method === "check_access_rights") {
520+
return true;
521+
}
522+
};
504523

505-
await testUtils.dom.click(actionManager.$('.o_activity_view .o_data_row .o_activity_empty_cell')[0]);
506-
assert.containsOnce(
507-
$,
508-
'.modal.o_technical_modal.show',
509-
"Activity Modal should be opened");
524+
const webClient = await createWebClient({ testConfig, mockRPC, legacyParams: {withLegacyMockServer: true} });
525+
await doAction(webClient, 1);
510526

511-
await testUtils.dom.click($('.modal.o_technical_modal.show button[special="cancel"]'));
512-
assert.containsNone(
513-
$,
514-
'.modal.o_technical_modal.show',
515-
"Activity Modal should be closed");
527+
await testUtils.dom.click(
528+
$(webClient.el).find(".o_activity_view .o_data_row .o_activity_empty_cell")[0]
529+
);
530+
await legacyExtraNextTick();
531+
assert.containsOnce($, ".modal.o_technical_modal", "Activity Modal should be opened");
516532

517-
actionManager.destroy();
533+
await testUtils.dom.click($('.modal.o_technical_modal button[special="cancel"]'));
534+
await legacyExtraNextTick();
535+
assert.containsNone($, ".modal.o_technical_modal", "Activity Modal should be closed");
518536
});
519537

520538
});

0 commit comments

Comments
 (0)