mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
move demo code to examples/
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
export { MockRouter } from "./mock_router";
|
||||
export { MockServer } from "./mock_server";
|
||||
export { makeMenuInfo, makeTestData, TestData } from "./test_data";
|
||||
export { makeTestEnv, TestEnv, TestInfo } from "./test_env";
|
||||
|
||||
export * from "../../../../../tests/helpers";
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Callback } from "../../../../../src/event_bus";
|
||||
import { IRouter, Query, RouterEvent } from "../../src/ts/services/router";
|
||||
|
||||
export class MockRouter implements IRouter {
|
||||
currentQuery: Query;
|
||||
|
||||
constructor(query: Query = {}) {
|
||||
this.currentQuery = query;
|
||||
}
|
||||
|
||||
navigate(query: Query) {
|
||||
this.currentQuery = query;
|
||||
}
|
||||
on(event: RouterEvent, owner: any, callback: Callback) {}
|
||||
getQuery(): Query {
|
||||
return this.currentQuery;
|
||||
}
|
||||
|
||||
formatURL(path: string, query: Query): string {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { TestData } from "./test_data";
|
||||
|
||||
export class MockServer {
|
||||
data: TestData;
|
||||
|
||||
constructor(data: TestData) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
rpc(route: string, params: any): Promise<any> {
|
||||
if (route === "web/action/load") {
|
||||
const action = this.data.actions.find(a => a.id === params.action_id);
|
||||
return Promise.resolve(action);
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
import { BaseMenuItem, getMenuInfo } from "../../src/ts/loaders";
|
||||
import { ActionDescription } from "../../src/ts/store/action_manager_mixin";
|
||||
import { MenuInfo } from "../../src/ts/store/store";
|
||||
|
||||
export interface TestData {
|
||||
menuInfo: MenuInfo;
|
||||
actions: ActionDescription[];
|
||||
}
|
||||
|
||||
export function makeTestData(): TestData {
|
||||
return {
|
||||
menuInfo: makeMenuInfo(),
|
||||
actions: makeActionData()
|
||||
};
|
||||
}
|
||||
|
||||
export function makeMenuInfo(): MenuInfo {
|
||||
const items: BaseMenuItem[] = [
|
||||
{
|
||||
id: 96,
|
||||
name: "Discuss",
|
||||
parent_id: false,
|
||||
action: "ir.actions.client,131",
|
||||
icon: "fa fa-comment",
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 205,
|
||||
name: "Notes",
|
||||
parent_id: false,
|
||||
action: "ir.actions.act_window,250",
|
||||
icon: "fa fa-pen",
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 409,
|
||||
name: "CRM",
|
||||
parent_id: false,
|
||||
action: "ir.actions.act_window,597",
|
||||
icon: "fa fa-handshake",
|
||||
children: [
|
||||
{
|
||||
id: 418,
|
||||
name: "Sales",
|
||||
parent_id: 409,
|
||||
action: false,
|
||||
icon: false,
|
||||
children: [
|
||||
{
|
||||
id: 423,
|
||||
name: "My Pipeline",
|
||||
parent_id: 418,
|
||||
action: "ir.actions.act_window,597",
|
||||
icon: false,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 812,
|
||||
name: "My Quotations",
|
||||
parent_id: 418,
|
||||
action: "ir.actions.act_window,1051",
|
||||
icon: false,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 419,
|
||||
name: "Team Pipelines",
|
||||
parent_id: 418,
|
||||
action: "ir.actions.act_window,275",
|
||||
icon: false,
|
||||
children: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 421,
|
||||
name: "Leads",
|
||||
parent_id: 409,
|
||||
action: false,
|
||||
icon: false,
|
||||
children: [
|
||||
{
|
||||
id: 422,
|
||||
name: "Leads",
|
||||
parent_id: 421,
|
||||
action: "ir.actions.act_window,595",
|
||||
icon: false,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 752,
|
||||
name: "Scoring Rules",
|
||||
parent_id: 421,
|
||||
icon: false,
|
||||
action: "ir.actions.act_window,1083",
|
||||
children: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
return getMenuInfo(items);
|
||||
}
|
||||
|
||||
function makeActionData(): ActionDescription[] {
|
||||
return [
|
||||
{
|
||||
id: 131,
|
||||
type: "ir.actions.client",
|
||||
target: "current",
|
||||
name: "Discuss",
|
||||
tag: "mail.discuss"
|
||||
},
|
||||
{
|
||||
id: 250,
|
||||
type: "ir.actions.act_window",
|
||||
name: "Notes",
|
||||
target: "current",
|
||||
domain: false,
|
||||
context: "{}",
|
||||
views: [[false, "kanban"], [false, "list"], [false, "form"]],
|
||||
res_id: 0,
|
||||
res_model: "note.note"
|
||||
},
|
||||
{
|
||||
id: 597,
|
||||
type: "ir.actions.act_window",
|
||||
name: "Pipeline",
|
||||
target: "current",
|
||||
domain: false,
|
||||
context: { default_team_id: 1 },
|
||||
views: [[2103, "kanban"], [2106, "list"], [2105, "form"]],
|
||||
res_id: 0,
|
||||
res_model: "crm.lead"
|
||||
},
|
||||
{
|
||||
id: 1051,
|
||||
type: "ir.actions.act_window",
|
||||
name: "Quotations",
|
||||
target: "current",
|
||||
domain: false,
|
||||
context: "{'search_default_my_quotation': 1}",
|
||||
views: [
|
||||
[3387, "list"],
|
||||
[3385, "kanban"],
|
||||
[3389, "form"],
|
||||
[3382, "calendar"],
|
||||
[3384, "pivot"],
|
||||
[3383, "graph"]
|
||||
],
|
||||
res_id: 0,
|
||||
res_model: "sale.order"
|
||||
},
|
||||
{
|
||||
id: 275,
|
||||
type: "ir.actions.act_window",
|
||||
name: "Team Pipelines",
|
||||
target: "current",
|
||||
context: "{}",
|
||||
domain: "[('use_opportunities', '=', True)]",
|
||||
views: [[false, "kanban"], [false, "form"]],
|
||||
res_id: 0,
|
||||
res_model: "crm.team"
|
||||
},
|
||||
{
|
||||
id: 595,
|
||||
type: "ir.actions.act_window",
|
||||
name: "Leads",
|
||||
target: "current",
|
||||
context:
|
||||
"{ 'default_type':'lead', 'search_default_type': 'lead', 'search_default_to_process':1, }",
|
||||
domain: "['|', ('type','=','lead'), ('type','=',False)]",
|
||||
views: [
|
||||
[2098, "list"],
|
||||
[2099, "kanban"],
|
||||
[2100, "calendar"],
|
||||
[2108, "pivot"],
|
||||
[2107, "graph"],
|
||||
[false, "form"]
|
||||
],
|
||||
res_id: 0,
|
||||
res_model: "crm.lead"
|
||||
},
|
||||
{
|
||||
id: 1083,
|
||||
type: "ir.actions.act_window",
|
||||
name: "Scores",
|
||||
target: "current",
|
||||
context: "{}",
|
||||
domain: false,
|
||||
views: [[false, "list"], [false, "kanban"], [false, "form"]],
|
||||
res_id: 0,
|
||||
res_model: "website.crm.score"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
// function loadTemplates(): Promise<string> {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// readFile("web/static/src/xml/templates.xml", "utf-8", (err, result) => {
|
||||
// resolve(result);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
// export async function makeTestData(): Promise<TestData> {
|
||||
// if (!templates) {
|
||||
// templates = await loadTemplates();
|
||||
// }
|
||||
// const _actionRegistry: typeof actionRegistry = new Registry();
|
||||
// (<any>_actionRegistry).map = Object.assign({}, (<any>actionRegistry).map);
|
||||
// const _viewRegistry: typeof actionRegistry = new Registry();
|
||||
// (<any>_viewRegistry).map = Object.assign({}, (<any>actionRegistry).map);
|
||||
|
||||
// return {
|
||||
// menuInfo: makeMenuInfo(),
|
||||
// actions: makeActionData(),
|
||||
// actionRegistry: _actionRegistry,
|
||||
// viewRegistry: _viewRegistry,
|
||||
// templates
|
||||
// };
|
||||
// }
|
||||
@@ -0,0 +1,88 @@
|
||||
import { readFileSync } from "fs";
|
||||
import { Env as WEnv } from "../../../../../src/component";
|
||||
import { QWeb } from "../../../../../src/qweb";
|
||||
import { Registry } from "../../../../../src/registry";
|
||||
import { Env, InitData, linkStoreToEnv, makeEnv } from "../../src/ts/env";
|
||||
import {
|
||||
actionRegistry as AR,
|
||||
viewRegistry as VR
|
||||
} from "../../src/ts/registries";
|
||||
import { Store } from "../../src/ts/store/store";
|
||||
import { MockRouter } from "./mock_router";
|
||||
import { MockServer } from "./mock_server";
|
||||
import { makeTestData, TestData } from "./test_data";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
export interface TestEnv extends Env {
|
||||
store: Store;
|
||||
}
|
||||
|
||||
export interface TestInfo extends Partial<InitData>, Partial<TestData> {
|
||||
mockRPC?(this: MockServer, route: string, params: any): Promise<any>;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Code
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const TEMPLATES = readFileSync(
|
||||
"examples/web/static/src/xml/templates.xml",
|
||||
"utf-8"
|
||||
);
|
||||
|
||||
export function makeTestWEnv(): WEnv {
|
||||
return {
|
||||
qweb: new QWeb()
|
||||
};
|
||||
}
|
||||
|
||||
export function makeTestEnv(info: TestInfo = {}): TestEnv {
|
||||
const templates = info.templates || TEMPLATES;
|
||||
const testData: TestData = makeTestData();
|
||||
if (info.menuInfo) {
|
||||
testData.menuInfo = info.menuInfo;
|
||||
}
|
||||
if (info.actions) {
|
||||
testData.actions = info.actions;
|
||||
}
|
||||
|
||||
const actionRegistry = info.actionRegistry || cloneRegistry(AR);
|
||||
const viewRegistry = info.viewRegistry || cloneRegistry(VR);
|
||||
|
||||
let rpc = info.services && info.services.rpc;
|
||||
if (!rpc) {
|
||||
const mockServer = new MockServer(testData);
|
||||
rpc = function(route: string, params: any): Promise<any> {
|
||||
if (info.mockRPC) {
|
||||
return info.mockRPC.call(mockServer, route, params);
|
||||
}
|
||||
return mockServer.rpc(route, params);
|
||||
};
|
||||
}
|
||||
|
||||
const router = (info.services && info.services.router) || new MockRouter();
|
||||
const initData: InitData = {
|
||||
services: {
|
||||
rpc,
|
||||
router
|
||||
},
|
||||
actionRegistry,
|
||||
viewRegistry,
|
||||
templates
|
||||
};
|
||||
|
||||
const env = makeEnv(initData);
|
||||
const store = new Store(env, testData.menuInfo);
|
||||
linkStoreToEnv(env, store);
|
||||
const testEnv = Object.assign({ store }, env);
|
||||
return testEnv;
|
||||
}
|
||||
|
||||
function cloneRegistry<T>(registry: Registry<T>): Registry<T> {
|
||||
const clone: Registry<T> = new Registry();
|
||||
(<any>clone).map = Object.assign({}, (<any>registry).map);
|
||||
return clone;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Registry } from "../../../../../src/registry";
|
||||
import { makeTestEnv } from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
test("does not reload action if already done", async () => {
|
||||
const routes: string[] = [];
|
||||
const testEnv = makeTestEnv({
|
||||
mockRPC(route, params) {
|
||||
routes.push(route);
|
||||
return this.rpc(route, params);
|
||||
}
|
||||
});
|
||||
|
||||
expect(routes).toEqual([]);
|
||||
|
||||
testEnv.store.doAction(131);
|
||||
|
||||
expect(routes).toEqual(["web/action/load"]);
|
||||
|
||||
testEnv.store.doAction(131);
|
||||
|
||||
expect(routes).toEqual(["web/action/load"]);
|
||||
});
|
||||
|
||||
test("display a warning if client action is not in registry", async () => {
|
||||
const testEnv = makeTestEnv({ actionRegistry: new Registry() });
|
||||
|
||||
await testEnv.store.doAction(131);
|
||||
|
||||
const notifs = testEnv.store.state.notifications;
|
||||
expect(notifs.length).toBe(1);
|
||||
expect(notifs[0].type).toBe("warning");
|
||||
});
|
||||
|
||||
test("display a warning if view is not in registry", async () => {
|
||||
const testEnv = makeTestEnv({ viewRegistry: new Registry() });
|
||||
|
||||
await testEnv.store.doAction(250);
|
||||
|
||||
const notifs = testEnv.store.state.notifications;
|
||||
expect(notifs.length).toBe(1);
|
||||
expect(notifs[0].type).toBe("warning");
|
||||
});
|
||||
@@ -0,0 +1,143 @@
|
||||
import { Store } from "../../src/ts/store/store";
|
||||
import { makeTestEnv, nextMicroTick, TestInfo } from "../helpers";
|
||||
|
||||
function makeTestStore(info?: TestInfo): Store {
|
||||
return makeTestEnv(info).store;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
describe("rpc", () => {
|
||||
test("properly translate query in route", async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const store = makeTestStore({
|
||||
mockRPC(route, params) {
|
||||
expect(route).toBe("/web/dataset/call_kw/test/hey");
|
||||
return this.rpc(route, params);
|
||||
}
|
||||
});
|
||||
|
||||
await store.rpc({ model: "test", method: "hey" });
|
||||
});
|
||||
|
||||
test("trigger proper events", async () => {
|
||||
const store = makeTestStore();
|
||||
const events: string[] = [];
|
||||
store.on("rpc_status", null, s => {
|
||||
events.push(s);
|
||||
});
|
||||
expect(events).toEqual([]);
|
||||
store.rpc({ model: "test", method: "hey" });
|
||||
expect(events).toEqual(["loading"]);
|
||||
await nextMicroTick();
|
||||
expect(events).toEqual(["loading", "notloading"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("notifications", () => {
|
||||
test("can subscribe and add notification", () => {
|
||||
const store = makeTestStore();
|
||||
expect(store.state.notifications.length).toBe(0);
|
||||
const id = store.addNotification({
|
||||
title: "test",
|
||||
message: "message"
|
||||
});
|
||||
expect(store.state.notifications.length).toBe(1);
|
||||
expect(id).toBeDefined();
|
||||
});
|
||||
|
||||
test("can close a notification", () => {
|
||||
const store = makeTestStore();
|
||||
|
||||
const id = store.addNotification({
|
||||
title: "test",
|
||||
message: "message"
|
||||
});
|
||||
expect(store.state.notifications.length).toBe(1);
|
||||
|
||||
store.closeNotification(id);
|
||||
expect(store.state.notifications.length).toBe(0);
|
||||
});
|
||||
|
||||
test("notifications closes themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
const store = makeTestStore();
|
||||
|
||||
store.addNotification({ title: "test", message: "message" });
|
||||
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(store.state.notifications.length).toBe(1);
|
||||
jest.runAllTimers();
|
||||
expect(store.state.notifications.length).toBe(0);
|
||||
});
|
||||
|
||||
test("sticky notifications do not close themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
const store = makeTestStore();
|
||||
|
||||
store.addNotification({
|
||||
title: "test",
|
||||
message: "message",
|
||||
sticky: true
|
||||
});
|
||||
|
||||
expect(setTimeout).toHaveBeenCalledTimes(0);
|
||||
expect(store.state.notifications.length).toBe(1);
|
||||
jest.runAllTimers();
|
||||
expect(store.state.notifications.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("state transitions", () => {
|
||||
test("toggle menu", async () => {
|
||||
const env = makeTestEnv();
|
||||
const store = env.store;
|
||||
expect(store.state.inHome).toBe(true);
|
||||
store.toggleHomeMenu();
|
||||
|
||||
// should still be in home menu since no app is currently active
|
||||
expect(store.state.inHome).toBe(true);
|
||||
expect(env.services.router.getQuery()).toEqual({ home: true });
|
||||
|
||||
const promise = store.activateMenuItem(96);
|
||||
expect(env.services.router.getQuery()).toEqual({ home: true });
|
||||
|
||||
await promise;
|
||||
store.activateController(store.lastController!);
|
||||
expect(store.state.inHome).toBe(false);
|
||||
expect(env.services.router.getQuery()).toEqual({
|
||||
action_id: "131",
|
||||
menu_id: "96"
|
||||
});
|
||||
|
||||
store.toggleHomeMenu();
|
||||
expect(store.state.inHome).toBe(true);
|
||||
expect(env.services.router.getQuery()).toEqual({ home: true });
|
||||
store.toggleHomeMenu();
|
||||
expect(store.state.inHome).toBe(false);
|
||||
expect(env.services.router.getQuery()).toEqual({
|
||||
action_id: "131",
|
||||
menu_id: "96"
|
||||
});
|
||||
});
|
||||
|
||||
test("document title", async () => {
|
||||
document.title = "Odoo";
|
||||
const store = makeTestStore();
|
||||
expect(store.state.inHome).toBe(true);
|
||||
expect(document.title).toBe("Odoo");
|
||||
const promise = store.activateMenuItem(96);
|
||||
expect(document.title).toBe("Odoo");
|
||||
await promise;
|
||||
store.activateController(store.lastController!);
|
||||
|
||||
expect(document.title).toBe("Discuss - Odoo");
|
||||
|
||||
store.toggleHomeMenu();
|
||||
|
||||
expect(document.title).toBe("Discuss - Odoo");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`can be rendered 1`] = `
|
||||
"<div class=\\"o_home_menu\\">
|
||||
<div class=\\"o_apps\\">
|
||||
<a href=\\"#menu_id=96&action_id=131\\" class=\\"o_app\\" data-menu=\\"96\\">
|
||||
<i class=\\"fa fa-comment o_app_icon fa-3x fa-fw\\"></i>
|
||||
<div class=\\"o_caption\\">
|
||||
Discuss
|
||||
</div>
|
||||
</a><a href=\\"#menu_id=205&action_id=250\\" class=\\"o_app\\" data-menu=\\"205\\">
|
||||
<i class=\\"fa fa-pen o_app_icon fa-3x fa-fw\\"></i>
|
||||
<div class=\\"o_caption\\">
|
||||
Notes
|
||||
</div>
|
||||
</a><a href=\\"#menu_id=409&action_id=597\\" class=\\"o_app\\" data-menu=\\"409\\">
|
||||
<i class=\\"fa fa-handshake o_app_icon fa-3x fa-fw\\"></i>
|
||||
<div class=\\"o_caption\\">
|
||||
CRM
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>"
|
||||
`;
|
||||
@@ -0,0 +1,45 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`can be rendered (in home menu, no app) 1`] = `
|
||||
"<div class=\\"o_navbar o_in_home\\">
|
||||
|
||||
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`can be rendered (in home menu, one active app) 1`] = `
|
||||
"<div class=\\"o_navbar o_in_home\\">
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-chevron-left\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`can render one menu item 1`] = `
|
||||
"<div class=\\"o_navbar\\">
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
|
||||
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
||||
Discuss
|
||||
</a>
|
||||
<ul class=\\"o_menu_sections\\">
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`mobile mode: navbar is different 1`] = `
|
||||
"<div class=\\"o_navbar\\">
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
|
||||
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
||||
Notes
|
||||
</a>
|
||||
<ul class=\\"o_menu_sections\\">
|
||||
|
||||
<li>MOBILEMODE</li>
|
||||
</ul>
|
||||
|
||||
</div>"
|
||||
`;
|
||||
@@ -0,0 +1,27 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`can be rendered (type = warning) 1`] = `
|
||||
"<div class=\\"o_notification o_error\\">
|
||||
|
||||
<div class=\\"o_notification_title\\">
|
||||
<span class=\\"o_icon fa fa-3x fa-exclamation\\" role=\\"img\\" aria-label=\\"Notification title\\" title=\\"Notification title\\"></span>
|
||||
title
|
||||
</div>
|
||||
<div class=\\"o_notification_content\\">
|
||||
message
|
||||
</div>
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`can be rendered 1`] = `
|
||||
"<div class=\\"o_notification\\">
|
||||
|
||||
<div class=\\"o_notification_title\\">
|
||||
<span class=\\"o_icon fa fa-3x fa-lightbulb\\" role=\\"img\\" aria-label=\\"Notification title\\" title=\\"Notification title\\"></span>
|
||||
title
|
||||
</div>
|
||||
<div class=\\"o_notification_content\\">
|
||||
message
|
||||
</div>
|
||||
</div>"
|
||||
`;
|
||||
@@ -0,0 +1,257 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`can be rendered (in home menu) 1`] = `
|
||||
"<div class=\\"o_web_client\\">
|
||||
<div class=\\"o_navbar o_in_home\\">
|
||||
|
||||
|
||||
</div>
|
||||
<div class=\\"o_home_menu\\">
|
||||
<div class=\\"o_apps\\">
|
||||
<a href=\\"#menu_id=96&action_id=131\\" class=\\"o_app\\" data-menu=\\"96\\">
|
||||
<i class=\\"fa fa-comment o_app_icon fa-3x fa-fw\\"></i>
|
||||
<div class=\\"o_caption\\">
|
||||
Discuss
|
||||
</div>
|
||||
</a><a href=\\"#menu_id=205&action_id=250\\" class=\\"o_app\\" data-menu=\\"205\\">
|
||||
<i class=\\"fa fa-pen o_app_icon fa-3x fa-fw\\"></i>
|
||||
<div class=\\"o_caption\\">
|
||||
Notes
|
||||
</div>
|
||||
</a><a href=\\"#menu_id=409&action_id=597\\" class=\\"o_app\\" data-menu=\\"409\\">
|
||||
<i class=\\"fa fa-handshake o_app_icon fa-3x fa-fw\\"></i>
|
||||
<div class=\\"o_caption\\">
|
||||
CRM
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class=\\"o_content o_hidden\\"></div>
|
||||
<div class=\\"o_notification_container\\">
|
||||
|
||||
</div>
|
||||
<div class=\\"o_loading d-none\\">Loading</div>
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`clicks on client action with invalid key => empty widget is rendered + warning 1`] = `
|
||||
"<div class=\\"o_web_client\\">
|
||||
<div class=\\"o_navbar\\">
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
|
||||
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
||||
Discuss
|
||||
</a>
|
||||
<ul class=\\"o_menu_sections\\">
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class=\\"o_content\\"><div class=\\"o_action_controller\\"></div></div>
|
||||
<div class=\\"o_notification_container\\">
|
||||
|
||||
<div class=\\"o_notification o_error\\">
|
||||
|
||||
<div class=\\"o_notification_title\\">
|
||||
<span class=\\"o_icon fa fa-3x fa-exclamation\\" role=\\"img\\" aria-label=\\"Notification Invalid Client Action\\" title=\\"Notification Invalid Client Action\\"></span>
|
||||
Invalid Client Action
|
||||
</div>
|
||||
<div class=\\"o_notification_content\\">
|
||||
Cannot find widget 'mail.discuss' in the action registry
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class=\\"o_loading d-none\\">Loading</div>
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`if url has action_id, will render action and navigate to proper menu_id 1`] = `
|
||||
"<div class=\\"o_web_client\\">
|
||||
<div class=\\"o_navbar\\">
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
|
||||
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
||||
Discuss
|
||||
</a>
|
||||
<ul class=\\"o_menu_sections\\">
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class=\\"o_content\\"><div class=\\"o_discuss o_action_controller\\">
|
||||
<div class=\\"o_control_panel\\">
|
||||
<ol class=\\"breadcrumb\\" role=\\"navigation\\">
|
||||
<li class=\\"breadcrumb-item active\\">
|
||||
Discuss
|
||||
</li>
|
||||
</ol>
|
||||
<div class=\\"o_cp_searchview\\" role=\\"search\\">
|
||||
<div class=\\"o_searchview\\" role=\\"search\\" aria-autocomplete=\\"list\\">
|
||||
<span class=\\"o_searchview_more fa\\" title=\\"Advanced Search...\\" role=\\"img\\" aria-label=\\"Advanced Search...\\"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class=\\"o_cp_left\\">
|
||||
<div class=\\"o_cp_buttons\\" role=\\"toolbar\\" aria-label=\\"Control panel toolbar\\"></div>
|
||||
<aside class=\\"o_cp_sidebar\\"></aside>
|
||||
</div>
|
||||
<div class=\\"o_cp_right\\">
|
||||
<div class=\\"btn-group o_search_options\\" role=\\"search\\"></div>
|
||||
<nav class=\\"o_cp_pager\\" role=\\"search\\" aria-label=\\"Pager\\"></nav>
|
||||
<nav class=\\"btn-group o_cp_switch_buttons\\" role=\\"toolbar\\" aria-label=\\"View switcher\\"></nav>
|
||||
</div>
|
||||
</div>
|
||||
<div class=\\"o_content\\">
|
||||
<div class=\\"o_discuss_sidebar\\">
|
||||
<span>DISCUSS!!</span>
|
||||
</div>
|
||||
<div class=\\"o_discuss_content\\">
|
||||
<button>Reset first counter</button>
|
||||
<button>Reset counter 2 in 3s</button>
|
||||
<button>Toggle Clock/counters</button>
|
||||
<button>Toggle Color</button>
|
||||
<button>Rerender this widget</button>
|
||||
<input>
|
||||
|
||||
<div>
|
||||
<button>-</button>
|
||||
<span style=\\"font-weight:bold\\">Value: 4</span>
|
||||
<button>+</button>
|
||||
</div>
|
||||
<div>
|
||||
<button>-</button>
|
||||
<span style=\\"font-weight:bold\\">Value: 400</span>
|
||||
<button>+</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>Current Color: </span>
|
||||
red
|
||||
</div>
|
||||
<button>Add notif</button>
|
||||
<button>Add sticky notif</button>
|
||||
<button>Add warning</button>
|
||||
</div>
|
||||
</div>
|
||||
</div></div>
|
||||
<div class=\\"o_notification_container\\">
|
||||
|
||||
</div>
|
||||
<div class=\\"o_loading d-none\\">Loading</div>
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`open act window action with invalid viewtype => empty widget is rendered + warning 1`] = `
|
||||
"<div class=\\"o_web_client\\">
|
||||
<div class=\\"o_navbar\\">
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
|
||||
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
||||
Notes
|
||||
</a>
|
||||
<ul class=\\"o_menu_sections\\">
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class=\\"o_content\\"><div class=\\"o_action_controller\\"></div></div>
|
||||
<div class=\\"o_notification_container\\">
|
||||
|
||||
<div class=\\"o_notification o_error\\">
|
||||
|
||||
<div class=\\"o_notification_title\\">
|
||||
<span class=\\"o_icon fa fa-3x fa-exclamation\\" role=\\"img\\" aria-label=\\"Notification Invalid View type\\" title=\\"Notification Invalid View type\\"></span>
|
||||
Invalid View type
|
||||
</div>
|
||||
<div class=\\"o_notification_content\\">
|
||||
Cannot find view of type 'kanban' in the view registry
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class=\\"o_loading d-none\\">Loading</div>
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`start with no action => clicks on client action => discuss is rendered 1`] = `
|
||||
"<div class=\\"o_web_client\\">
|
||||
<div class=\\"o_navbar\\">
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
|
||||
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
|
||||
Discuss
|
||||
</a>
|
||||
<ul class=\\"o_menu_sections\\">
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class=\\"o_content\\"><div class=\\"o_discuss o_action_controller\\">
|
||||
<div class=\\"o_control_panel\\">
|
||||
<ol class=\\"breadcrumb\\" role=\\"navigation\\">
|
||||
<li class=\\"breadcrumb-item active\\">
|
||||
Discuss
|
||||
</li>
|
||||
</ol>
|
||||
<div class=\\"o_cp_searchview\\" role=\\"search\\">
|
||||
<div class=\\"o_searchview\\" role=\\"search\\" aria-autocomplete=\\"list\\">
|
||||
<span class=\\"o_searchview_more fa\\" title=\\"Advanced Search...\\" role=\\"img\\" aria-label=\\"Advanced Search...\\"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class=\\"o_cp_left\\">
|
||||
<div class=\\"o_cp_buttons\\" role=\\"toolbar\\" aria-label=\\"Control panel toolbar\\"></div>
|
||||
<aside class=\\"o_cp_sidebar\\"></aside>
|
||||
</div>
|
||||
<div class=\\"o_cp_right\\">
|
||||
<div class=\\"btn-group o_search_options\\" role=\\"search\\"></div>
|
||||
<nav class=\\"o_cp_pager\\" role=\\"search\\" aria-label=\\"Pager\\"></nav>
|
||||
<nav class=\\"btn-group o_cp_switch_buttons\\" role=\\"toolbar\\" aria-label=\\"View switcher\\"></nav>
|
||||
</div>
|
||||
</div>
|
||||
<div class=\\"o_content\\">
|
||||
<div class=\\"o_discuss_sidebar\\">
|
||||
<span>DISCUSS!!</span>
|
||||
</div>
|
||||
<div class=\\"o_discuss_content\\">
|
||||
<button>Reset first counter</button>
|
||||
<button>Reset counter 2 in 3s</button>
|
||||
<button>Toggle Clock/counters</button>
|
||||
<button>Toggle Color</button>
|
||||
<button>Rerender this widget</button>
|
||||
<input>
|
||||
|
||||
<div>
|
||||
<button>-</button>
|
||||
<span style=\\"font-weight:bold\\">Value: 4</span>
|
||||
<button>+</button>
|
||||
</div>
|
||||
<div>
|
||||
<button>-</button>
|
||||
<span style=\\"font-weight:bold\\">Value: 400</span>
|
||||
<button>+</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>Current Color: </span>
|
||||
red
|
||||
</div>
|
||||
<button>Add notif</button>
|
||||
<button>Add sticky notif</button>
|
||||
<button>Add warning</button>
|
||||
</div>
|
||||
</div>
|
||||
</div></div>
|
||||
<div class=\\"o_notification_container\\">
|
||||
|
||||
</div>
|
||||
<div class=\\"o_loading d-none\\">Loading</div>
|
||||
</div>"
|
||||
`;
|
||||
@@ -0,0 +1,28 @@
|
||||
import { HomeMenu } from "../../src/ts/ui/home_menu";
|
||||
import { makeTestEnv, makeTestFixture } from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
let fixture: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.remove();
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
test("can be rendered", async () => {
|
||||
const testEnv = makeTestEnv();
|
||||
const props = { menuInfo: testEnv.store.menuInfo };
|
||||
const homeMenu = new HomeMenu(testEnv, props);
|
||||
await homeMenu.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import { MenuInfo } from "../../src/ts/store/store";
|
||||
import { Navbar, Props } from "../../src/ts/ui/navbar";
|
||||
import * as helpers from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
let fixture: HTMLElement;
|
||||
let env: helpers.TestEnv;
|
||||
let props: Props;
|
||||
let menuInfo: MenuInfo;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = helpers.makeTestFixture();
|
||||
env = helpers.makeTestEnv();
|
||||
props = { inHome: false, app: null };
|
||||
menuInfo = env.store.menuInfo;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.remove();
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
test("can be rendered (in home menu, no app)", async () => {
|
||||
props.inHome = true;
|
||||
const navbar = new Navbar(env, props);
|
||||
await navbar.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("can be rendered (in home menu, one active app)", async () => {
|
||||
props = { inHome: true, app: menuInfo.menus[96]! };
|
||||
const navbar = new Navbar(env, props);
|
||||
await navbar.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("can render one menu item", async () => {
|
||||
props.app = menuInfo.menus[96]!;
|
||||
const navbar = new Navbar(env, props);
|
||||
await navbar.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("mobile mode: navbar is different", async () => {
|
||||
props.app = menuInfo.menus[205]!;
|
||||
env.isMobile = true;
|
||||
const navbar = new Navbar(env, props);
|
||||
await navbar.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("clicking on left icon toggle home menu ", async () => {
|
||||
props.app = menuInfo.menus[96]!;
|
||||
env.store.state.inHome = false;
|
||||
const navbar = new Navbar(env, props);
|
||||
await navbar.mount(fixture);
|
||||
expect(env.store.state.inHome).toBe(false);
|
||||
(<any>fixture).getElementsByClassName("o_title")[0].click();
|
||||
expect(env.store.state.inHome).toBe(true);
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Notification as INotification } from "../../src/ts/store/store";
|
||||
import { Notification } from "../../src/ts/ui/notification";
|
||||
import * as helpers from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
let fixture: HTMLElement;
|
||||
let env: helpers.TestEnv;
|
||||
|
||||
beforeEach(async () => {
|
||||
fixture = helpers.makeTestFixture();
|
||||
env = helpers.makeTestEnv();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.remove();
|
||||
});
|
||||
|
||||
function makeNotification(notif: Partial<INotification> = {}): INotification {
|
||||
const defaultNotif = {
|
||||
id: 1,
|
||||
title: "title",
|
||||
message: "message",
|
||||
type: "notification",
|
||||
sticky: false
|
||||
};
|
||||
return Object.assign(defaultNotif, notif);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
test("can be rendered", async () => {
|
||||
const notif = makeNotification({ title: "title", message: "message" });
|
||||
const navbar = new Notification(env, notif);
|
||||
await navbar.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("can be rendered (type = warning)", async () => {
|
||||
const notif = makeNotification({
|
||||
title: "title",
|
||||
message: "message",
|
||||
type: "warning"
|
||||
});
|
||||
const navbar = new Notification(env, notif);
|
||||
await navbar.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("can be closed by clicking on it (if sticky)", async () => {
|
||||
env.addNotification({
|
||||
title: "title",
|
||||
message: "message",
|
||||
sticky: true
|
||||
});
|
||||
|
||||
const navbar = new Notification(env, env.store.state.notifications[0]);
|
||||
await navbar.mount(fixture);
|
||||
expect(env.store.state.notifications.length).toBe(1);
|
||||
(<any>fixture.getElementsByClassName("o_close")[0]).click();
|
||||
expect(env.store.state.notifications.length).toBe(0);
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import { Registry } from "../../../../../src/registry";
|
||||
import { Root } from "../../src/ts/ui/root";
|
||||
import * as helpers from "../helpers";
|
||||
import { makeTestEnv } from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
let fixture: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = helpers.makeTestFixture();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.remove();
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
test("can be rendered (in home menu)", async () => {
|
||||
const testEnv = makeTestEnv();
|
||||
const root = new Root(testEnv, testEnv.store);
|
||||
await root.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("if url has action_id, will render action and navigate to proper menu_id", async () => {
|
||||
const router = new helpers.MockRouter({ action_id: "131" });
|
||||
const testEnv = makeTestEnv({ services: <any>{ router } });
|
||||
await helpers.nextTick();
|
||||
|
||||
const root = new Root(testEnv, testEnv.store);
|
||||
await root.mount(fixture);
|
||||
await helpers.nextTick();
|
||||
expect(router.getQuery()).toEqual({
|
||||
action_id: "131",
|
||||
menu_id: "96"
|
||||
});
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("start with no action => clicks on client action => discuss is rendered", async () => {
|
||||
const testEnv = makeTestEnv();
|
||||
const root = new Root(testEnv, testEnv.store);
|
||||
await root.mount(fixture);
|
||||
|
||||
expect(testEnv.services.router.getQuery()).toEqual({ home: true });
|
||||
|
||||
// discuss menu item
|
||||
await (<any>document.querySelector('[data-menu="96"]')).click();
|
||||
await helpers.nextTick();
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
expect(testEnv.services.router.getQuery()).toEqual({
|
||||
action_id: "131",
|
||||
menu_id: "96"
|
||||
});
|
||||
});
|
||||
|
||||
test("clicks on client action with invalid key => empty widget is rendered + warning", async () => {
|
||||
const testEnv = makeTestEnv({ actionRegistry: new Registry() });
|
||||
const root = new Root(testEnv, testEnv.store);
|
||||
await root.mount(fixture);
|
||||
|
||||
// discuss menu item
|
||||
await (<any>document.querySelector('[data-menu="96"]')).click();
|
||||
await helpers.nextTick();
|
||||
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("open act window action with invalid viewtype => empty widget is rendered + warning", async () => {
|
||||
const testEnv = makeTestEnv({ viewRegistry: new Registry() });
|
||||
const root = new Root(testEnv, testEnv.store);
|
||||
await root.mount(fixture);
|
||||
|
||||
// note menu item
|
||||
await (<any>document.querySelector('[data-menu="205"]')).click();
|
||||
await helpers.nextTick();
|
||||
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
Reference in New Issue
Block a user