Skip to content

Commit

Permalink
[FIX] web: add more details when an error dialog is detected
Browse files Browse the repository at this point in the history
Before this commit, when the clickbot detected an error dialog, it
stopped the test and throw an error saying that an error dialog was
detected. This information is not enough to check why, and how, the
error dialog was produced.

Now, we also log the content of the error dialog as well as all the
information of the last rpc that was in error.

closes odoo#160103

closes odoo#160783

X-original-commit: 84b4b13
Signed-off-by: Aaron Bohy (aab) <[email protected]>
Signed-off-by: Jorge Pinna Puissant (jpp) <[email protected]>
Signed-off-by: Samuel Degueldre (sad) <[email protected]>
  • Loading branch information
jpp-odoo committed Apr 8, 2024
1 parent c941765 commit b554e94
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
22 changes: 19 additions & 3 deletions addons/web/static/src/webclient/clickbot/clickbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const STUDIO_SYSTRAY_ICON_SELECTOR = ".o_web_studio_navbar_item:not(.o_disabled)
let isEnterprise;
let state;
let calledRPC;
let errorRPC;
let actionCount;
let env;
let apps;
Expand Down Expand Up @@ -69,6 +70,7 @@ function setup(light, currentState) {
actionCount = 0;
calledRPC = {};
apps = null;
errorRPC = undefined;
}

function onRPCRequest({ detail }) {
Expand All @@ -77,6 +79,9 @@ function onRPCRequest({ detail }) {

function onRPCResponse({ detail }) {
delete calledRPC[detail.data.id];
if (detail.error) {
errorRPC = { ...detail };
}
}

function uiUpdate() {
Expand Down Expand Up @@ -145,11 +150,22 @@ async function waitForCondition(stopCondition) {
}
return size > 0;
}

while (!stopCondition() || hasPendingRPC() || hasScheduledTask()) {
function errorDialog() {
if (document.querySelector(".o_error_dialog")) {
throw new Error("Error dialog detected");
if (errorRPC) {
browser.console.error(
"A RPC in error was detected, maybe it's related to the error dialog : " +
JSON.stringify(errorRPC)
);
}
throw new Error(
"Error dialog detected" + document.querySelector(".o_error_dialog").innerHTML
);
}
return false;
}

while (errorDialog() || !stopCondition() || hasPendingRPC() || hasScheduledTask()) {
if (timeLimit <= 0) {
let msg = `Timeout, the clicked element took more than ${
initialTime / 1000
Expand Down
9 changes: 8 additions & 1 deletion addons/web/static/tests/legacy/helpers/mock_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ export function patchRPCWithCleanup(mockRPC = () => {}) {
rpcBus.trigger("RPC:RESPONSE", { data, settings, result });
resolve(result);
})
.catch(reject);
.catch((error) => {
rpcBus.trigger("RPC:RESPONSE", {
data,
settings,
error,
});
reject(error);
});
});
rpcProm.abort = (rejectError = true) => {
if (rejectError) {
Expand Down
65 changes: 64 additions & 1 deletion addons/web/static/tests/legacy/webclient/clickbot_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { browser } from "@web/core/browser/browser";
import { ListRenderer } from "@web/views/list/list_renderer";
import { SUCCESS_SIGNAL } from "@web/webclient/clickbot/clickbot";
import { onWillStart, onWillUpdateProps } from "@odoo/owl";
import { getFixture } from "../helpers/utils";
import { getFixture, nextTick } from "../helpers/utils";
import { errorService } from "@web/core/errors/error_service";
import { makeServerError } from "@web/../tests/helpers/mock_server";

let serverData;
let clickEverywhereDef;
Expand Down Expand Up @@ -307,6 +309,67 @@ QUnit.module("clickbot", (hooks) => {
]);
});

QUnit.test("clickbot show rpc error when an error dialog is detected", async (assert) => {
let clickBotStarted = false;
registry.category("services").add("error", errorService);
serverData.actions = {
1001: {
id: 1,
name: "App1",
res_model: "foo",
type: "ir.actions.act_window",
views: [[false, "list"]],
},
};
serverData.menus = {
root: { id: "root", children: [1], name: "root", appID: "root" },
1: { id: 1, children: [], name: "App1", appID: 1, actionID: 1001, xmlid: "app1" },
};
patchWithCleanup(browser, {
console: {
log: (msg) => {
if (msg === "test successful") {
assert.step(msg);
clickEverywhereDef.resolve();
}
},
error: (msg) => {
assert.step(msg.toString());
clickEverywhereDef.resolve();
},
},
});
let id = 1;
await createWebClient({
serverData,
mockRPC: async function (route, args) {
if (args.method === "web_search_read") {
if (clickBotStarted) {
if (id === 3) {
// click on the Second Filter
throw makeServerError({
message:
"This is a server Error, it should be displayed in an error dialog",
});
}
id++;
}
}
},
});
clickBotStarted = true;

clickEverywhereDef = makeDeferred();
window.clickEverywhere();
await clickEverywhereDef;
await nextTick();
assert.verifySteps([
'A RPC in error was detected, maybe it\'s related to the error dialog : {"data":{"id":6,"jsonrpc":"2.0","method":"call","params":{"model":"foo","method":"web_search_read","args":[],"kwargs":{"specification":{"foo":{}},"offset":0,"order":"","limit":80,"context":{"lang":"en","tz":"taht","uid":7,"bin_size":true},"count_limit":10001,"domain":["|",["bar","=",false],"&",["date",">=","2024-04-01"],["date","<=","2024-04-30"]]}}},"settings":{"silent":false},"error":{"name":"RPC_ERROR","type":"server","code":200,"data":{"name":"odoo.exceptions.UserError","debug":"traceback","arguments":[],"context":{}},"exceptionName":"odoo.exceptions.UserError","message":"This is a server Error, it should be displayed in an error dialog","errorEvent":{"isTrusted":true}}}',
"Error while testing App1 app1",
'Error: Error dialog detected<header class="modal-header"><h4 class="modal-title text-break">Odoo Error</h4><button type="button" class="btn-close" aria-label="Close" tabindex="-1"></button></header><footer class="modal-footer justify-content-around justify-content-sm-start flex-wrap gap-1 w-100" style="order:2"><button class="btn btn-primary o-default-button">Close</button><button class="btn btn-secondary"><i class="fa fa-clipboard mr8"></i>Copy error to clipboard</button></footer><main class="modal-body"><div role="alert"><p class="text-prewrap"><p><b>An error occurred</b></p><p>Please use the copy button to report the error to your support service.</p></p><button class="btn btn-link">See details</button></div></main>',
]);
});

QUnit.test("clickbot test waiting render after clicking filter", async (assert) => {
let clickBotStarted = false;
serverData.actions = {
Expand Down

0 comments on commit b554e94

Please sign in to comment.