Files
odoo_source/addons/spreadsheet/static/tests/utils/ui.js
T
Lucas Lefèvre 9a06c9550a [IMP] spreadsheet: update o_spreadsheet to latest version
https://github.com/odoo/o-spreadsheet/commit/331a62e8 [REF] menu: simplify menu api
https://github.com/odoo/o-spreadsheet/commit/9c5f0ebc [IMP/REF] bottom_bar: improve style and usability
https://github.com/odoo/o-spreadsheet/commit/a378c53c [IMP] composer: fuzzy search to autocomplete
https://github.com/odoo/o-spreadsheet/commit/35b1263a [FIX] bottom_bar_sheet: fix innerHTML security issue

closes odoo/odoo#110106

Related: odoo/enterprise#35897
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
2023-01-17 20:59:02 +01:00

52 lines
1.5 KiB
JavaScript

/** @odoo-module */
import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
import { registerCleanup } from "@web/../tests/helpers/cleanup";
import { getFixture } from "@web/../tests/helpers/utils";
import { loadJS, templates } from "@web/core/assets";
const { App } = owl;
const { Spreadsheet } = spreadsheet;
/** @typedef {import("@spreadsheet/o_spreadsheet/o_spreadsheet").Model} Model */
/**
* Mount o-spreadsheet component with the given spreadsheet model
* @param {Model} model
* @returns {Promise<HTMLElement>}
*/
export async function mountSpreadsheet(model) {
await loadJS("/web/static/lib/Chart/Chart.js");
const app = new App(Spreadsheet, {
props: { model },
templates: templates,
env: model.config.custom.env,
test: true,
});
registerCleanup(() => app.destroy());
const fixture = getFixture();
await app.mount(fixture);
return fixture;
}
export async function doMenuAction(registry, path, env) {
await getMenuItem(registry, path, env).action(env);
}
function getMenuItem(registry, _path, env) {
const path = [..._path];
let items = registry.getMenuItems();
while (items.length && path.length) {
const id = path.shift();
const item = items.find((item) => item.id === id);
if (!item) {
throw new Error(`Menu item ${id} not found`);
}
if (path.length === 0) {
return item;
}
items = item.children(env);
}
throw new Error(`Menu item not found`);
}