Skip to content

Commit 2f7b6ea

Browse files
alexkuhnvchu-odoo
authored andcommitted
[REF] mail, web, *: replace deprecated asyncStep() in tests
The functions `asyncStep()` and `waitForSteps()` are deprecated. This commit replace by equivalent code with newer syntax, i.e. `expect.step()` and `expect.waitForStep()`. closes odoo#232919 Related: odoo/enterprise#98004 Signed-off-by: Sébastien Theys (seb) <[email protected]>
1 parent e572db9 commit 2f7b6ea

File tree

77 files changed

+776
-971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+776
-971
lines changed

addons/account/static/tests/account_move_form.test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
openFormView,
55
start,
66
startServer,
7-
triggerHotkey
7+
triggerHotkey,
88
} from "@mail/../tests/mail_test_helpers";
99
import { expect, test } from "@odoo/hoot";
10-
import { asyncStep, contains, onRpc, waitForSteps } from "@web/../tests/web_test_helpers";
10+
import { contains, onRpc } from "@web/../tests/web_test_helpers";
1111
import { defineAccountModels } from "./account_test_helpers";
1212

1313
defineAccountModels();
@@ -17,7 +17,7 @@ test("When I switch tabs, it saves", async () => {
1717
const accountMove = pyEnv["account.move"].create({ name: "move0" });
1818
await start();
1919
onRpc("account.move", "web_save", () => {
20-
asyncStep("tab saved");
20+
expect.step("tab saved");
2121
});
2222
await openFormView("account.move", accountMove, {
2323
arch: `<form js_class='account_move_form'>
@@ -34,16 +34,14 @@ test("When I switch tabs, it saves", async () => {
3434
await insertText("[name='name'] input", "somebody save me!");
3535
triggerHotkey("Enter");
3636
await click('a[name="aml_tab"]');
37-
await waitForSteps(["tab saved"]);
37+
await expect.waitForSteps(["tab saved"]);
3838
});
3939

4040
test("Confirmation dialog on delete contains a warning", async () => {
4141
const pyEnv = await startServer();
4242
const accountMove = pyEnv["account.move"].create({ name: "move0" });
4343
await start();
44-
onRpc("account.move", "check_move_sequence_chain", () => {
45-
return false;
46-
});
44+
onRpc("account.move", "check_move_sequence_chain", () => false);
4745
await openFormView("account.move", accountMove, {
4846
arch: `<form js_class='account_move_form'>
4947
<sheet>
@@ -58,7 +56,8 @@ test("Confirmation dialog on delete contains a warning", async () => {
5856
});
5957
await contains(".o_cp_action_menus button").click();
6058
await contains(".o_menu_item:contains(Delete)").click();
61-
expect(".o_dialog div.text-danger").toHaveText("This operation will create a gap in the sequence.", {
62-
message: "warning message has been added in the dialog"
63-
});
59+
expect(".o_dialog div.text-danger").toHaveText(
60+
"This operation will create a gap in the sequence.",
61+
{ message: "warning message has been added in the dialog" }
62+
);
6463
});
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import { describe, test } from "@odoo/hoot";
1+
import { describe, expect, test } from "@odoo/hoot";
22
import { runAllTimers, waitFor } from "@odoo/hoot-dom";
3-
import {
4-
asyncStep,
5-
contains,
6-
getService,
7-
MockServer,
8-
mountWithCleanup,
9-
waitForSteps,
10-
} from "@web/../tests/web_test_helpers";
3+
import { contains, getService, MockServer, mountWithCleanup } from "@web/../tests/web_test_helpers";
114
import { browser } from "@web/core/browser/browser";
125
import { WebClient } from "@web/webclient/webclient";
136
import { defineBusModels } from "./bus_test_helpers";
@@ -16,15 +9,15 @@ defineBusModels();
169
describe.current.tags("desktop");
1710

1811
test("can listen on bus and display notifications in DOM", async () => {
19-
browser.location.addEventListener("reload", () => asyncStep("reload-page"));
12+
browser.location.addEventListener("reload", () => expect.step("reload-page"));
2013
await mountWithCleanup(WebClient);
21-
getService("bus_service").subscribe("bundle_changed", () => asyncStep("bundle_changed"));
14+
getService("bus_service").subscribe("bundle_changed", () => expect.step("bundle_changed"));
2215
MockServer.env["bus.bus"]._sendone("broadcast", "bundle_changed", {
2316
server_version: "NEW_MAJOR_VERSION",
2417
});
25-
await waitForSteps(["bundle_changed"]);
18+
await expect.waitForSteps(["bundle_changed"]);
2619
await runAllTimers();
2720
await waitFor(".o_notification", { text: "The page appears to be out of date." });
2821
await contains(".o_notification button:contains(Refresh)").click();
29-
await waitForSteps(["reload-page"]);
22+
await expect.waitForSteps(["reload-page"]);
3023
});

addons/bus/static/tests/bus_monitoring_service.test.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import { WEBSOCKET_CLOSE_CODES } from "@bus/workers/websocket_worker";
77
import { describe, expect, test } from "@odoo/hoot";
88
import { manuallyDispatchProgrammaticEvent, runAllTimers } from "@odoo/hoot-dom";
99
import {
10-
asyncStep,
1110
getService,
1211
makeMockEnv,
1312
MockServer,
1413
mockService,
1514
patchWithCleanup,
16-
waitForSteps,
1715
} from "@web/../tests/web_test_helpers";
1816

1917
defineBusModels();
@@ -26,7 +24,7 @@ function stepConnectionStateChanges() {
2624
},
2725
set isConnectionLost(value) {
2826
if (value !== this._isConnectionLost) {
29-
asyncStep(`isConnectionLost - ${value}`);
27+
expect.step(`isConnectionLost - ${value}`);
3028
}
3129
this._isConnectionLost = value;
3230
},
@@ -36,53 +34,53 @@ function stepConnectionStateChanges() {
3634
test("connection considered as lost after failed reconnect attempt", async () => {
3735
stepConnectionStateChanges();
3836
addBusServiceListeners(
39-
["BUS:CONNECT", () => asyncStep("BUS:CONNECT")],
40-
["BUS:DISCONNECT", () => asyncStep("BUS:DISCONNECT")]
37+
["BUS:CONNECT", () => expect.step("BUS:CONNECT")],
38+
["BUS:DISCONNECT", () => expect.step("BUS:DISCONNECT")]
4139
);
4240
await makeMockEnv();
43-
await waitForSteps(["isConnectionLost - false", "BUS:CONNECT"]);
41+
await expect.waitForSteps(["isConnectionLost - false", "BUS:CONNECT"]);
4442
const unlockWebsocket = lockWebsocketConnect();
4543
MockServer.env["bus.bus"]._simulateDisconnection(WEBSOCKET_CLOSE_CODES.ABNORMAL_CLOSURE);
46-
await waitForSteps(["BUS:DISCONNECT"]);
44+
await expect.waitForSteps(["BUS:DISCONNECT"]);
4745
await runAllTimers();
48-
await waitForSteps(["isConnectionLost - true"]);
46+
await expect.waitForSteps(["isConnectionLost - true"]);
4947
unlockWebsocket();
5048
await runAllTimers();
51-
await waitForSteps(["isConnectionLost - false"]);
49+
await expect.waitForSteps(["isConnectionLost - false"]);
5250
});
5351

5452
test("brief disconect not considered lost", async () => {
5553
stepConnectionStateChanges();
5654
addBusServiceListeners(
57-
["BUS:CONNECT", () => asyncStep("BUS:CONNECT")],
58-
["BUS:DISCONNECT", () => asyncStep("BUS:DISCONNECT")],
59-
["BUS:RECONNECT", () => asyncStep("BUS:RECONNECT")]
55+
["BUS:CONNECT", () => expect.step("BUS:CONNECT")],
56+
["BUS:DISCONNECT", () => expect.step("BUS:DISCONNECT")],
57+
["BUS:RECONNECT", () => expect.step("BUS:RECONNECT")]
6058
);
6159
await makeMockEnv();
62-
await waitForSteps(["isConnectionLost - false", "BUS:CONNECT"]);
60+
await expect.waitForSteps(["isConnectionLost - false", "BUS:CONNECT"]);
6361
MockServer.env["bus.bus"]._simulateDisconnection(WEBSOCKET_CLOSE_CODES.SESSION_EXPIRED);
64-
await waitForSteps(["BUS:DISCONNECT"]);
62+
await expect.waitForSteps(["BUS:DISCONNECT"]);
6563
await runAllTimers();
66-
await waitForSteps(["BUS:RECONNECT"]); // Only reconnect step, which means the monitoring state didn't change.
64+
await expect.waitForSteps(["BUS:RECONNECT"]); // Only reconnect step, which means the monitoring state didn't change.
6765
});
6866

6967
test("computer sleep doesn't mark connection as lost", async () => {
7068
stepConnectionStateChanges();
7169
addBusServiceListeners(
72-
["BUS:CONNECT", () => asyncStep("BUS:CONNECT")],
73-
["BUS:DISCONNECT", () => asyncStep("BUS:DISCONNECT")],
74-
["BUS:RECONNECT", () => asyncStep("BUS:RECONNECT")]
70+
["BUS:CONNECT", () => expect.step("BUS:CONNECT")],
71+
["BUS:DISCONNECT", () => expect.step("BUS:DISCONNECT")],
72+
["BUS:RECONNECT", () => expect.step("BUS:RECONNECT")]
7573
);
7674
await makeMockEnv();
77-
await waitForSteps(["isConnectionLost - false", "BUS:CONNECT"]);
75+
await expect.waitForSteps(["isConnectionLost - false", "BUS:CONNECT"]);
7876
const unlockWebsocket = lockWebsocketConnect();
7977
patchWithCleanup(navigator, { onLine: false });
8078
await manuallyDispatchProgrammaticEvent(window, "offline"); // Offline event is triggered when the computer goes to sleep.
81-
await waitForSteps(["BUS:DISCONNECT"]);
79+
await expect.waitForSteps(["BUS:DISCONNECT"]);
8280
patchWithCleanup(navigator, { onLine: true });
8381
await manuallyDispatchProgrammaticEvent(window, "online"); // Online event is triggered when the computer wakes up.
8482
unlockWebsocket();
8583
await runAllTimers();
86-
await waitForSteps(["BUS:CONNECT"]);
84+
await expect.waitForSteps(["BUS:CONNECT"]);
8785
expect(getService("bus.monitoring_service").isConnectionLost).toBe(false);
8886
});

0 commit comments

Comments
 (0)