`;
static props = ["*"];
setup() {
this.boom = false;
}
get a() {
// a bit artificial, but makes the test firefox compliant
throw new Error("Cannot read properties of undefined (reading 'b')");
}
onClick() {
this.boom = true;
this.render();
}
}
actionRegistry.add("Boom", Boom);
await mountWithCleanup(WebClient);
await getService("action").doAction("Boom");
expect(".my_button").toHaveCount(1);
await contains(".my_button").click();
await animationFrame();
expect(".my_button").toHaveCount(1);
expect(".o_error_dialog").toHaveCount(1);
expect.verifyErrors(["Cannot read properties of undefined (reading 'b')"]);
});
test("connection lost when opening form view from kanban", async () => {
expect.errors(2);
stepAllNetworkCalls();
await mountWithCleanup(WebClient);
await getService("action").doAction(1);
expect(".o_kanban_view").toHaveCount(1);
mockFetch((input) => {
expect.step(input);
if (input === "/web/webclient/version_info") {
// simulate a connection restore at the end of the test, to have no
// impact on other tests (see connectionLostNotifRemove)
return true;
}
throw new Error(); // simulate a ConnectionLost error
});
await contains(".o_kanban_record").click();
expect(".o_kanban_view").toHaveCount(1);
expect(".o_notification").toHaveCount(1);
expect(".o_notification").toHaveText("Connection lost. Trying to reconnect...");
expect.verifySteps([
"/web/webclient/translations",
"/web/webclient/load_menus",
"/web/action/load",
"get_views",
"web_search_read",
"/web/dataset/call_kw/partner/web_read", // from mockFetch
"/web/dataset/call_kw/partner/web_search_read", // from mockFetch
]);
await animationFrame();
expect.verifySteps([]); // doesn't indefinitely try to reload the list
// cleanup
await runAllTimers();
await animationFrame();
expect.verifySteps(["/web/webclient/version_info"]);
expect.verifyErrors([Error, Error]);
});
test.tags("desktop");
test("connection lost when coming back to kanban from form", async () => {
expect.errors(1);
stepAllNetworkCalls();
await mountWithCleanup(WebClient);
await getService("action").doAction(1);
expect(".o_kanban_view").toHaveCount(1);
await contains(".o_kanban_record").click();
expect(".o_form_view").toHaveCount(1);
mockFetch((input) => {
expect.step(input);
if (input === "/web/webclient/version_info") {
// simulate a connection restore at the end of the test, to have no
// impact on other tests (see connectionLostNotifRemove)
return true;
}
throw new Error(); // simulate a ConnectionLost error
});
await contains(".o_breadcrumb .o_back_button a").click();
await animationFrame();
expect(".o_form_view").toHaveCount(1);
expect(".o_notification").toHaveCount(1);
expect(".o_notification").toHaveText("Connection lost. Trying to reconnect...");
expect.verifySteps([
"/web/webclient/translations",
"/web/webclient/load_menus",
"/web/action/load",
"get_views",
"web_search_read",
"web_read",
"/web/dataset/call_kw/partner/web_search_read", // from mockFetch
]);
await animationFrame();
expect.verifySteps([]); // doesn't indefinitely try to reload the list
// cleanup
await runAllTimers();
await animationFrame();
expect.verifySteps(["/web/webclient/version_info"]);
expect.verifyErrors([Error]);
});
test("error on onMounted", async () => {
expect.errors(1);
Partner._fields.bar = fields.Boolean();
Partner._views = {
"kanban,1": `
`,
"form,false": ``,
"search,false": ``,
};
stepAllNetworkCalls();
patchWithCleanup(BooleanField.prototype, {
setup() {
super.setup();
onMounted(() => {
throw new Error("faulty on mounted");
});
},
});
patchWithCleanup(FormController.prototype, {
setup() {
super.setup();
onMounted(() => {
// If a onMounted hook is faulty, the rest of the onMounted will not be executed
// leading to inconsistent views.
throw new Error("Never Executed code");
});
},
});
await mountWithCleanup(WebClient);
await getService("action").doAction(1);
await animationFrame();
expect(".o_kanban_view").toHaveCount(1);
expect.verifySteps([
"/web/webclient/translations",
"/web/webclient/load_menus",
"/web/action/load",
"get_views",
"web_search_read",
]);
await contains(".o_kanban_record").click();
await animationFrame();
expect(".o_form_view").toHaveCount(0);
// check that the action manager is empty
expect(".o_action_manager").toHaveText("");
expect(".o_error_dialog").toHaveCount(1);
expect.verifySteps(["web_read"]);
expect.verifyErrors(["Error: faulty on mounted"]);
});