Files
odoo_source/addons/spreadsheet/static/tests/utils/ui.js
T
Pierre Pulinckx (pipu) 7e3c1ecdb8 [REF] *: Update Chart.js to V4.3
Change version of Chart.js from V2.9.3 to V4.3.0
You can find changelog on
https://www.chartjs.org/docs/latest/migration/v4-migration.html

Version 4.3.0 of chart.js no longer uses moment.js. This task is a
prerequisite to completely remove the use of moment.js (task 3391739)

Why add aspectRatio : 2 ? => Canvas aspect ratio (i.e. width / height,
a value of 1 representing a square canvas). Note that this option
is ignored if the height is explicitly defined either as attribute
or via the style. The default value varies by chart type; Radial charts
(doughnut, pie, polarArea, radar) default to 1 and others default to 2.

Why no more Chart.animationService.advance(); ?
There is no longer an equivalent in this version.
However, we have verified that the problem is no longer present in this
version.

Why use now getElementsAtEventForMode ?
It's clearly noted in the changelog. follow the link above.

task-3392075

Part-of: odoo/odoo#127259
2023-08-16 12:47:34 +02:00

93 lines
2.9 KiB
JavaScript

/** @odoo-module */
import { Spreadsheet } from "@odoo/o-spreadsheet";
import { registerCleanup } from "@web/../tests/helpers/cleanup";
import { makeTestEnv } from "@web/../tests/helpers/mock_env";
import { getFixture, nextTick } from "@web/../tests/helpers/utils";
import { loadJS, templates } from "@web/core/assets";
import { PublicReadonlySpreadsheet } from "@spreadsheet/public_readonly_app/public_readonly";
import { App } from "@odoo/owl";
import { registry } from "@web/core/registry";
/** @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");
await loadJS("/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.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;
}
/**
* Mount public spreadsheet component with the given data
* @param {Model} model
* @returns {Promise<HTMLElement>}
*/
export async function mountPublicSpreadsheet(data, dataUrl, mode) {
const serviceRegistry = registry.category("services");
const fakeHTTPService = {
start() {
return {
get: (route, params) => {
if (route === dataUrl) {
return data;
}
},
};
},
};
serviceRegistry.add("http", fakeHTTPService);
const env = await makeTestEnv();
const app = new App(PublicReadonlySpreadsheet, {
props: { dataUrl, downloadExcelUrl: "downloadUrl", mode },
templates,
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).execute(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`);
}
export async function keyDown(eventArgs) {
const ev = new KeyboardEvent("keydown", { bubbles: true, cancelable: true, ...eventArgs });
document.activeElement.dispatchEvent(ev);
return await nextTick();
}