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:
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user