Files
owl/web/static/tests/helpers.ts
T

84 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-01-29 10:46:01 +01:00
import { QWeb } from "../src/ts/core/qweb_vdom";
import { idGenerator } from "../src/ts/core/utils";
2019-02-04 21:09:17 +01:00
import { WEnv } from "../src/ts/core/base_widget";
2019-01-29 10:46:01 +01:00
import { Env } from "../src/ts/env";
2019-02-02 16:27:49 +01:00
import { IAjax, RPCQuery } from "../src/ts/core/ajax";
2019-02-02 16:51:24 +01:00
import { Registry } from "../src/ts/core/registry";
2019-02-02 16:27:49 +01:00
import { NotificationManager } from "../src/ts/core/notifications";
2019-01-29 16:13:05 +01:00
2019-01-31 13:19:30 +01:00
import { IActionManager, ActionEvent } from "../src/ts/services/action_manager";
2019-01-29 10:46:01 +01:00
import { Callback } from "../src/ts/core/event_bus";
2019-02-02 16:27:49 +01:00
import { IRouter, Query, RouterEvent } from "../src/ts/core/router";
import { readFile } from "fs";
2019-01-29 10:46:01 +01:00
export function makeTestFixture() {
let fixture = document.createElement("div");
document.body.appendChild(fixture);
return fixture;
}
export function makeTestWEnv(): WEnv {
return {
qweb: new QWeb(),
getID: idGenerator()
};
}
export function makeTestEnv(): Env {
const ajax = new MockAjax();
const actionManager = new MockActionManager();
const router = new MockRouter();
2019-01-29 16:13:05 +01:00
const notifications = new NotificationManager();
2019-01-29 10:46:01 +01:00
let { qweb, getID } = makeTestWEnv();
return {
qweb,
getID,
2019-02-02 16:51:24 +01:00
actionRegistry: new Registry(),
2019-01-29 10:46:01 +01:00
ajax,
actionManager,
2019-01-29 16:13:05 +01:00
notifications,
2019-01-29 10:46:01 +01:00
router,
rpc: ajax.rpc,
debug: false,
2019-02-05 08:56:33 +01:00
isMobile: false
2019-01-29 10:46:01 +01:00
};
}
class MockAjax implements IAjax {
2019-01-29 16:13:05 +01:00
async rpc(rpc: RPCQuery) {
2019-01-29 10:46:01 +01:00
return true;
}
}
class MockActionManager implements IActionManager {
doAction(actionID: number) {}
on(event: ActionEvent, owner: any, callback: Callback) {}
2019-01-31 13:19:30 +01:00
activate() {}
getStack() {
return [];
2019-01-29 10:46:01 +01:00
}
}
class MockRouter implements IRouter {
navigate(query: Query) {}
on(event: RouterEvent, owner: any, callback: Callback) {}
getQuery(): Query {
return {};
}
formatURL(path: string, query: Query): string {
return "";
}
}
export function normalize(str: string): string {
return str.replace(/\s+/g, "");
}
export async function loadTemplates(): Promise<string> {
return new Promise((resolve, reject) => {
readFile("web/static/src/xml/templates.xml", "utf-8", (err, result) => {
resolve(result);
});
});
}