Odoo18-Base/addons/web/static/lib/hoot/tests/local_helpers.js
KaySar12 8a9c49514f
Some checks are pending
Setup Native Action / native (3.12.7) (push) Waiting to run
Setup Native Action / docker (3.12.7) (push) Waiting to run
update base web lib
2025-05-23 14:51:51 +07:00

52 lines
1.4 KiB
JavaScript

/** @odoo-module */
import { after, destroy, getFixture } from "@odoo/hoot";
import { queryAll } from "@odoo/hoot-dom";
import { App, Component, xml } from "@odoo/owl";
//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------
/**
* @param {import("@odoo/owl").ComponentConstructor} ComponentClass
* @param {ConstructorParameters<typeof App>[1]} [config]
*/
export async function mountForTest(ComponentClass, config) {
if (typeof ComponentClass === "string") {
ComponentClass = class extends Component {
static name = "anonymous component";
static props = {};
static template = xml`${ComponentClass}`;
};
}
const app = new App(ComponentClass, {
name: "TEST",
test: true,
warnIfNoStaticProps: true,
...config,
});
const fixture = getFixture();
after(() => destroy(app));
fixture.style.backgroundColor = "#fff";
return app.mount(fixture);
}
/**
* @param {string} url
*/
export function parseUrl(url) {
return url.replace(/^.*hoot\/tests/, "@hoot").replace(/(\.test)?\.js$/, "");
}
export function waitForIframes() {
return Promise.all(
queryAll("iframe").map(
(iframe) => new Promise((resolve) => iframe.addEventListener("load", resolve))
)
);
}