Debian Codegraph @

addons/web/static/tests/legacy/views/graph_view_tests.js

raw symbols SCIP
1 /** @odoo-module alias=@web/../tests/views/graph_view_tests default=false */
2
3 import { click, findChildren, triggerEvent } from "@web/../tests/helpers/utils";
4 import { ensureArray } from "@web/core/utils/arrays";
5
6 // TODO: remove when dependant modules are converted
7
8 export function checkLabels(assert, graph, expectedLabels) {
9 const labels = getGraphRenderer(graph).chart.data.labels.map((l) => l.toString());
10 assert.deepEqual(labels, expectedLabels);
11 }
12
13 export function checkLegend(assert, graph, expectedLegendLabels) {
14 expectedLegendLabels = ensureArray(expectedLegendLabels);
15 const { chart } = getGraphRenderer(graph);
16 const actualLegendLabels = chart.config.options.plugins.legend.labels
17 .generateLabels(chart)
18 .map((o) => o.text);
19 assert.deepEqual(actualLegendLabels, expectedLegendLabels);
20 }
21
22 export function clickOnDataset(graph) {
23 const { chart } = getGraphRenderer(graph);
24 const meta = chart.getDatasetMeta(0);
25 const rectangle = chart.canvas.getBoundingClientRect();
26 const point = meta.data[0].getCenterPoint();
27 return triggerEvent(chart.canvas, null, "click", {
28 pageX: rectangle.left + point.x,
29 pageY: rectangle.top + point.y,
30 });
31 }
32
33 export function getGraphRenderer(graph) {
34 for (const { component } of Object.values(findChildren(graph).children)) {
35 if (component.chart) {
36 return component;
37 }
38 }
39 return null;
40 }
41
42 export function selectMode(el, mode) {
43 return click(el, `.o_graph_button[data-mode="${mode}"`);
44 }