-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVegaChart.test.tsx
More file actions
66 lines (60 loc) · 1.99 KB
/
VegaChart.test.tsx
File metadata and controls
66 lines (60 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (c) 2019-2026 by Brockmann Consult Development team
* Permissions are hereby granted under the terms of the MIT License:
* https://opensource.org/licenses/MIT.
*/
import { describe, expect, it } from "vitest";
import { render } from "@testing-library/react";
// import { render, screen, fireEvent } from "@testing-library/react";
import type { TopLevelSpec } from "vega-lite";
import { createChangeHandler } from "@/plugins/mui/common.test";
import { VegaChart } from "./VegaChart";
global.ResizeObserver = class {
observe() {}
unobserve() {}
disconnect() {}
};
describe("VegaChart", () => {
it("should render if chart is not given", () => {
render(
<VegaChart id="vc" type={"VegaChart"} chart={null} onChange={() => {}} />,
);
// to inspect rendered component, do:
// expect(document.body).toEqual({});
expect(document.querySelector("#vc")).not.toBeUndefined();
});
it("should render if chart is given", () => {
const { recordedEvents, onChange } = createChangeHandler();
render(
<VegaChart
id="vc"
type={"VegaChart"}
chart={chart}
onChange={onChange}
/>,
);
// to inspect rendered component, do:
// expect(document.body).toEqual({});
expect(recordedEvents.length).toBe(0);
// TODO: all of the following doesn't work!
// expect(document.querySelector("canvas")).toEqual({});
// expect(screen.getByRole("canvas")).not.toBeUndefined();
// fireEvent.click(screen.getByRole("canvas"));
// expect(recordedEvents.length).toBe(1);
});
});
const chart: TopLevelSpec = {
$schema: "https://vega.github.io/schema/vega-lite/v6.json",
config: { view: { continuousWidth: 300, continuousHeight: 300 } },
data: { name: "data-0" },
mark: { type: "bar" },
datasets: {
"data-0": [
{ x: "A", a: 28, b: 50, c: 50 },
{ x: "B", a: 55, b: 32, c: 40 },
{ x: "C", a: 43, b: 56, c: 30 },
{ x: "D", a: 91, b: 44, c: 20 },
{ x: "E", a: 81, b: 8, c: 10 },
],
},
};