test utils refactoring

This commit is contained in:
Géry Debongnie
2019-03-04 22:47:20 +01:00
parent 8926b8828f
commit a162e40fe0
15 changed files with 494 additions and 394 deletions
+3
View File
@@ -232,6 +232,9 @@ export class QWeb {
const parser = new DOMParser();
const doc = parser.parseFromString(xmlstr, "text/xml");
const templates = doc.getElementsByTagName("templates")[0];
if (!templates) {
return;
}
for (let elem of <any>templates.children) {
const name = elem.getAttribute("t-name");
this._processTemplate(elem);
+14 -4
View File
@@ -1,9 +1,14 @@
//------------------------------------------------------------------------------
// Registry code
//------------------------------------------------------------------------------
/**
* The registry is basically a simple hashmap. It is only a little safer and
* more structured than a simple object.
*/
export class Registry<T> {
private map: { [key: string]: T } = {};
/**
* Add an element to the registry. Note that the add method returns the
* registry, to it can be chained.
*/
add(key: string, item: T): Registry<T> {
if (key in this.map) {
throw new Error(`Key ${key} already exists!`);
@@ -12,7 +17,12 @@ export class Registry<T> {
return this;
}
get(key: string): T {
/**
* Returns the element corresponding to the key
*
* Nothing is done to check that the key actually exists.
*/
get(key: string): T | undefined {
return this.map[key];
}
}
+29 -17
View File
@@ -83,22 +83,24 @@ export function actionManagerMixin<T extends ReturnType<typeof rpcMixin>>(
default:
throw new Error("unhandled action");
}
const action: Action = {
id: this.generateID(),
executor,
activate() {
if (self.currentAction && self.currentAction.widget) {
self.currentAction.widget.destroy();
if (executor) {
const action: Action = {
id: this.generateID(),
executor,
activate() {
if (self.currentAction && self.currentAction.widget) {
self.currentAction.widget.destroy();
}
self.currentAction = action;
self.update({
inHome: false
});
document.title = descr.name + " - Odoo";
}
self.currentAction = action;
self.update({
inHome: false
});
document.title = descr.name + " - Odoo";
}
};
self.lastAction = action;
this.trigger("update_action", action);
};
self.lastAction = action;
this.trigger("update_action", action);
}
}
doActWindowAction(descr: ActWindowActionDescription) {
@@ -111,11 +113,21 @@ export function actionManagerMixin<T extends ReturnType<typeof rpcMixin>>(
};
}
doClientAction(descr: ClientActionDescription) {
doClientAction(
descr: ClientActionDescription
): Action["executor"] | undefined {
let key = descr.tag;
let Widget = this.actionRegistry.get(key);
if (!Widget) {
this.addNotification({
title: "Invalid Client Action",
type: "warning",
message: `Cannot find widget '${key}' in the action registry`
});
return;
}
return async function executor(this: Action, parent: Widget<any, any>) {
const widget = new Widget(parent, {});
const widget = new Widget!(parent, {});
const div = document.createElement("div");
await widget.mount(div);
this.widget = widget;