mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 04:52:02 +02:00
vanilla 19.0
This commit is contained in:
parent
991d2234ca
commit
d1963a3c3a
3066 changed files with 1651266 additions and 922560 deletions
|
|
@ -0,0 +1,193 @@
|
|||
import { beforeEach, describe, expect, test } from "@odoo/hoot";
|
||||
import { click, queryAll } from "@odoo/hoot-dom";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import {
|
||||
contains,
|
||||
defineActions,
|
||||
defineMenus,
|
||||
getService,
|
||||
mountWithCleanup,
|
||||
patchWithCleanup,
|
||||
useTestClientAction,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
import { config as transitionConfig } from "@web/core/transition";
|
||||
import { WebClient } from "@web/webclient/webclient";
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
describe.current.tags("mobile");
|
||||
|
||||
beforeEach(() => {
|
||||
const testAction = useTestClientAction();
|
||||
defineActions([
|
||||
{ ...testAction, id: 1001, params: { description: "Id 1" } },
|
||||
{ ...testAction, id: 1002, params: { description: "Info" } },
|
||||
{ ...testAction, id: 1003, params: { description: "Report" } },
|
||||
]);
|
||||
defineMenus([
|
||||
{ id: 0 }, // prevents auto-loading the first action
|
||||
{ id: 1, name: "App1", actionID: 1001, xmlid: "menu_1" },
|
||||
]);
|
||||
patchWithCleanup(transitionConfig, { disabled: true });
|
||||
});
|
||||
|
||||
test("Burger menu can be opened and closed", async () => {
|
||||
await mountWithCleanup(WebClient);
|
||||
await contains(".o_mobile_menu_toggle", { root: document.body }).click();
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(1);
|
||||
await contains(".o_sidebar_close", { root: document.body }).click();
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("Burger Menu on an App", async () => {
|
||||
defineMenus([
|
||||
{
|
||||
id: 1,
|
||||
children: [
|
||||
{
|
||||
id: 99,
|
||||
name: "SubMenu",
|
||||
appID: 1,
|
||||
actionID: 1002,
|
||||
xmlid: "",
|
||||
webIconData: undefined,
|
||||
webIcon: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
await mountWithCleanup(WebClient);
|
||||
await contains("a.o_menu_toggle", { root: document.body }).click();
|
||||
await contains(".o_sidebar_topbar a.btn-primary", { root: document.body }).click();
|
||||
await contains(".o_burger_menu_content li:nth-of-type(2)", { root: document.body }).click();
|
||||
|
||||
expect(queryAll(".o_burger_menu_content", { root: document.body })).toHaveCount(0);
|
||||
|
||||
await contains("a.o_menu_toggle", { root: document.body }).click();
|
||||
|
||||
expect(
|
||||
queryAll(".o_app_menu_sidebar nav.o_burger_menu_content", { root: document.body })
|
||||
).toHaveText("App1\nSubMenu");
|
||||
await click(".modal-backdrop", { root: document.body });
|
||||
await contains(".o_mobile_menu_toggle", { root: document.body }).click();
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(1);
|
||||
expect(
|
||||
queryAll(".o_burger_menu nav.o_burger_menu_content", { root: document.body })
|
||||
).toHaveCount(1);
|
||||
|
||||
expect(queryAll(".o_burger_menu_content", { root: document.body })).toHaveClass(
|
||||
"o_burger_menu_app"
|
||||
);
|
||||
|
||||
await click(".o_sidebar_topbar", { root: document.body });
|
||||
|
||||
expect(queryAll(".o_burger_menu_content", { root: document.body })).not.toHaveClass(
|
||||
"o_burger_menu_dark"
|
||||
);
|
||||
|
||||
await click(".o_sidebar_topbar", { root: document.body });
|
||||
|
||||
expect(queryAll(".o_burger_menu_content", { root: document.body })).toHaveClass(
|
||||
"o_burger_menu_app"
|
||||
);
|
||||
});
|
||||
|
||||
test("Burger Menu on an App without SubMenu", async () => {
|
||||
await mountWithCleanup(WebClient);
|
||||
await contains("a.o_menu_toggle", { root: document.body }).click();
|
||||
await contains(".o_sidebar_topbar a.btn-primary", { root: document.body }).click();
|
||||
await contains(".o_burger_menu_content li:nth-of-type(2)", { root: document.body }).click();
|
||||
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(0);
|
||||
|
||||
await contains(".o_mobile_menu_toggle", { root: document.body }).click();
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(1);
|
||||
expect(queryAll(".o_user_menu_mobile", { root: document.body })).toHaveCount(1);
|
||||
await click(".o_sidebar_close", { root: document.body });
|
||||
expect(queryAll(".o_burger_menu")).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("Burger menu closes when an action is requested", async () => {
|
||||
await mountWithCleanup(WebClient);
|
||||
await contains(".o_mobile_menu_toggle", { root: document.body }).click();
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(1);
|
||||
expect(queryAll(".test_client_action", { root: document.body })).toHaveCount(0);
|
||||
await getService("action").doAction(1001);
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(0);
|
||||
expect(queryAll(".o_kanban_view", { root: document.body })).toHaveCount(0);
|
||||
expect(queryAll(".test_client_action", { root: document.body })).toHaveCount(1);
|
||||
});
|
||||
|
||||
test("Burger menu closes when click on menu item", async () => {
|
||||
defineMenus([
|
||||
{
|
||||
id: 1,
|
||||
children: [
|
||||
{
|
||||
id: 99,
|
||||
name: "SubMenu",
|
||||
actionID: 1002,
|
||||
xmlid: "",
|
||||
webIconData: undefined,
|
||||
webIcon: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{ id: 2, name: "App2", actionID: 1003, xmlid: "menu_2" },
|
||||
]);
|
||||
await mountWithCleanup(WebClient);
|
||||
getService("menu").setCurrentMenu(2);
|
||||
|
||||
await contains(".o_menu_toggle", { root: document.body }).click();
|
||||
expect(
|
||||
queryAll(".o_app_menu_sidebar nav.o_burger_menu_content", { root: document.body })
|
||||
).toHaveText("App2");
|
||||
|
||||
await contains(".oi-apps", { root: document.body }).click();
|
||||
expect(
|
||||
queryAll(".o_app_menu_sidebar nav.o_burger_menu_content", { root: document.body })
|
||||
).toHaveText("App0\nApp1\nApp2");
|
||||
|
||||
await contains(".o_burger_menu_app > ul > li:nth-of-type(2)", { root: document.body }).click();
|
||||
expect(queryAll(".o_burger_menu_app")).toHaveCount(0);
|
||||
|
||||
await contains(".o_menu_toggle", { root: document.body }).click();
|
||||
expect(queryAll(".o_burger_menu_app", { root: document.body })).toHaveCount(1);
|
||||
expect(
|
||||
queryAll(".o_app_menu_sidebar nav.o_burger_menu_content", { root: document.body })
|
||||
).toHaveText("App1\nSubMenu");
|
||||
|
||||
await click(".o_burger_menu_content li:nth-of-type(1)", { root: document.body });
|
||||
// click
|
||||
await animationFrame();
|
||||
// action
|
||||
await animationFrame();
|
||||
// close burger
|
||||
await animationFrame();
|
||||
expect(queryAll(".o_burger_menu_content", { root: document.body })).toHaveCount(0);
|
||||
expect(queryAll(".test_client_action", { root: document.body })).toHaveCount(1);
|
||||
});
|
||||
|
||||
test("Burger menu closes when click on user menu item", async () => {
|
||||
registry.category("user_menuitems").add("ring_item", () => ({
|
||||
type: "item",
|
||||
id: "ring",
|
||||
description: "Ring",
|
||||
callback: () => {
|
||||
expect.step("callback ring_item");
|
||||
},
|
||||
sequence: 5,
|
||||
}));
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(0);
|
||||
|
||||
await click(queryAll(".o_mobile_menu_toggle", { root: document.body }));
|
||||
await animationFrame();
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(1);
|
||||
|
||||
await click(queryAll(".o_burger_menu .o_user_menu_mobile a", { root: document.body }));
|
||||
await animationFrame();
|
||||
expect(queryAll(".o_burger_menu", { root: document.body })).toHaveCount(0);
|
||||
expect.verifySteps(["callback ring_item"]);
|
||||
});
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
import { BurgerUserMenu } from "@web/webclient/burger_menu/burger_user_menu/burger_user_menu";
|
||||
import { preferencesItem } from "@web/webclient/user_menu/user_menu_items";
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
import {
|
||||
clearRegistry,
|
||||
mockService,
|
||||
mountWithCleanup,
|
||||
onRpc,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
import { beforeEach, expect, test } from "@odoo/hoot";
|
||||
import { click, queryAll, queryAllTexts } from "@odoo/hoot-dom";
|
||||
import { markup } from "@odoo/owl";
|
||||
|
||||
const userMenuRegistry = registry.category("user_menuitems");
|
||||
|
||||
beforeEach(() => clearRegistry(userMenuRegistry));
|
||||
|
||||
test.tags("mobile");
|
||||
test("can be rendered", async () => {
|
||||
userMenuRegistry.add("bad_item", () => ({
|
||||
type: "item",
|
||||
id: "bad",
|
||||
description: "Bad",
|
||||
callback: () => {
|
||||
expect.step("callback bad_item");
|
||||
},
|
||||
sequence: 10,
|
||||
}));
|
||||
userMenuRegistry.add("ring_item", () => ({
|
||||
type: "item",
|
||||
id: "ring",
|
||||
description: "Ring",
|
||||
callback: () => {
|
||||
expect.step("callback ring_item");
|
||||
},
|
||||
sequence: 5,
|
||||
}));
|
||||
userMenuRegistry.add("frodo_item", () => ({
|
||||
type: "switch",
|
||||
id: "frodo",
|
||||
description: "Frodo",
|
||||
callback: () => {
|
||||
expect.step("callback frodo_item");
|
||||
},
|
||||
sequence: 11,
|
||||
}));
|
||||
userMenuRegistry.add("separator", () => ({
|
||||
type: "separator",
|
||||
sequence: 15,
|
||||
}));
|
||||
userMenuRegistry.add("invisible_item", () => ({
|
||||
type: "item",
|
||||
id: "hidden",
|
||||
description: "Hidden Power",
|
||||
callback: () => {
|
||||
expect.step("callback hidden_item");
|
||||
},
|
||||
sequence: 5,
|
||||
hide: true,
|
||||
}));
|
||||
userMenuRegistry.add("eye_item", () => ({
|
||||
type: "item",
|
||||
id: "eye",
|
||||
description: "Eye",
|
||||
callback: () => {
|
||||
expect.step("callback eye_item");
|
||||
},
|
||||
}));
|
||||
userMenuRegistry.add("html_item", () => ({
|
||||
type: "item",
|
||||
id: "html",
|
||||
description: markup`<div>HTML<i class="fa fa-check px-2"></i></div>`,
|
||||
callback: () => {
|
||||
expect.step("callback html_item");
|
||||
},
|
||||
sequence: 20,
|
||||
}));
|
||||
await mountWithCleanup(BurgerUserMenu);
|
||||
expect("a").toHaveCount(4);
|
||||
expect(".form-switch input.form-check-input").toHaveCount(1);
|
||||
expect("hr").toHaveCount(1);
|
||||
expect(queryAllTexts("a, .form-switch")).toEqual(["Ring", "Bad", "Frodo", "HTML", "Eye"]);
|
||||
for (const item of queryAll("a, .form-switch")) {
|
||||
await click(item);
|
||||
}
|
||||
expect.verifySteps([
|
||||
"callback ring_item",
|
||||
"callback bad_item",
|
||||
"callback frodo_item",
|
||||
"callback html_item",
|
||||
"callback eye_item",
|
||||
]);
|
||||
});
|
||||
|
||||
test.tags("mobile");
|
||||
test("can execute the callback of settings", async () => {
|
||||
onRpc("action_get", () => ({
|
||||
name: "Change My Preferences",
|
||||
res_id: 0,
|
||||
}));
|
||||
mockService("action", {
|
||||
async doAction(actionId) {
|
||||
expect.step(actionId.res_id);
|
||||
expect.step(actionId.name);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
userMenuRegistry.add("preferences", preferencesItem);
|
||||
await mountWithCleanup(BurgerUserMenu);
|
||||
expect("a").toHaveCount(1);
|
||||
expect("a").toHaveText("My Preferences");
|
||||
await click("a");
|
||||
await expect.waitForSteps([7, "Change My Preferences"]);
|
||||
});
|
||||
|
|
@ -0,0 +1,293 @@
|
|||
import { beforeEach, describe, expect, test } from "@odoo/hoot";
|
||||
import { queryAllTexts } from "@odoo/hoot-dom";
|
||||
import { animationFrame, runAllTimers } from "@odoo/hoot-mock";
|
||||
import {
|
||||
contains,
|
||||
mountWithCleanup,
|
||||
patchWithCleanup,
|
||||
serverState,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
|
||||
import { cookie } from "@web/core/browser/cookie";
|
||||
import { user } from "@web/core/user";
|
||||
import { MobileSwitchCompanyMenu } from "@web/webclient/burger_menu/mobile_switch_company_menu/mobile_switch_company_menu";
|
||||
|
||||
const ORIGINAL_TOGGLE_DELAY = MobileSwitchCompanyMenu.toggleDelay;
|
||||
|
||||
async function createSwitchCompanyMenu(options = { toggleDelay: 0 }) {
|
||||
patchWithCleanup(MobileSwitchCompanyMenu, { toggleDelay: options.toggleDelay });
|
||||
await mountWithCleanup(MobileSwitchCompanyMenu);
|
||||
}
|
||||
|
||||
function patchUserActiveCompanies(cids) {
|
||||
patchWithCleanup(
|
||||
user.activeCompanies,
|
||||
cids.map((cid) => serverState.companies.find((company) => company.id === cid))
|
||||
);
|
||||
}
|
||||
|
||||
describe.current.tags("mobile");
|
||||
|
||||
const clickConfirm = () => contains(".o_switch_company_menu_buttons button:first").click();
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
*/
|
||||
const toggleCompany = async (index) =>
|
||||
contains(`[data-company-id] [role=menuitemcheckbox]:eq(${index})`).click();
|
||||
|
||||
beforeEach(() => {
|
||||
serverState.companies = [
|
||||
{ id: 1, name: "Hermit", parent_id: false, child_ids: [] },
|
||||
{ id: 2, name: "Herman's", parent_id: false, child_ids: [] },
|
||||
{ id: 3, name: "Heroes TM", parent_id: false, child_ids: [] },
|
||||
];
|
||||
});
|
||||
|
||||
test("basic rendering", async () => {
|
||||
await mountWithCleanup(MobileSwitchCompanyMenu);
|
||||
|
||||
expect(".o_burger_menu_companies").toHaveProperty("tagName", "DIV");
|
||||
expect(".o_burger_menu_companies").toHaveClass("o_burger_menu_companies");
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect(".log_into").toHaveCount(3);
|
||||
expect(".fa-check-square").toHaveCount(1);
|
||||
expect(".fa-square-o").toHaveCount(2);
|
||||
|
||||
expect(".o_switch_company_item:eq(0)").toHaveText("Hermit");
|
||||
expect(".o_switch_company_item:eq(0)").toHaveClass("alert-secondary");
|
||||
expect(".o_switch_company_item:eq(1)").toHaveText("Herman's");
|
||||
expect(".o_switch_company_item:eq(2)").toHaveText("Heroes TM");
|
||||
|
||||
expect(".o_switch_company_item i:eq(0)").toHaveClass("fa-check-square");
|
||||
expect(".o_switch_company_item i:eq(1)").toHaveClass("fa-square-o");
|
||||
expect(".o_switch_company_item i:eq(2)").toHaveClass("fa-square-o");
|
||||
|
||||
expect(".o_burger_menu_companies").toHaveText("Companies\nHermit\nHerman's\nHeroes TM");
|
||||
});
|
||||
|
||||
test("companies can be toggled: toggle a second company", async () => {
|
||||
await createSwitchCompanyMenu();
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([1]);
|
||||
expect(user.activeCompany.id).toBe(1);
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(1);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(2);
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [x] Company 2 -> toggle
|
||||
* [ ] Company 3
|
||||
*/
|
||||
await toggleCompany(1);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(2);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(1);
|
||||
await clickConfirm();
|
||||
expect(cookie.get("cids")).toEqual("1-2");
|
||||
});
|
||||
|
||||
test("can toggle multiple companies at once", async () => {
|
||||
await createSwitchCompanyMenu({ toggleDelay: ORIGINAL_TOGGLE_DELAY });
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([1]);
|
||||
expect(user.activeCompany.id).toBe(1);
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(1);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(2);
|
||||
|
||||
/**
|
||||
* [ ] **Company 1** -> toggle all
|
||||
* [x] Company 2 -> toggle all
|
||||
* [x] Company 3 -> toggle all
|
||||
*/
|
||||
await toggleCompany(0);
|
||||
await toggleCompany(1);
|
||||
await toggleCompany(2);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(2);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(1);
|
||||
|
||||
expect.verifySteps([]);
|
||||
await clickConfirm();
|
||||
expect(cookie.get("cids")).toEqual("2-3");
|
||||
});
|
||||
|
||||
test("single company selected: toggling it off will keep it", async () => {
|
||||
await createSwitchCompanyMenu();
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
await runAllTimers();
|
||||
expect(cookie.get("cids")).toBe("1");
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([1]);
|
||||
expect(user.activeCompany.id).toBe(1);
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(1);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(2);
|
||||
|
||||
/**
|
||||
* [ ] **Company 1** -> toggle off
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
await toggleCompany(0);
|
||||
await clickConfirm();
|
||||
expect(cookie.get("cids")).toEqual("1");
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([1]);
|
||||
expect(user.activeCompany.id).toBe(1);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(1);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(2);
|
||||
});
|
||||
|
||||
test("single company mode: companies can be logged in", async () => {
|
||||
await createSwitchCompanyMenu();
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([1]);
|
||||
expect(user.activeCompany.id).toBe(1);
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(1);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(2);
|
||||
|
||||
/**
|
||||
* [ ] **Company 1**
|
||||
* [x] Company 2 -> log into
|
||||
* [ ] Company 3
|
||||
*/
|
||||
await contains(".log_into:eq(1)").click();
|
||||
expect(cookie.get("cids")).toEqual("2");
|
||||
});
|
||||
|
||||
test("multi company mode: log into a non selected company", async () => {
|
||||
patchUserActiveCompanies([3, 1]);
|
||||
await createSwitchCompanyMenu();
|
||||
|
||||
/**
|
||||
* [x] Company 1
|
||||
* [ ] Company 2
|
||||
* [x] **Company 3**
|
||||
*/
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([3, 1]);
|
||||
expect(user.activeCompany.id).toBe(3);
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(2);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(1);
|
||||
|
||||
/**
|
||||
* [x] Company 1
|
||||
* [ ] Company 2 -> log into
|
||||
* [x] **Company 3**
|
||||
*/
|
||||
await contains(".log_into:eq(1)").click();
|
||||
expect(cookie.get("cids")).toEqual("2-1-3"); // 1-3 in that order, they are sorted
|
||||
});
|
||||
|
||||
test("multi company mode: log into an already selected company", async () => {
|
||||
patchUserActiveCompanies([2, 3]);
|
||||
await createSwitchCompanyMenu();
|
||||
|
||||
/**
|
||||
* [ ] Company 1
|
||||
* [x] **Company 2**
|
||||
* [x] Company 3
|
||||
*/
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([2, 3]);
|
||||
expect(user.activeCompany.id).toBe(2);
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(2);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(1);
|
||||
|
||||
/**
|
||||
* [ ] Company 1
|
||||
* [x] **Company 2**
|
||||
* [x] Company 3 -> log into
|
||||
*/
|
||||
await contains(".log_into:eq(2)").click();
|
||||
expect(cookie.get("cids")).toEqual("3-2");
|
||||
});
|
||||
|
||||
test("companies can be logged in even if some toggled within delay", async () => {
|
||||
await createSwitchCompanyMenu({ toggleDelay: ORIGINAL_TOGGLE_DELAY });
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
expect(user.activeCompanies.map((c) => c.id)).toEqual([1]);
|
||||
expect(user.activeCompany.id).toBe(1);
|
||||
expect("[data-company-id]").toHaveCount(3);
|
||||
expect("[data-company-id] .fa-check-square").toHaveCount(1);
|
||||
expect("[data-company-id] .fa-square-o").toHaveCount(2);
|
||||
|
||||
/**
|
||||
* [ ] **Company 1** -> toggled
|
||||
* [ ] Company 2 -> logged in
|
||||
* [ ] Company 3 -> toggled
|
||||
*/
|
||||
await contains("[data-company-id] [role=menuitemcheckbox]:eq(2)").click();
|
||||
await contains("[data-company-id] [role=menuitemcheckbox]:eq(0)").click();
|
||||
await contains(".log_into:eq(1)").click();
|
||||
expect(cookie.get("cids")).toEqual("2");
|
||||
});
|
||||
|
||||
test("show confirm and reset buttons only when selection has changed", async () => {
|
||||
await mountWithCleanup(MobileSwitchCompanyMenu);
|
||||
expect(".o_switch_company_menu_buttons").toHaveCount(0);
|
||||
await toggleCompany(1);
|
||||
expect(".o_switch_company_menu_buttons button").toHaveCount(2);
|
||||
await toggleCompany(1);
|
||||
expect(".o_switch_company_menu_buttons").toHaveCount(0);
|
||||
});
|
||||
|
||||
test("No collapse and no search input when less that 10 companies", async () => {
|
||||
await mountWithCleanup(MobileSwitchCompanyMenu);
|
||||
expect(".o_burger_menu_companies .fa-caret-right").toHaveCount(0);
|
||||
expect(".o_burger_menu_companies .visually-hidden input").toHaveCount(1);
|
||||
});
|
||||
|
||||
test("Show search input when more that 10 companies & search filters items but ignore case and spaces", async () => {
|
||||
serverState.companies = [
|
||||
{ id: 3, name: "Hermit", sequence: 1, parent_id: false, child_ids: [] },
|
||||
{ id: 2, name: "Herman's", sequence: 2, parent_id: false, child_ids: [] },
|
||||
{ id: 1, name: "Heroes TM", sequence: 3, parent_id: false, child_ids: [4, 5] },
|
||||
{ id: 4, name: "Hercules", sequence: 4, parent_id: 1, child_ids: [] },
|
||||
{ id: 5, name: "Hulk", sequence: 5, parent_id: 1, child_ids: [] },
|
||||
{ id: 6, name: "Random Company a", sequence: 6, parent_id: false, child_ids: [7, 8] },
|
||||
{ id: 7, name: "Random Company aa", sequence: 7, parent_id: 6, child_ids: [] },
|
||||
{ id: 8, name: "Random Company ab", sequence: 8, parent_id: 6, child_ids: [] },
|
||||
{ id: 9, name: "Random d", sequence: 9, parent_id: false, child_ids: [] },
|
||||
{ id: 10, name: "Random e", sequence: 10, parent_id: false, child_ids: [] },
|
||||
];
|
||||
await createSwitchCompanyMenu();
|
||||
await contains(".o_burger_menu_companies > div").click();
|
||||
expect(".o_burger_menu_companies input").toHaveCount(1);
|
||||
expect(".o_burger_menu_companies input").not.toBeFocused();
|
||||
|
||||
expect(".o_switch_company_item").toHaveCount(10);
|
||||
contains(".o_burger_menu_companies input").edit("omcom");
|
||||
await animationFrame();
|
||||
|
||||
expect(".o_switch_company_item").toHaveCount(3);
|
||||
expect(queryAllTexts(".o_switch_company_item.o-navigable")).toEqual([
|
||||
"Random Company a",
|
||||
"Random Company aa",
|
||||
"Random Company ab",
|
||||
]);
|
||||
});
|
||||
|
|
@ -1,319 +0,0 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { hotkeyService } from "@web/core/hotkeys/hotkey_service";
|
||||
import { makeTestEnv } from "@web/../tests/helpers/mock_env";
|
||||
import {
|
||||
click,
|
||||
getFixture,
|
||||
makeDeferred,
|
||||
mount,
|
||||
patchWithCleanup,
|
||||
} from "@web/../tests/helpers/utils";
|
||||
import { MobileSwitchCompanyMenu } from "@web/webclient/burger_menu/mobile_switch_company_menu/mobile_switch_company_menu";
|
||||
import { companyService } from "@web/webclient/company_service";
|
||||
import { uiService } from "@web/core/ui/ui_service";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const serviceRegistry = registry.category("services");
|
||||
let target;
|
||||
|
||||
const ORIGINAL_TOGGLE_DELAY = MobileSwitchCompanyMenu.toggleDelay;
|
||||
async function createSwitchCompanyMenu(routerParams = {}, toggleDelay = 0) {
|
||||
patchWithCleanup(MobileSwitchCompanyMenu, { toggleDelay });
|
||||
if (routerParams.onPushState) {
|
||||
const pushState = browser.history.pushState;
|
||||
patchWithCleanup(browser, {
|
||||
history: Object.assign({}, browser.history, {
|
||||
pushState(state, title, url) {
|
||||
pushState(...arguments);
|
||||
if (routerParams.onPushState) {
|
||||
routerParams.onPushState(url);
|
||||
}
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
const env = await makeTestEnv();
|
||||
const scMenu = await mount(MobileSwitchCompanyMenu, target, { env });
|
||||
return scMenu;
|
||||
}
|
||||
|
||||
QUnit.module("MobileSwitchCompanyMenu", (hooks) => {
|
||||
hooks.beforeEach(() => {
|
||||
target = getFixture();
|
||||
patchWithCleanup(session.user_companies, {
|
||||
allowed_companies: {
|
||||
1: { id: 1, name: "Hermit" },
|
||||
2: { id: 2, name: "Herman's" },
|
||||
3: { id: 3, name: "Heroes TM" },
|
||||
},
|
||||
current_company: 1,
|
||||
});
|
||||
serviceRegistry.add("ui", uiService);
|
||||
serviceRegistry.add("company", companyService);
|
||||
serviceRegistry.add("hotkey", hotkeyService);
|
||||
});
|
||||
|
||||
QUnit.test("basic rendering", async (assert) => {
|
||||
assert.expect(13);
|
||||
|
||||
await createSwitchCompanyMenu();
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
assert.strictEqual(scMenuEl.tagName.toUpperCase(), "DIV");
|
||||
assert.hasClass(scMenuEl, "o_burger_menu_companies");
|
||||
assert.containsN(scMenuEl, ".toggle_company", 3);
|
||||
assert.containsN(scMenuEl, ".log_into", 3);
|
||||
assert.containsOnce(scMenuEl, ".fa-check-square");
|
||||
assert.containsN(scMenuEl, ".fa-square-o", 2);
|
||||
|
||||
assert.strictEqual(
|
||||
scMenuEl.querySelectorAll(".menu_companies_item")[0].textContent,
|
||||
"Hermit(current)"
|
||||
);
|
||||
assert.strictEqual(
|
||||
scMenuEl.querySelectorAll(".menu_companies_item")[1].textContent,
|
||||
"Herman's"
|
||||
);
|
||||
assert.strictEqual(
|
||||
scMenuEl.querySelectorAll(".menu_companies_item")[2].textContent,
|
||||
"Heroes TM"
|
||||
);
|
||||
|
||||
assert.hasClass(scMenuEl.querySelectorAll(".menu_companies_item i")[0], "fa-check-square");
|
||||
assert.hasClass(scMenuEl.querySelectorAll(".menu_companies_item i")[1], "fa-square-o");
|
||||
assert.hasClass(scMenuEl.querySelectorAll(".menu_companies_item i")[2], "fa-square-o");
|
||||
|
||||
assert.strictEqual(scMenuEl.textContent, "CompaniesHermit(current)Herman'sHeroes TM");
|
||||
});
|
||||
|
||||
QUnit.test("companies can be toggled: toggle a second company", async (assert) => {
|
||||
assert.expect(9);
|
||||
|
||||
const prom = makeDeferred();
|
||||
function onPushState(url) {
|
||||
assert.step(url.split("#")[1]);
|
||||
prom.resolve();
|
||||
}
|
||||
const scMenu = await createSwitchCompanyMenu({ onPushState });
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id]", 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 2);
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [x] Company 2 -> toggle
|
||||
* [ ] Company 3
|
||||
*/
|
||||
await click(scMenuEl.querySelectorAll(".toggle_company")[1]);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 2);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 1);
|
||||
await prom;
|
||||
assert.verifySteps(["cids=1%2C2"]);
|
||||
});
|
||||
|
||||
QUnit.test("can toggle multiple companies at once", async (assert) => {
|
||||
assert.expect(10);
|
||||
|
||||
const prom = makeDeferred();
|
||||
function onPushState(url) {
|
||||
assert.step(url.split("#")[1]);
|
||||
prom.resolve();
|
||||
}
|
||||
const scMenu = await createSwitchCompanyMenu({ onPushState }, ORIGINAL_TOGGLE_DELAY);
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id]", 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 2);
|
||||
|
||||
/**
|
||||
* [ ] **Company 1** -> toggle all
|
||||
* [x] Company 2 -> toggle all
|
||||
* [x] Company 3 -> toggle all
|
||||
*/
|
||||
await click(scMenuEl.querySelectorAll(".toggle_company")[0]);
|
||||
await click(scMenuEl.querySelectorAll(".toggle_company")[1]);
|
||||
await click(scMenuEl.querySelectorAll(".toggle_company")[2]);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 2);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 1);
|
||||
|
||||
assert.verifySteps([]);
|
||||
await prom; // await toggle promise
|
||||
assert.verifySteps(["cids=2%2C3"]);
|
||||
});
|
||||
|
||||
QUnit.test("single company selected: toggling it off will keep it", async (assert) => {
|
||||
assert.expect(11);
|
||||
|
||||
patchWithCleanup(browser, {
|
||||
setTimeout(fn) {
|
||||
return fn(); // s.t. we can directly assert changes in the hash
|
||||
},
|
||||
});
|
||||
const scMenu = await createSwitchCompanyMenu();
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.router.current.hash, { cids: 1 });
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id]", 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 2);
|
||||
|
||||
/**
|
||||
* [ ] **Company 1** -> toggle off
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
await click(scMenuEl.querySelectorAll(".toggle_company")[0]);
|
||||
assert.deepEqual(scMenu.env.services.router.current.hash, { cids: 1 });
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-squarqe", 0);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 3);
|
||||
});
|
||||
|
||||
QUnit.test("single company mode: companies can be logged in", async (assert) => {
|
||||
assert.expect(7);
|
||||
|
||||
function onPushState(url) {
|
||||
assert.step(url.split("#")[1]);
|
||||
}
|
||||
const scMenu = await createSwitchCompanyMenu({ onPushState });
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id]", 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 2);
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2 -> log into
|
||||
* [ ] Company 3
|
||||
*/
|
||||
await click(scMenuEl.querySelectorAll(".log_into")[1]);
|
||||
assert.verifySteps(["cids=2"]);
|
||||
});
|
||||
|
||||
QUnit.test("multi company mode: log into a non selected company", async (assert) => {
|
||||
assert.expect(7);
|
||||
|
||||
function onPushState(url) {
|
||||
assert.step(url.split("#")[1]);
|
||||
}
|
||||
Object.assign(browser.location, { hash: "cids=3%2C1" });
|
||||
const scMenu = await createSwitchCompanyMenu({ onPushState });
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
/**
|
||||
* [x] Company 1
|
||||
* [ ] Company 2
|
||||
* [x] **Company 3**
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [3, 1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id]", 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 2);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 1);
|
||||
|
||||
/**
|
||||
* [x] Company 1
|
||||
* [ ] Company 2 -> log into
|
||||
* [x] **Company 3**
|
||||
*/
|
||||
await click(scMenuEl.querySelectorAll(".log_into")[1]);
|
||||
assert.verifySteps(["cids=2%2C3%2C1"]);
|
||||
});
|
||||
|
||||
QUnit.test("multi company mode: log into an already selected company", async (assert) => {
|
||||
assert.expect(7);
|
||||
|
||||
function onPushState(url) {
|
||||
assert.step(url.split("#")[1]);
|
||||
}
|
||||
Object.assign(browser.location, { hash: "cids=2%2C3" });
|
||||
const scMenu = await createSwitchCompanyMenu({ onPushState });
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
/**
|
||||
* [ ] Company 1
|
||||
* [x] **Company 2**
|
||||
* [x] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 2);
|
||||
assert.containsN(scMenuEl, "[data-company-id]", 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 2);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 1);
|
||||
|
||||
/**
|
||||
* [ ] Company 1
|
||||
* [x] **Company 2**
|
||||
* [x] Company 3 -> log into
|
||||
*/
|
||||
await click(scMenuEl.querySelectorAll(".log_into")[2]);
|
||||
assert.verifySteps(["cids=3%2C2"]);
|
||||
});
|
||||
|
||||
QUnit.test("companies can be logged in even if some toggled within delay", async (assert) => {
|
||||
assert.expect(7);
|
||||
|
||||
function onPushState(url) {
|
||||
assert.step(url.split("#")[1]);
|
||||
}
|
||||
const scMenu = await createSwitchCompanyMenu({ onPushState }, ORIGINAL_TOGGLE_DELAY);
|
||||
const scMenuEl = target.querySelector(".o_burger_menu_companies");
|
||||
|
||||
/**
|
||||
* [x] **Company 1**
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id]", 3);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-check-square", 1);
|
||||
assert.containsN(scMenuEl, "[data-company-id] .fa-square-o", 2);
|
||||
|
||||
/**
|
||||
* [ ] **Company 1** -> toggled
|
||||
* [ ] Company 2 -> logged in
|
||||
* [ ] Company 3 -> toggled
|
||||
*/
|
||||
await click(scMenuEl.querySelectorAll(".toggle_company")[2]);
|
||||
await click(scMenuEl.querySelectorAll(".toggle_company")[0]);
|
||||
await click(scMenuEl.querySelectorAll(".log_into")[1]);
|
||||
assert.verifySteps(["cids=2"]);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue