[REF] web: extract company service from user service
This commit is contained in:
@@ -4,10 +4,9 @@ import ActivityView from '@mail/js/views/activity/activity_view';
|
||||
import testUtils from 'web.test_utils';
|
||||
import { createWebClient } from "@web/../tests/webclient/actions/helpers";
|
||||
|
||||
import { legacyExtraNextTick } from "@web/../tests/helpers/utils";
|
||||
import { legacyExtraNextTick, patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
import { doAction, getActionManagerTestConfig } from "@web/../tests/webclient/actions/helpers";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { makeFakeUserService } from "@web/../tests/helpers/mock_services";
|
||||
|
||||
let testConfig;
|
||||
|
||||
@@ -392,15 +391,7 @@ QUnit.test("activity view: no group_by_menu and no comparison_menu", async funct
|
||||
}
|
||||
};
|
||||
|
||||
registry.category("services").add(
|
||||
"user",
|
||||
makeFakeUserService({
|
||||
session_info: {
|
||||
user_context: { lang: "zz_ZZ" },
|
||||
},
|
||||
}),
|
||||
{ force: true }
|
||||
);
|
||||
patchWithCleanup(odoo.session_info.user_context, { lang: "zz_ZZ" });
|
||||
|
||||
const webClient = await createWebClient({ testConfig, mockRPC , legacyParams: {withLegacyMockServer: true}});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { manageMessages } from "@mail/js/tools/debug_manager";
|
||||
import { click, legacyExtraNextTick } from "@web/../tests/helpers/utils";
|
||||
import { click, legacyExtraNextTick, patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
import {
|
||||
createWebClient,
|
||||
doAction,
|
||||
@@ -15,9 +15,8 @@ QUnit.module("DebugMenu");
|
||||
QUnit.test("Manage Messages", async function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const testConfig = Object.assign(getActionManagerTestConfig(), {
|
||||
debug: "1",
|
||||
});
|
||||
patchWithCleanup(odoo, { debug: "1" });
|
||||
const testConfig = getActionManagerTestConfig();
|
||||
|
||||
// Add fake "mail.message" model and arch
|
||||
testConfig.serverData.models["mail.message"] = {
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
export const companyAutocompleteService = {
|
||||
dependencies: ["orm", "user"],
|
||||
dependencies: ["orm", "company"],
|
||||
|
||||
start(env, { orm, user }) {
|
||||
start(env, { orm, company }) {
|
||||
if (odoo.session_info.iap_company_enrich) {
|
||||
const currentCompanyId = user.current_company.id;
|
||||
const currentCompanyId = company.currentCompany.id;
|
||||
orm.silent.call("res.company", "iap_enrich_auto", [currentCompanyId], {});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,135 +1,50 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { browser } from "./browser/browser";
|
||||
import { registry } from "./registry";
|
||||
|
||||
function parseCompanyIds(cidsFromHash) {
|
||||
const cids = [];
|
||||
if (typeof cidsFromHash === "string") {
|
||||
cids.push(...cidsFromHash.split(",").map(Number));
|
||||
} else if (typeof cidsFromHash === "number") {
|
||||
cids.push(cidsFromHash);
|
||||
}
|
||||
return cids;
|
||||
}
|
||||
|
||||
export function computeAllowedCompanyIds(cids) {
|
||||
const { user_companies } = odoo.session_info;
|
||||
|
||||
let allowedCompanies = cids || [];
|
||||
const allowedCompaniesFromSession = user_companies.allowed_companies;
|
||||
const notReallyAllowedCompanies = allowedCompanies.filter(
|
||||
(id) => !(id in allowedCompaniesFromSession)
|
||||
);
|
||||
|
||||
if (!allowedCompanies.length || notReallyAllowedCompanies.length) {
|
||||
allowedCompanies = [user_companies.current_company];
|
||||
}
|
||||
return allowedCompanies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function} getAllowedCompanyIds function that returns the allowed
|
||||
* company ids.
|
||||
* @returns {function} function that takes a mode ('toggle' or 'loginto') and
|
||||
* a company id, and that returns the selected company ids following that
|
||||
* operation.
|
||||
*/
|
||||
export function makeSetCompanies(getAllowedCompanyIds) {
|
||||
return function setCompanies(mode, companyId) {
|
||||
let nextCompanyIds = getAllowedCompanyIds().slice();
|
||||
if (mode === "toggle") {
|
||||
if (nextCompanyIds.includes(companyId)) {
|
||||
nextCompanyIds = nextCompanyIds.filter((id) => id !== companyId);
|
||||
} else {
|
||||
nextCompanyIds.push(companyId);
|
||||
}
|
||||
} else if (mode === "loginto") {
|
||||
if (nextCompanyIds.length === 1) {
|
||||
// 1 enabled company: stay in single company mode
|
||||
nextCompanyIds = [companyId];
|
||||
} else {
|
||||
// multi company mode
|
||||
if (nextCompanyIds.includes(companyId)) {
|
||||
nextCompanyIds = nextCompanyIds.filter((id) => id !== companyId);
|
||||
}
|
||||
nextCompanyIds.unshift(companyId);
|
||||
}
|
||||
}
|
||||
return nextCompanyIds.length ? nextCompanyIds : [companyId];
|
||||
};
|
||||
}
|
||||
|
||||
export const userService = {
|
||||
dependencies: ["router", "cookie"],
|
||||
start(env, { router, cookie }) {
|
||||
const info = odoo.session_info;
|
||||
const {
|
||||
user_context,
|
||||
username,
|
||||
name,
|
||||
is_system,
|
||||
is_admin,
|
||||
partner_id,
|
||||
user_companies,
|
||||
home_action_id,
|
||||
show_effect: showEffect,
|
||||
} = info;
|
||||
start() {
|
||||
const sessionInfo = odoo.session_info;
|
||||
|
||||
let cids;
|
||||
if ("cids" in router.current.hash) {
|
||||
cids = parseCompanyIds(router.current.hash.cids);
|
||||
} else if ("cids" in cookie.current) {
|
||||
cids = parseCompanyIds(cookie.current.cids);
|
||||
}
|
||||
const allowedCompanies = computeAllowedCompanyIds(cids);
|
||||
let context = {
|
||||
lang: user_context.lang,
|
||||
tz: user_context.tz,
|
||||
uid: info.uid,
|
||||
allowed_company_ids: allowedCompanies,
|
||||
const context = {
|
||||
...sessionInfo.user_context,
|
||||
uid: sessionInfo.uid,
|
||||
};
|
||||
|
||||
const stringCIds = allowedCompanies.join(",");
|
||||
router.replaceState({ cids: stringCIds }, { lock: true });
|
||||
cookie.setCookie("cids", stringCIds);
|
||||
|
||||
const setCompanies = makeSetCompanies(() => allowedCompanies);
|
||||
return {
|
||||
context,
|
||||
get context() {
|
||||
return Object.assign({}, context);
|
||||
},
|
||||
removeFromContext(key) {
|
||||
delete context[key];
|
||||
},
|
||||
updateContext(update) {
|
||||
Object.assign(context, update);
|
||||
},
|
||||
name: sessionInfo.name,
|
||||
userName: sessionInfo.username,
|
||||
isAdmin: sessionInfo.is_admin,
|
||||
isSystem: sessionInfo.is_system,
|
||||
partnerId: sessionInfo.partner_id,
|
||||
home_action_id: sessionInfo.home_action_id,
|
||||
showEffect: sessionInfo.show_effect,
|
||||
get userId() {
|
||||
return context.uid;
|
||||
},
|
||||
name,
|
||||
userName: username,
|
||||
isAdmin: is_admin,
|
||||
isSystem: is_system,
|
||||
partnerId: partner_id,
|
||||
allowed_companies: user_companies.allowed_companies,
|
||||
current_company: user_companies.allowed_companies[allowedCompanies[0]],
|
||||
get lang() {
|
||||
return context.lang;
|
||||
},
|
||||
get tz() {
|
||||
return context.tz;
|
||||
},
|
||||
home_action_id,
|
||||
get db() {
|
||||
const res = {
|
||||
name: info.db,
|
||||
name: sessionInfo.db,
|
||||
};
|
||||
if ("dbuuid" in info) {
|
||||
res.uuid = info.dbuuid;
|
||||
if ("dbuuid" in sessionInfo) {
|
||||
res.uuid = sessionInfo.dbuuid;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
showEffect,
|
||||
setCompanies: (mode, companyId) => {
|
||||
const nextCompanyIds = setCompanies(mode, companyId).join(",");
|
||||
router.pushState({ cids: nextCompanyIds }, { lock: true });
|
||||
cookie.setCookie("cids", nextCompanyIds);
|
||||
browser.setTimeout(() => window.location.reload()); // history.pushState is a little async
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,15 +23,14 @@ import { registry } from "./core/registry";
|
||||
/**
|
||||
* Return a value Odoo Env object
|
||||
*
|
||||
* @param {string} debug
|
||||
* @returns {OdooEnv}
|
||||
*/
|
||||
export function makeEnv(debug) {
|
||||
export function makeEnv() {
|
||||
return {
|
||||
qweb: new owl.QWeb(),
|
||||
bus: new owl.core.EventBus(),
|
||||
services: {},
|
||||
debug,
|
||||
debug: odoo.debug,
|
||||
_t: () => {
|
||||
throw new Error("Translations are not ready yet. Maybe use _lt instead?");
|
||||
},
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function startWebClient(Webclient) {
|
||||
odoo.isReady = false;
|
||||
|
||||
// setup environment
|
||||
const env = makeEnv(odoo.debug);
|
||||
const env = makeEnv();
|
||||
const [, templates] = await Promise.all([
|
||||
startServices(env),
|
||||
odoo.loadTemplatesPromise.then(processTemplates),
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
function parseCompanyIds(cidsFromHash) {
|
||||
const cids = [];
|
||||
if (typeof cidsFromHash === "string") {
|
||||
cids.push(...cidsFromHash.split(",").map(Number));
|
||||
} else if (typeof cidsFromHash === "number") {
|
||||
cids.push(cidsFromHash);
|
||||
}
|
||||
return cids;
|
||||
}
|
||||
|
||||
function computeAllowedCompanyIds(cids) {
|
||||
const { user_companies } = odoo.session_info;
|
||||
let allowedCompanyIds = cids || [];
|
||||
const availableCompaniesFromSession = user_companies.allowed_companies;
|
||||
const notReallyAllowedCompanies = allowedCompanyIds.filter(
|
||||
(id) => !(id in availableCompaniesFromSession)
|
||||
);
|
||||
|
||||
if (!allowedCompanyIds.length || notReallyAllowedCompanies.length) {
|
||||
allowedCompanyIds = [user_companies.current_company];
|
||||
}
|
||||
return allowedCompanyIds;
|
||||
}
|
||||
|
||||
export const companyService = {
|
||||
dependencies: ["user", "router", "cookie"],
|
||||
start(env, { user, router, cookie }) {
|
||||
let cids;
|
||||
if ("cids" in router.current.hash) {
|
||||
cids = parseCompanyIds(router.current.hash.cids);
|
||||
} else if ("cids" in cookie.current) {
|
||||
cids = parseCompanyIds(cookie.current.cids);
|
||||
}
|
||||
let allowedCompanyIds = computeAllowedCompanyIds(cids);
|
||||
|
||||
const stringCIds = allowedCompanyIds.join(",");
|
||||
router.replaceState({ cids: stringCIds }, { lock: true });
|
||||
cookie.setCookie("cids", stringCIds);
|
||||
|
||||
user.updateContext({ allowed_company_ids: allowedCompanyIds });
|
||||
const availableCompanies = odoo.session_info.user_companies.allowed_companies;
|
||||
|
||||
return {
|
||||
availableCompanies,
|
||||
get allowedCompanyIds() {
|
||||
return allowedCompanyIds.slice();
|
||||
},
|
||||
get currentCompany() {
|
||||
return availableCompanies[allowedCompanyIds[0]];
|
||||
},
|
||||
setCompanies(mode, companyId) {
|
||||
// compute next company ids
|
||||
let nextCompanyIds = allowedCompanyIds.slice();
|
||||
if (mode === "toggle") {
|
||||
if (nextCompanyIds.includes(companyId)) {
|
||||
nextCompanyIds = nextCompanyIds.filter((id) => id !== companyId);
|
||||
} else {
|
||||
nextCompanyIds.push(companyId);
|
||||
}
|
||||
} else if (mode === "loginto") {
|
||||
if (nextCompanyIds.length === 1) {
|
||||
// 1 enabled company: stay in single company mode
|
||||
nextCompanyIds = [companyId];
|
||||
} else {
|
||||
// multi company mode
|
||||
if (nextCompanyIds.includes(companyId)) {
|
||||
nextCompanyIds = nextCompanyIds.filter((id) => id !== companyId);
|
||||
}
|
||||
nextCompanyIds.unshift(companyId);
|
||||
}
|
||||
}
|
||||
allowedCompanyIds = nextCompanyIds.length ? nextCompanyIds : [companyId];
|
||||
|
||||
// apply them
|
||||
router.pushState({ cids: allowedCompanyIds }, { lock: true });
|
||||
cookie.setCookie("cids", allowedCompanyIds);
|
||||
browser.setTimeout(() => browser.location.reload()); // history.pushState is a little async
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
registry.category("services").add("company", companyService);
|
||||
@@ -5,20 +5,21 @@ import { registry } from "../../core/registry";
|
||||
|
||||
export class SwitchCompanyMenu extends owl.Component {
|
||||
static isDisplayed(env) {
|
||||
const allowedCompanies = env.services.user.allowed_companies;
|
||||
return Object.keys(allowedCompanies).length > 1 && !env.isSmall;
|
||||
const { availableCompanies } = env.services.company;
|
||||
return Object.keys(availableCompanies).length > 1 && !env.isSmall;
|
||||
}
|
||||
|
||||
setup() {
|
||||
this.user = useService("user");
|
||||
this.companyService = useService("company");
|
||||
this.currentCompany = this.companyService.currentCompany;
|
||||
}
|
||||
|
||||
toggleCompany(companyId) {
|
||||
this.user.setCompanies("toggle", companyId);
|
||||
this.companyService.setCompanies("toggle", companyId);
|
||||
}
|
||||
|
||||
logIntoCompany(companyId) {
|
||||
this.user.setCompanies("loginto", companyId);
|
||||
this.companyService.setCompanies("loginto", companyId);
|
||||
}
|
||||
}
|
||||
SwitchCompanyMenu.template = "web.SwitchCompanyMenu";
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
<t t-name="web.SwitchCompanyMenu" owl="1">
|
||||
<Dropdown class="o_switch_company_menu">
|
||||
<span t-attf-class="{{env.isSmall ? 'fa fa-building-o' : 'oe_topbar_name'}}">
|
||||
<t t-if="!env.isSmall"><t t-esc="user.current_company.name"/></t>
|
||||
<t t-if="!env.isSmall"><t t-esc="currentCompany.name"/></t>
|
||||
</span>
|
||||
<t t-set-slot="menu">
|
||||
<t t-foreach="user.allowed_companies" t-as="company_id">
|
||||
<t t-foreach="Object.values(companyService.availableCompanies)" t-as="company">
|
||||
<t t-call="web.SwitchCompanyItem">
|
||||
<t t-set="company" t-value="user.allowed_companies[company_id]" />
|
||||
<t t-set="company" t-value="company" />
|
||||
</t>
|
||||
</t>
|
||||
</t>
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
<t t-name="web.SwitchCompanyItem" owl="1">
|
||||
<div>
|
||||
<t t-set="isCompanySelected" t-value="user.context.allowed_company_ids.includes(company.id)"/>
|
||||
<t t-set="isCurrent" t-value="company.id === user.current_company.id"/>
|
||||
<t t-set="isCompanySelected" t-value="companyService.allowedCompanyIds.includes(company.id)"/>
|
||||
<t t-set="isCurrent" t-value="company.id === companyService.currentCompany.id"/>
|
||||
<DropdownItem>
|
||||
<div class="dropdown-item d-flex py-0 px-0" data-menu="company" t-att-data-company-id="company.id">
|
||||
<div
|
||||
|
||||
@@ -180,7 +180,7 @@ QUnit.module("DebugMenu", (hooks) => {
|
||||
}
|
||||
Parent.components = { ActionDialog };
|
||||
Parent.template = tags.xml`<ActionDialog/>`;
|
||||
testConfig.debug = "1";
|
||||
patchWithCleanup(odoo, { debug: "1" });
|
||||
const env = await makeTestEnv(testConfig);
|
||||
const actionDialog = await mount(Parent, { env, target });
|
||||
registerCleanup(() => {
|
||||
|
||||
@@ -4,7 +4,6 @@ import { ormService } from "@web/core/orm_service";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/service_hook";
|
||||
import { makeTestEnv } from "../helpers/mock_env";
|
||||
import { makeFakeUserService } from "../helpers/mock_services";
|
||||
import { getFixture } from "../helpers/utils";
|
||||
|
||||
const { Component, mount, tags } = owl;
|
||||
@@ -13,7 +12,6 @@ const serviceRegistry = registry.category("services");
|
||||
|
||||
QUnit.module("ORM Service", {
|
||||
async beforeEach() {
|
||||
serviceRegistry.add("user", makeFakeUserService());
|
||||
serviceRegistry.add("orm", ormService);
|
||||
},
|
||||
});
|
||||
@@ -41,7 +39,6 @@ QUnit.test("add user context to a simple read request", async (assert) => {
|
||||
args: [[3], ["id", "descr"]],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
@@ -62,7 +59,6 @@ QUnit.test("context is combined with user context in read request", async (asser
|
||||
args: [[3], ["id", "descr"]],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
@@ -84,7 +80,6 @@ QUnit.test("basic method call of model", async (assert) => {
|
||||
args: [],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
@@ -110,7 +105,6 @@ QUnit.test("create method", async (assert) => {
|
||||
],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
@@ -131,7 +125,6 @@ QUnit.test("unlink method", async (assert) => {
|
||||
args: [[43]],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
@@ -152,7 +145,6 @@ QUnit.test("write method", async (assert) => {
|
||||
args: [[43, 14], { active: false }],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
@@ -182,7 +174,6 @@ QUnit.test("readGroup method", async (assert) => {
|
||||
fields: ["amount_total:sum"],
|
||||
groupby: ["date_order"],
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
uid: 7,
|
||||
tz: "taht",
|
||||
@@ -204,7 +195,6 @@ QUnit.test("searchRead method", async (assert) => {
|
||||
args: [],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
@@ -227,7 +217,6 @@ QUnit.test("webSearchRead method", async (assert) => {
|
||||
args: [],
|
||||
kwargs: {
|
||||
context: {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
|
||||
@@ -5,7 +5,7 @@ odoo.define("web.SessionOverrideForTests", (require) => {
|
||||
// So if a test does a session_reload, it will merge the odoo global of that test
|
||||
// into the session, and will alter every subsequent test of the suite.
|
||||
// Obviously, we don't want that, ever.
|
||||
const initialOdoo = odoo;
|
||||
const initialOdoo = Object.assign({}, odoo);
|
||||
const Session = require("web.Session");
|
||||
const { patch } = require("@web/core/utils/patch");
|
||||
patch(Session.prototype, "web.SessionTestPatch", {
|
||||
|
||||
@@ -91,49 +91,8 @@ export async function makeTestEnv(config = {}) {
|
||||
FormController.prototype.multiClickTime = initialQuickEditDelay;
|
||||
});
|
||||
|
||||
setTestOdooWithCleanup(config);
|
||||
const env = makeEnv(odoo.debug);
|
||||
const env = makeEnv();
|
||||
await startServices(env);
|
||||
env.qweb.addTemplates(window.__ODOO_TEMPLATES__);
|
||||
return env;
|
||||
}
|
||||
|
||||
export function setTestOdooWithCleanup(config = {}) {
|
||||
const originalOdoo = odoo;
|
||||
registerCleanup(() => {
|
||||
odoo = originalOdoo;
|
||||
});
|
||||
odoo = Object.assign({}, originalOdoo, {
|
||||
debug: config.debug || "",
|
||||
session_info: {
|
||||
cache_hashes: {
|
||||
load_menus: "161803",
|
||||
translations: "314159",
|
||||
},
|
||||
currencies: {
|
||||
1: { name: "USD", digits: [69, 2], position: "before", symbol: "$" },
|
||||
2: { name: "EUR", digits: [69, 2], position: "after", symbol: "€" },
|
||||
},
|
||||
user_context: {
|
||||
lang: "en",
|
||||
uid: 7,
|
||||
tz: "taht",
|
||||
},
|
||||
qweb: "owl",
|
||||
uid: 7,
|
||||
name: "Mitchell",
|
||||
username: "The wise",
|
||||
is_admin: true,
|
||||
partner_id: 7,
|
||||
// Commit: 3e847fc8f499c96b8f2d072ab19f35e105fd7749
|
||||
// to see what user_companies is
|
||||
user_companies: {
|
||||
allowed_companies: { 1: { id: 1, name: "Hermit" } },
|
||||
current_company: 1,
|
||||
},
|
||||
db: "test",
|
||||
server_version: "1.0",
|
||||
server_version_info: ["1.0"],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,11 +6,12 @@ import { localization } from "@web/core/l10n/localization";
|
||||
import { translatedTerms } from "@web/core/l10n/translation";
|
||||
import { rpcService } from "@web/core/network/rpc_service";
|
||||
import { SIZES } from "@web/core/ui_service";
|
||||
import { computeAllowedCompanyIds, makeSetCompanies } from "@web/core/user_service";
|
||||
import { userService } from "@web/core/user_service";
|
||||
import { effectService } from "@web/webclient/effects/effect_service";
|
||||
import { objectToUrlEncodedString } from "../../src/core/utils/urls";
|
||||
import { objectToUrlEncodedString } from "@web/core/utils/urls";
|
||||
import { registerCleanup } from "./cleanup";
|
||||
import { patchWithCleanup } from "./utils";
|
||||
import { companyService } from "@web/webclient/company_service";
|
||||
|
||||
const { Component } = owl;
|
||||
|
||||
@@ -46,57 +47,6 @@ export function makeFakeLocalizationService(config = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a fake user service.
|
||||
*/
|
||||
export function makeFakeUserService(values) {
|
||||
const sessionInfo = {};
|
||||
Object.assign(sessionInfo, odoo.session_info, values && values.session_info);
|
||||
const { uid, name, username, is_admin, user_companies, partner_id, user_context } = sessionInfo;
|
||||
return {
|
||||
name: "user",
|
||||
start() {
|
||||
let allowedCompanies = computeAllowedCompanyIds();
|
||||
const setCompanies = makeSetCompanies(() => allowedCompanies);
|
||||
const context = {
|
||||
...user_context,
|
||||
get allowed_company_ids() {
|
||||
return allowedCompanies;
|
||||
},
|
||||
};
|
||||
const result = {
|
||||
context,
|
||||
userId: uid,
|
||||
name: name,
|
||||
userName: username,
|
||||
isAdmin: is_admin,
|
||||
partnerId: partner_id,
|
||||
allowed_companies: user_companies.allowed_companies,
|
||||
get current_company() {
|
||||
return user_companies.allowed_companies[allowedCompanies[0]];
|
||||
},
|
||||
lang: user_context.lang,
|
||||
tz: "Europe/Brussels",
|
||||
get db() {
|
||||
const res = {
|
||||
name: sessionInfo.db,
|
||||
};
|
||||
if ("dbuuid" in sessionInfo) {
|
||||
res.uuid = sessionInfo.dbuuid;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
showEffect: false,
|
||||
setCompanies(mode, companyId) {
|
||||
allowedCompanies = setCompanies(mode, companyId);
|
||||
},
|
||||
};
|
||||
Object.assign(result, values);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function buildMockRPC(mockRPC) {
|
||||
return async function (...args) {
|
||||
if (this instanceof Component && this.__owl__.status === 5) {
|
||||
@@ -176,12 +126,13 @@ export function makeMockFetch(mockRPC) {
|
||||
};
|
||||
}
|
||||
|
||||
export function makeMockLocation() {
|
||||
function makeMockLocation() {
|
||||
const locationLink = Object.assign(document.createElement("a"), {
|
||||
href: window.location.origin + window.location.pathname,
|
||||
assign(url) {
|
||||
this.href = url;
|
||||
},
|
||||
reload() {},
|
||||
});
|
||||
return new Proxy(locationLink, {
|
||||
get(target, p) {
|
||||
@@ -280,6 +231,14 @@ export function makeFakeUIService(values = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
export function makeFakeCompanyService() {
|
||||
const mockLocation = makeMockLocation();
|
||||
patchWithCleanup(browser, {
|
||||
location: mockLocation,
|
||||
});
|
||||
return companyService;
|
||||
}
|
||||
|
||||
export const fakeCookieService = {
|
||||
start() {
|
||||
const cookie = {};
|
||||
@@ -338,13 +297,14 @@ export function makeFakeNotificationService(createMock, closeMock) {
|
||||
}
|
||||
|
||||
export const mocks = {
|
||||
company: makeFakeCompanyService,
|
||||
cookie: () => fakeCookieService,
|
||||
effect: () => effectService, // BOI The real service ? Is this what we want ?
|
||||
localization: makeFakeLocalizationService,
|
||||
ui: makeFakeUIService,
|
||||
notifications: makeFakeNotificationService,
|
||||
router: makeFakeRouterService,
|
||||
rpc: makeFakeRPCService,
|
||||
title: () => fakeTitleService,
|
||||
user: makeFakeUserService,
|
||||
ui: makeFakeUIService,
|
||||
user: () => userService,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { browser } from "@web/core/browser/browser";
|
||||
import { patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
import { legacyProm } from "web.test_legacy";
|
||||
import { registerCleanup } from "./helpers/cleanup";
|
||||
import { prepareRegistriesWithCleanup, setTestOdooWithCleanup } from "./helpers/mock_env";
|
||||
import { prepareRegistriesWithCleanup } from "./helpers/mock_env";
|
||||
|
||||
const { whenReady, loadFile } = owl.utils;
|
||||
|
||||
@@ -61,14 +61,50 @@ function patchLegacySession() {
|
||||
});
|
||||
}
|
||||
|
||||
function patchOdoo() {
|
||||
patchWithCleanup(odoo, {
|
||||
debug: "",
|
||||
session_info: {
|
||||
cache_hashes: {
|
||||
load_menus: "161803",
|
||||
translations: "314159",
|
||||
},
|
||||
currencies: {
|
||||
1: { name: "USD", digits: [69, 2], position: "before", symbol: "$" },
|
||||
2: { name: "EUR", digits: [69, 2], position: "after", symbol: "€" },
|
||||
},
|
||||
user_context: {
|
||||
lang: "en",
|
||||
uid: 7,
|
||||
tz: "taht",
|
||||
},
|
||||
qweb: "owl",
|
||||
uid: 7,
|
||||
name: "Mitchell",
|
||||
username: "The wise",
|
||||
is_admin: true,
|
||||
partner_id: 7,
|
||||
// Commit: 3e847fc8f499c96b8f2d072ab19f35e105fd7749
|
||||
// to see what user_companies is
|
||||
user_companies: {
|
||||
allowed_companies: { 1: { id: 1, name: "Hermit" } },
|
||||
current_company: 1,
|
||||
},
|
||||
db: "test",
|
||||
server_version: "1.0",
|
||||
server_version_info: ["1.0"],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function setupTests() {
|
||||
QUnit.testStart(() => {
|
||||
setTestOdooWithCleanup();
|
||||
prepareRegistriesWithCleanup();
|
||||
forceLocaleAndTimezoneWithCleanup();
|
||||
patchBrowserWithCleanup();
|
||||
patchLegacyCoreBus();
|
||||
patchLegacySession();
|
||||
patchOdoo();
|
||||
});
|
||||
|
||||
const templatesUrl = `/web/webclient/qweb/${new Date().getTime()}?bundle=web.assets_qweb`;
|
||||
|
||||
@@ -5,14 +5,12 @@ import { NotificationContainer } from "@web/core/notifications/notification_cont
|
||||
import { EffectContainer } from "@web/webclient/effects/effect_container";
|
||||
import testUtils from "web.test_utils";
|
||||
import { clearRegistryWithCleanup } from "../../helpers/mock_env";
|
||||
import { makeFakeUserService } from "../../helpers/mock_services";
|
||||
import { click, legacyExtraNextTick, nextTick } from "../../helpers/utils";
|
||||
import { click, legacyExtraNextTick, nextTick, patchWithCleanup } from "../../helpers/utils";
|
||||
import { createWebClient, doAction, getActionManagerTestConfig } from "./helpers";
|
||||
|
||||
let testConfig;
|
||||
|
||||
const mainComponentRegistry = registry.category("main_components");
|
||||
const serviceRegistry = registry.category("services");
|
||||
|
||||
QUnit.module("ActionManager", (hooks) => {
|
||||
hooks.beforeEach(() => {
|
||||
@@ -23,9 +21,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("rainbowman integrated to webClient", async function (assert) {
|
||||
assert.expect(10);
|
||||
serviceRegistry.add("user", makeFakeUserService({ showEffect: true }), {
|
||||
force: true,
|
||||
});
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
clearRegistryWithCleanup(mainComponentRegistry);
|
||||
mainComponentRegistry.add("EffectContainer", {
|
||||
Component: EffectContainer,
|
||||
@@ -77,9 +73,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("on close with effect from server", async function (assert) {
|
||||
assert.expect(1);
|
||||
serviceRegistry.add("user", makeFakeUserService({ showEffect: true }), {
|
||||
force: true,
|
||||
});
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
const mockRPC = async (route, args) => {
|
||||
if (route === "/web/dataset/call_button") {
|
||||
return Promise.resolve({
|
||||
@@ -112,9 +106,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
</header>
|
||||
<field name="display_name"/>
|
||||
</form>`;
|
||||
serviceRegistry.add("user", makeFakeUserService({ showEffect: true }), {
|
||||
force: true,
|
||||
});
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
const mockRPC = async (route, args) => {
|
||||
if (route === "/web/dataset/call_button") {
|
||||
return Promise.resolve(false);
|
||||
|
||||
@@ -39,13 +39,13 @@ import {
|
||||
makeFakeLocalizationService,
|
||||
makeFakeRouterService,
|
||||
makeFakeUIService,
|
||||
makeFakeUserService,
|
||||
} from "../../helpers/mock_services";
|
||||
import { getFixture, legacyExtraNextTick, nextTick, patchWithCleanup } from "../../helpers/utils";
|
||||
import session from "web.session";
|
||||
import { ComponentAdapter } from "web.OwlCompatibility";
|
||||
import LegacyMockServer from "web.MockServer";
|
||||
import Widget from "web.Widget";
|
||||
import { userService } from "@web/core/user_service";
|
||||
|
||||
const { Component, mount, tags } = owl;
|
||||
|
||||
@@ -263,7 +263,6 @@ export function getActionManagerTestConfig() {
|
||||
|
||||
// need activateMockServer or something like that for odoo.browser.fetch !!! something is bad
|
||||
const fakeLocalizationService = makeFakeLocalizationService();
|
||||
const fakeUserService = makeFakeUserService();
|
||||
const fakeUIService = makeFakeUIService();
|
||||
const fakeRouterService = makeFakeRouterService();
|
||||
|
||||
@@ -280,7 +279,7 @@ export function getActionManagerTestConfig() {
|
||||
serviceRegistry.add("router", fakeRouterService);
|
||||
serviceRegistry.add("title", fakeTitleService);
|
||||
serviceRegistry.add("ui", fakeUIService);
|
||||
serviceRegistry.add("user", fakeUserService);
|
||||
serviceRegistry.add("user", userService);
|
||||
serviceRegistry.add("view", viewService);
|
||||
|
||||
// additional basic client action
|
||||
|
||||
@@ -119,7 +119,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
return {};
|
||||
});
|
||||
registry.category("services").add("debug", debugService);
|
||||
testConfig.debug = true;
|
||||
patchWithCleanup(odoo, { debug: true });
|
||||
|
||||
const mockRPC = (route) => {
|
||||
if (route.includes("check_access_rights")) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import core from "web.core";
|
||||
import AbstractAction from "web.AbstractAction";
|
||||
import { registerCleanup } from "../../helpers/cleanup";
|
||||
import { makeTestEnv } from "../../helpers/mock_env";
|
||||
import { makeFakeRouterService, makeFakeUserService } from "../../helpers/mock_services";
|
||||
import { makeFakeRouterService } from "../../helpers/mock_services";
|
||||
import { getFixture, legacyExtraNextTick, patchWithCleanup } from "../../helpers/utils";
|
||||
import { createWebClient, doAction, getActionManagerTestConfig, loadState } from "./helpers";
|
||||
|
||||
@@ -99,9 +99,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("fallback on home action if no action found", async (assert) => {
|
||||
assert.expect(2);
|
||||
serviceRegistry.add("user", makeFakeUserService({ home_action_id: 1001 }), {
|
||||
force: true,
|
||||
});
|
||||
patchWithCleanup(odoo.session_info, { home_action_id: 1001 });
|
||||
|
||||
const wc = await createWebClient({ testConfig });
|
||||
await testUtils.nextTick(); // wait for the navbar to be updated
|
||||
|
||||
@@ -174,7 +174,6 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
let action = await loadAction(3, actionParams);
|
||||
assert.verifySteps(["server loaded"]);
|
||||
const baseContext = {
|
||||
allowed_company_ids: [1],
|
||||
lang: "en",
|
||||
tz: "taht",
|
||||
uid: 7,
|
||||
|
||||
@@ -5,7 +5,8 @@ import { uiService } from "@web/core/ui_service";
|
||||
import testUtils from "web.test_utils";
|
||||
import ReportClientAction from "report.client_action";
|
||||
import { clearRegistryWithCleanup } from "../../helpers/mock_env";
|
||||
import { makeFakeNotificationService, makeFakeUserService } from "../../helpers/mock_services";
|
||||
import { makeFakeNotificationService } from "../../helpers/mock_services";
|
||||
import { patchWithCleanup } from "../../helpers/utils";
|
||||
import { createWebClient, doAction, getActionManagerTestConfig } from "./helpers";
|
||||
import { mockDownload } from "@web/../tests/helpers/utils";
|
||||
import { DialogContainer } from "@web/core/dialog/dialog_container";
|
||||
@@ -168,8 +169,8 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
"/web/action/load",
|
||||
"/report/check_wkhtmltopdf",
|
||||
"notify",
|
||||
// context={"lang":'en',"uid":7,"tz":'taht', allowed_company_ids: [1]}
|
||||
"/report/html/some_report?context=%7B%22lang%22%3A%22en%22%2C%22uid%22%3A7%2C%22tz%22%3A%22taht%22%2C%22allowed_company_ids%22%3A%5B1%5D%7D",
|
||||
// context={"lang":'en',"uid":7,"tz":'taht'}
|
||||
"/report/html/some_report?context=%7B%22lang%22%3A%22en%22%2C%22uid%22%3A7%2C%22tz%22%3A%22taht%22%7D",
|
||||
]);
|
||||
testUtils.mock.unpatch(ReportClientAction);
|
||||
}
|
||||
@@ -191,9 +192,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
),
|
||||
{ force: true }
|
||||
);
|
||||
serviceRegistry.add("user", makeFakeUserService({ context: { some_key: 2 } }), {
|
||||
force: true,
|
||||
});
|
||||
patchWithCleanup(odoo.session_info.user_context, { some_key: 2 });
|
||||
const mockRPC = async (route, args) => {
|
||||
assert.step(args.method || route);
|
||||
if (route.includes("/report/html/some_report")) {
|
||||
@@ -218,8 +217,8 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
assert.verifySteps([
|
||||
"/web/webclient/load_menus",
|
||||
"/web/action/load",
|
||||
// context={"some_key":2}
|
||||
"/report/html/some_report?context=%7B%22some_key%22%3A2%7D",
|
||||
// context={"lang":'en',"uid":7,"tz":'taht',"some_key":2}
|
||||
"/report/html/some_report?context=%7B%22lang%22%3A%22en%22%2C%22uid%22%3A7%2C%22tz%22%3A%22taht%22%2C%22some_key%22%3A2%7D",
|
||||
]);
|
||||
testUtils.mock.unpatch(ReportClientAction);
|
||||
});
|
||||
|
||||
@@ -11,8 +11,7 @@ import ListController from "web.ListController";
|
||||
import testUtils from "web.test_utils";
|
||||
import legacyViewRegistry from "web.view_registry";
|
||||
import { clearRegistryWithCleanup } from "../../helpers/mock_env";
|
||||
import { makeFakeUserService } from "../../helpers/mock_services";
|
||||
import { click, legacyExtraNextTick, nextTick } from "../../helpers/utils";
|
||||
import { click, legacyExtraNextTick, nextTick, patchWithCleanup } from "../../helpers/utils";
|
||||
import { createWebClient, doAction, getActionManagerTestConfig, loadState } from "./helpers";
|
||||
|
||||
let testConfig;
|
||||
@@ -704,13 +703,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("requests for execute_action of type object are handled", async function (assert) {
|
||||
assert.expect(11);
|
||||
serviceRegistry.add(
|
||||
"user",
|
||||
makeFakeUserService({
|
||||
context: Object.assign({}, { some_key: 2 }),
|
||||
}),
|
||||
{ force: true }
|
||||
);
|
||||
patchWithCleanup(odoo.session_info.user_context, { some_key: 2 });
|
||||
const mockRPC = async (route, args) => {
|
||||
assert.step((args && args.method) || route);
|
||||
if (route === "/web/dataset/call_button") {
|
||||
@@ -718,7 +711,14 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
args,
|
||||
{
|
||||
args: [[1]],
|
||||
kwargs: { context: { some_key: 2 } },
|
||||
kwargs: {
|
||||
context: {
|
||||
lang: "en",
|
||||
uid: 7,
|
||||
tz: "taht",
|
||||
some_key: 2,
|
||||
},
|
||||
},
|
||||
method: "object",
|
||||
model: "partner",
|
||||
},
|
||||
@@ -1600,7 +1600,6 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
lang: "en",
|
||||
uid: 7,
|
||||
tz: "taht",
|
||||
allowed_company_ids: [1],
|
||||
},
|
||||
};
|
||||
const sessionStorage = testConfig.browser.sessionStorage;
|
||||
@@ -1630,7 +1629,6 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
lang: "en",
|
||||
uid: 7,
|
||||
tz: "taht",
|
||||
allowed_company_ids: [1],
|
||||
active_model: "partner",
|
||||
active_id: 1,
|
||||
active_ids: [1],
|
||||
@@ -2231,7 +2229,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
serviceRegistry.add("debug", debugService);
|
||||
registry.category("debug").category("view").add("editView", editView);
|
||||
testConfig.debug = "1";
|
||||
patchWithCleanup(odoo, { debug: "1" });
|
||||
const mockRPC = async (route) => {
|
||||
if (route.includes("check_access_rights")) {
|
||||
return true;
|
||||
|
||||
@@ -5,9 +5,9 @@ import { registry } from "@web/core/registry";
|
||||
import { EffectContainer } from "@web/webclient/effects/effect_container";
|
||||
import { effectService } from "@web/webclient/effects/effect_service";
|
||||
import { RainbowMan } from "@web/webclient/effects/rainbow_man";
|
||||
import { userService } from "@web/core/user_service";
|
||||
import { makeTestEnv } from "../../helpers/mock_env";
|
||||
import { makeFakeUserService } from "../../helpers/mock_services";
|
||||
import { click, getFixture, nextTick } from "../../helpers/utils";
|
||||
import { click, getFixture, nextTick, patchWithCleanup } from "../../helpers/utils";
|
||||
|
||||
const { Component, mount, tags } = owl;
|
||||
const serviceRegistry = registry.category("services");
|
||||
@@ -31,8 +31,8 @@ QUnit.module("RainbowMan", (hooks) => {
|
||||
fadeout: "nextTick",
|
||||
};
|
||||
target = getFixture();
|
||||
const user = makeFakeUserService({ showEffect: true });
|
||||
serviceRegistry.add("user", user);
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
serviceRegistry.add("user", userService);
|
||||
serviceRegistry.add("effect", effectService);
|
||||
serviceRegistry.add("notification", notificationService);
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { uiService } from "@web/core/ui_service";
|
||||
import { patch, unpatch } from "@web/core/utils/patch";
|
||||
import { LoadingIndicator } from "@web/webclient/loading_indicator/loading_indicator";
|
||||
import { makeTestEnv } from "../helpers/mock_env";
|
||||
import { getFixture, nextTick } from "../helpers/utils";
|
||||
import { getFixture, nextTick, patchWithCleanup } from "../helpers/utils";
|
||||
|
||||
const { mount } = owl;
|
||||
const serviceRegistry = registry.category("services");
|
||||
@@ -45,7 +45,8 @@ QUnit.test("displays the loading indicator in non debug mode", async (assert) =>
|
||||
});
|
||||
|
||||
QUnit.test("displays the loading indicator for one rpc in debug mode", async (assert) => {
|
||||
const env = await makeTestEnv(Object.assign(baseConfig, { debug: "1" }));
|
||||
patchWithCleanup(odoo, { debug: "1" });
|
||||
const env = await makeTestEnv({ ...baseConfig });
|
||||
await mount(LoadingIndicator, { env, target });
|
||||
let loadingIndicator = target.querySelector(".o_loading");
|
||||
assert.strictEqual(loadingIndicator, null, "the loading indicator should not be displayed");
|
||||
@@ -65,7 +66,8 @@ QUnit.test("displays the loading indicator for one rpc in debug mode", async (as
|
||||
});
|
||||
|
||||
QUnit.test("displays the loading indicator for multi rpc in debug mode", async (assert) => {
|
||||
const env = await makeTestEnv(Object.assign(baseConfig, { debug: "1" }));
|
||||
patchWithCleanup(odoo, { debug: "1" });
|
||||
const env = await makeTestEnv({ ...baseConfig });
|
||||
await mount(LoadingIndicator, { env, target });
|
||||
let loadingIndicator = target.querySelector(".o_loading");
|
||||
assert.strictEqual(loadingIndicator, null, "the loading indicator should not be displayed");
|
||||
|
||||
@@ -5,26 +5,24 @@ import { hotkeyService } from "@web/webclient/hotkeys/hotkey_service";
|
||||
import { SwitchCompanyMenu } from "@web/webclient/switch_company_menu/switch_company_menu";
|
||||
import { registerCleanup } from "../helpers/cleanup";
|
||||
import { makeTestEnv } from "../helpers/mock_env";
|
||||
import { makeFakeUIService, makeFakeUserService } from "../helpers/mock_services";
|
||||
import { click, getFixture } from "../helpers/utils";
|
||||
import { makeFakeCompanyService, makeFakeUIService } from "../helpers/mock_services";
|
||||
import { click, getFixture, patchWithCleanup } from "../helpers/utils";
|
||||
|
||||
const { mount } = owl;
|
||||
const serviceRegistry = registry.category("services");
|
||||
|
||||
QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
hooks.beforeEach(() => {
|
||||
const session_info = {
|
||||
user_companies: {
|
||||
allowed_companies: {
|
||||
1: { id: 1, name: "Hermit" },
|
||||
2: { id: 2, name: "Herman's" },
|
||||
3: { id: 3, name: "Heroes TM" },
|
||||
},
|
||||
current_company: 1,
|
||||
patchWithCleanup(odoo.session_info.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", makeFakeUIService());
|
||||
serviceRegistry.add("user", makeFakeUserService({ session_info }));
|
||||
serviceRegistry.add("company", makeFakeCompanyService());
|
||||
serviceRegistry.add("hotkey", hotkeyService);
|
||||
});
|
||||
|
||||
@@ -61,7 +59,6 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
|
||||
QUnit.test("companies can be toggled and logged in", async (assert) => {
|
||||
assert.expect(22);
|
||||
|
||||
const env = await makeTestEnv();
|
||||
const target = getFixture();
|
||||
const scMenu = await mount(SwitchCompanyMenu, { env, target });
|
||||
@@ -72,8 +69,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [1]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 1);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".toggle_company")[1]);
|
||||
@@ -82,8 +79,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] Company 2 -> toggle
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [1, 2]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 1);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1, 2]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".toggle_company")[1]);
|
||||
@@ -92,8 +89,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [ ] Company 2 -> toggle
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [1]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 1);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".toggle_company")[0]);
|
||||
@@ -102,8 +99,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [ ] Company 2
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [1]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 1);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".log_into")[1]);
|
||||
@@ -112,8 +109,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] **Company 2** -> click label (log into)
|
||||
* [ ] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [2]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 2);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [2]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 2);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".toggle_company")[2]);
|
||||
@@ -122,8 +119,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] **Company 2**
|
||||
* [x] Company 3 -> toggle
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 2);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 2);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".toggle_company")[0]);
|
||||
@@ -132,8 +129,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] **Company 2**
|
||||
* [x] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [2, 3, 1]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 2);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [2, 3, 1]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 2);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".log_into")[0]);
|
||||
@@ -142,8 +139,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] Company 2
|
||||
* [x] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [1, 2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 1);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1, 2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".log_into")[0]);
|
||||
@@ -152,8 +149,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] Company 2
|
||||
* [x] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [1, 2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 1);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1, 2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".toggle_company")[0]);
|
||||
@@ -162,8 +159,8 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] **Company 2**
|
||||
* [x] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 2);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 2);
|
||||
|
||||
await click(scMenu.el.querySelector(".o_dropdown_toggler"));
|
||||
await click(scMenu.el.querySelectorAll(".log_into")[0]);
|
||||
@@ -172,7 +169,7 @@ QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
* [x] Company 2
|
||||
* [x] Company 3
|
||||
*/
|
||||
assert.deepEqual(scMenu.env.services.user.context.allowed_company_ids, [1, 2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.user.current_company.id, 1);
|
||||
assert.deepEqual(scMenu.env.services.company.allowedCompanyIds, [1, 2, 3]);
|
||||
assert.strictEqual(scMenu.env.services.company.currentCompany.id, 1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,9 +8,10 @@ import { patch, unpatch } from "@web/core/utils/patch";
|
||||
import { hotkeyService } from "@web/webclient/hotkeys/hotkey_service";
|
||||
import { UserMenu } from "@web/webclient/user_menu/user_menu";
|
||||
import { preferencesItem } from "@web/webclient/user_menu/user_menu_items";
|
||||
import { userService } from "@web/core/user_service";
|
||||
import { makeTestEnv } from "../helpers/mock_env";
|
||||
import { makeFakeLocalizationService, makeFakeUserService } from "../helpers/mock_services";
|
||||
import { click, getFixture } from "../helpers/utils";
|
||||
import { makeFakeLocalizationService } from "../helpers/mock_services";
|
||||
import { click, getFixture, patchWithCleanup } from "../helpers/utils";
|
||||
|
||||
const { mount } = owl;
|
||||
const serviceRegistry = registry.category("services");
|
||||
@@ -21,7 +22,8 @@ let userMenu;
|
||||
|
||||
QUnit.module("UserMenu", {
|
||||
async beforeEach() {
|
||||
serviceRegistry.add("user", makeFakeUserService({ name: "Sauron" }));
|
||||
patchWithCleanup(odoo.session_info, { name: "Sauron" });
|
||||
serviceRegistry.add("user", userService);
|
||||
serviceRegistry.add("hotkey", hotkeyService);
|
||||
serviceRegistry.add("ui", uiService);
|
||||
target = getFixture();
|
||||
@@ -124,7 +126,8 @@ QUnit.test("can be rendered", async (assert) => {
|
||||
});
|
||||
|
||||
QUnit.test("display the correct name in debug mode", async (assert) => {
|
||||
env = await makeTestEnv({ debug: "1" });
|
||||
patchWithCleanup(odoo, { debug: "1" });
|
||||
env = await makeTestEnv();
|
||||
userMenu = await mount(UserMenu, { env, target });
|
||||
let userMenuEl = userMenu.el;
|
||||
assert.containsOnce(userMenuEl, "img.o_user_avatar");
|
||||
|
||||
@@ -11,8 +11,8 @@ import { hotkeyService } from "@web/webclient/hotkeys/hotkey_service";
|
||||
import { menuService } from "@web/webclient/menu_service";
|
||||
import { WebClient } from "@web/webclient/webclient";
|
||||
import { clearRegistryWithCleanup, makeTestEnv } from "../helpers/mock_env";
|
||||
import { fakeTitleService, makeFakeUserService } from "../helpers/mock_services";
|
||||
import { getFixture } from "../helpers/utils";
|
||||
import { fakeTitleService } from "../helpers/mock_services";
|
||||
import { getFixture, patchWithCleanup } from "../helpers/utils";
|
||||
|
||||
const { Component, tags, mount } = owl;
|
||||
const { xml } = tags;
|
||||
@@ -59,8 +59,7 @@ QUnit.test("can render a main component", async (assert) => {
|
||||
|
||||
QUnit.test("webclient for the superuser", async (assert) => {
|
||||
assert.expect(1);
|
||||
const mockedSessionInfo = { uid: 1 };
|
||||
serviceRegistry.add("user", makeFakeUserService({ session_info: mockedSessionInfo }));
|
||||
patchWithCleanup(odoo.session_info, { uid: 1 });
|
||||
const env = await makeTestEnv(baseConfig);
|
||||
const target = getFixture();
|
||||
const webClient = await mount(WebClient, { env, target });
|
||||
@@ -69,8 +68,7 @@ QUnit.test("webclient for the superuser", async (assert) => {
|
||||
|
||||
QUnit.test("webclient for a non superuser", async (assert) => {
|
||||
assert.expect(1);
|
||||
const mockedSessionInfo = { uid: 2 };
|
||||
serviceRegistry.add("user", makeFakeUserService({ session_info: mockedSessionInfo }));
|
||||
patchWithCleanup(odoo.session_info, { uid: 2 });
|
||||
const env = await makeTestEnv(baseConfig);
|
||||
const target = getFixture();
|
||||
const webClient = await mount(WebClient, { env, target });
|
||||
|
||||
Reference in New Issue
Block a user