make ajax emit rpc events

This commit is contained in:
Géry Debongnie
2019-02-06 16:38:52 +01:00
parent 82d8ca9da8
commit 87facd993b
3 changed files with 58 additions and 5 deletions
+2 -2
View File
@@ -1,14 +1,14 @@
import { readFile } from "fs";
import { Ajax, RPCQuery } from "../src/ts/services/ajax";
import { WEnv } from "../src/ts/core/component";
import { Callback } from "../src/ts/core/event_bus";
import { NotificationManager } from "../src/ts/core/notifications";
import { QWeb } from "../src/ts/core/qweb_vdom";
import { actionRegistry } from "../src/ts/registries";
import { IRouter, Query, RouterEvent } from "../src/ts/core/router";
import { idGenerator } from "../src/ts/core/utils";
import { getMenuInfo } from "../src/ts/init";
import { actionRegistry } from "../src/ts/registries";
import { ActionManager } from "../src/ts/services/action_manager";
import { Ajax } from "../src/ts/services/ajax";
import { MenuInfo } from "../src/ts/widgets/root";
import { Env } from "../src/ts/widgets/widget";
+37
View File
@@ -0,0 +1,37 @@
import { Ajax } from "../../src/ts/services/ajax";
import { nextMicroTick } from "../helpers";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
function mockFetch(route: string, params: any): Promise<any> {
return Promise.resolve(`${route}`);
}
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("parameters conversion", () => {
test("properly translate query in route", async () => {
const ajax = new Ajax(mockFetch);
const result = await ajax.rpc({ model: "test", method: "hey" });
expect(result).toBe("/web/dataset/call_kw/test/hey");
});
});
describe("event and status", () => {
test("trigger proper events", async () => {
const ajax = new Ajax(mockFetch);
const events: string[] = [];
ajax.on("rpc_status", null, s => {
events.push(s);
});
expect(events).toEqual([]);
ajax.rpc({ model: "test", method: "hey" });
expect(events).toEqual(["loading"]);
await nextMicroTick();
expect(events).toEqual(["loading", "notloading"]);
});
});