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,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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user