mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
test utils refactoring
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { makeTestStore, mockFetch } from "../helpers";
|
||||
import { makeTestData, makeTestEnv } from "../helpers";
|
||||
import { Registry } from "../../src/ts/core/registry";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
@@ -6,19 +7,34 @@ import { makeTestStore, mockFetch } from "../helpers";
|
||||
|
||||
test("does not reload action if already done", async () => {
|
||||
const routes: string[] = [];
|
||||
const store = makeTestStore({
|
||||
rpc: async (route, params) => {
|
||||
const data = await makeTestData();
|
||||
const testEnv = makeTestEnv({
|
||||
...data,
|
||||
mockRPC(route, params) {
|
||||
routes.push(route);
|
||||
return mockFetch(route, params);
|
||||
return this.rpc(route, params);
|
||||
}
|
||||
});
|
||||
|
||||
expect(routes).toEqual([]);
|
||||
|
||||
store.doAction(131);
|
||||
testEnv.store.doAction(131);
|
||||
|
||||
expect(routes).toEqual(["web/action/load"]);
|
||||
|
||||
store.doAction(131);
|
||||
testEnv.store.doAction(131);
|
||||
|
||||
expect(routes).toEqual(["web/action/load"]);
|
||||
});
|
||||
|
||||
test("display a warning if client action is not in registry", async () => {
|
||||
const data = await makeTestData();
|
||||
data.actionRegistry = new Registry();
|
||||
const testEnv = makeTestEnv(data);
|
||||
|
||||
await testEnv.store.doAction(131);
|
||||
|
||||
const notifs = testEnv.store.state.notifications;
|
||||
expect(notifs.length).toBe(1);
|
||||
expect(notifs[0].type).toBe("warning");
|
||||
});
|
||||
|
||||
@@ -1,12 +1,4 @@
|
||||
import { makeTestStore, nextMicroTick } from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function mockFetch(route: string, params: any): Promise<any> {
|
||||
return Promise.resolve(`${route}`);
|
||||
}
|
||||
import { makeTestData, makeTestEnv, nextMicroTick } from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
@@ -14,13 +6,20 @@ function mockFetch(route: string, params: any): Promise<any> {
|
||||
|
||||
describe("rpc", () => {
|
||||
test("properly translate query in route", async () => {
|
||||
const store = makeTestStore({ rpc: mockFetch });
|
||||
const result = await store.rpc({ model: "test", method: "hey" });
|
||||
expect(result).toBe("/web/dataset/call_kw/test/hey");
|
||||
expect.assertions(1);
|
||||
|
||||
const store = makeTestEnv({
|
||||
mockRPC(route, params) {
|
||||
expect(route).toBe("/web/dataset/call_kw/test/hey");
|
||||
return this.rpc(route, params);
|
||||
}
|
||||
}).store;
|
||||
|
||||
await store.rpc({ model: "test", method: "hey" });
|
||||
});
|
||||
|
||||
test("trigger proper events", async () => {
|
||||
const store = makeTestStore({ rpc: mockFetch });
|
||||
const store = makeTestEnv().store;
|
||||
const events: string[] = [];
|
||||
store.on("rpc_status", null, s => {
|
||||
events.push(s);
|
||||
@@ -35,7 +34,7 @@ describe("rpc", () => {
|
||||
|
||||
describe("notifications", () => {
|
||||
test("can subscribe and add notification", () => {
|
||||
const store = makeTestStore();
|
||||
const store = makeTestEnv().store;
|
||||
expect(store.state.notifications.length).toBe(0);
|
||||
const id = store.addNotification({
|
||||
title: "test",
|
||||
@@ -46,7 +45,7 @@ describe("notifications", () => {
|
||||
});
|
||||
|
||||
test("can close a notification", () => {
|
||||
const store = makeTestStore();
|
||||
const store = makeTestEnv().store;
|
||||
|
||||
const id = store.addNotification({
|
||||
title: "test",
|
||||
@@ -60,7 +59,7 @@ describe("notifications", () => {
|
||||
|
||||
test("notifications closes themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
const store = makeTestStore();
|
||||
const store = makeTestEnv().store;
|
||||
|
||||
store.addNotification({ title: "test", message: "message" });
|
||||
|
||||
@@ -72,7 +71,7 @@ describe("notifications", () => {
|
||||
|
||||
test("sticky notifications do not close themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
const store = makeTestStore();
|
||||
const store = makeTestEnv().store;
|
||||
|
||||
store.addNotification({
|
||||
title: "test",
|
||||
@@ -89,7 +88,8 @@ describe("notifications", () => {
|
||||
|
||||
describe("state transitions", () => {
|
||||
test("toggle menu", async () => {
|
||||
const store = makeTestStore();
|
||||
const data = await makeTestData();
|
||||
const store = makeTestEnv(data).store;
|
||||
expect(store.state.inHome).toBe(true);
|
||||
store.toggleHomeMenu();
|
||||
|
||||
@@ -121,7 +121,8 @@ describe("state transitions", () => {
|
||||
|
||||
test("document title", async () => {
|
||||
document.title = "Odoo";
|
||||
const store = makeTestStore();
|
||||
const data = await makeTestData();
|
||||
const store = makeTestEnv(data).store;
|
||||
expect(store.state.inHome).toBe(true);
|
||||
expect(document.title).toBe("Odoo");
|
||||
const promise = store.activateMenuItem(96);
|
||||
|
||||
Reference in New Issue
Block a user