Files
odoo_source/addons/web/static/tests/webclient/actions/effects_tests.js
T
Jorge Pinna Puissant 54e9527ec2 [IMP] web, *: read session information from a module
* google_recaptcha, mail, partner_autocomplete, point_of_sale, website

Now, to read session information, the module "@web/session" must be
imported. Not that, there is also the user service with all the user
information.

closes odoo/odoo#73201

Related: odoo/enterprise#19434
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-07-08 14:13:39 +00:00

119 lines
4.8 KiB
JavaScript

/** @odoo-module **/
import { registry } from "@web/core/registry";
import testUtils from "web.test_utils";
import { clearRegistryWithCleanup } from "../../helpers/mock_env";
import { click, legacyExtraNextTick, nextTick, patchWithCleanup } from "../../helpers/utils";
import { createWebClient, doAction, getActionManagerServerData } from "./../helpers";
import { session } from "@web/session";
let serverData;
const mainComponentRegistry = registry.category("main_components");
QUnit.module("ActionManager", (hooks) => {
hooks.beforeEach(() => {
serverData = getActionManagerServerData();
});
QUnit.module("Effects");
QUnit.test("rainbowman integrated to webClient", async function (assert) {
assert.expect(10);
patchWithCleanup(session, { show_effect: true });
clearRegistryWithCleanup(mainComponentRegistry);
const webClient = await createWebClient({ serverData });
await doAction(webClient, 1);
assert.containsOnce(webClient.el, ".o_kanban_view");
assert.containsNone(webClient.el, ".o_reward");
webClient.env.services.effect.add("rainbowman", { message: "", fadeout: "no" });
await nextTick();
await legacyExtraNextTick();
assert.containsOnce(webClient.el, ".o_reward");
assert.containsOnce(webClient.el, ".o_kanban_view");
await testUtils.dom.click(webClient.el.querySelector(".o_kanban_record"));
await legacyExtraNextTick();
assert.containsNone(webClient.el, ".o_reward");
assert.containsOnce(webClient.el, ".o_kanban_view");
webClient.env.services.effect.add("rainbowman", { message: "", fadeout: "no" });
await nextTick();
await legacyExtraNextTick();
assert.containsOnce(webClient.el, ".o_reward");
assert.containsOnce(webClient.el, ".o_kanban_view");
// Do not force rainbow man to destroy on doAction
// we let it die either after its animation or on user click
await doAction(webClient, 3);
assert.containsOnce(webClient.el, ".o_reward");
assert.containsOnce(webClient.el, ".o_list_view");
});
QUnit.test("show effect notification instead of rainbow man", async function (assert) {
assert.expect(6);
const webClient = await createWebClient({ serverData });
await doAction(webClient, 1);
assert.containsOnce(webClient.el, ".o_kanban_view");
assert.containsNone(webClient.el, ".o_reward");
assert.containsNone(webClient.el, ".o_notification");
webClient.env.services.effect.add("rainbowman", { message: "", fadeout: "no" });
await nextTick();
await legacyExtraNextTick();
assert.containsOnce(webClient.el, ".o_kanban_view");
assert.containsNone(webClient.el, ".o_reward");
assert.containsOnce(webClient.el, ".o_notification");
});
QUnit.test("on close with effect from server", async function (assert) {
assert.expect(1);
patchWithCleanup(session, { show_effect: true });
const mockRPC = async (route) => {
if (route === "/web/dataset/call_button") {
return Promise.resolve({
type: "ir.actions.act_window_close",
effect: {
type: "rainbow_man",
message: "button called",
},
});
}
};
clearRegistryWithCleanup(mainComponentRegistry);
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, 6);
await click(webClient.el.querySelector('button[name="object"]'));
assert.containsOnce(webClient, ".o_reward");
});
QUnit.test("on close with effect in xml", async function (assert) {
assert.expect(2);
serverData.views["partner,false,form"] = `
<form>
<header>
<button string="Call method" name="object" type="object"
effect="{'type': 'rainbow_man', 'message': 'rainBowInXML'}"
/>
</header>
<field name="display_name"/>
</form>`;
patchWithCleanup(session, { show_effect: true });
const mockRPC = async (route) => {
if (route === "/web/dataset/call_button") {
return Promise.resolve(false);
}
};
clearRegistryWithCleanup(mainComponentRegistry);
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, 6);
await click(webClient.el.querySelector('button[name="object"]'));
await legacyExtraNextTick();
assert.containsOnce(webClient.el, ".o_reward");
assert.strictEqual(
webClient.el.querySelector(".o_reward .o_reward_msg_content").textContent,
"rainBowInXML"
);
});
});