Skip to content

Commit 64bb8b4

Browse files
test(custom-chart-web): add unit tests for parseData, parseLayout, and parseConfig functions
1 parent f3faf7c commit 64bb8b4

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

packages/pluggableWidgets/custom-chart-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"publish-marketplace": "rui-publish-marketplace",
4040
"release": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pluggable-widgets-tools release:web",
4141
"start": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pluggable-widgets-tools start:server",
42-
"test": "echo 'FIXME: Finish custom-chart-web unit test migration'",
42+
"test": "pluggable-widgets-tools test:unit:web:enzyme-free",
4343
"update-changelog": "rui-update-changelog-widget",
4444
"verify": "rui-verify-package-format"
4545
},
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { parseData, parseLayout, parseConfig } from "../utils/utils";
2+
3+
describe("parseData", () => {
4+
it("returns empty array when all inputs are empty", () => {
5+
expect(parseData()).toEqual([]);
6+
});
7+
8+
it("parses staticData only", () => {
9+
const staticData = JSON.stringify([{ x: [1], y: [2] }]);
10+
expect(parseData(staticData)).toEqual([{ x: [1], y: [2] }]);
11+
});
12+
13+
it("parses sampleData when attributeData and staticData are empty", () => {
14+
const sampleData = JSON.stringify([{ x: [3], y: [4] }]);
15+
expect(parseData(undefined, undefined, sampleData)).toEqual([{ x: [3], y: [4] }]);
16+
});
17+
18+
it("parses attributeData and ignores sampleData if attributeData is present", () => {
19+
const attributeData = JSON.stringify([{ x: [5], y: [6] }]);
20+
const sampleData = JSON.stringify([{ x: [7], y: [8] }]);
21+
expect(parseData(undefined, attributeData, sampleData)).toEqual([{ x: [5], y: [6] }]);
22+
});
23+
});
24+
25+
describe("parseLayout", () => {
26+
it("returns empty object when all inputs are empty", () => {
27+
expect(parseLayout()).toEqual({});
28+
});
29+
30+
it("parses staticLayout only", () => {
31+
const staticLayout = JSON.stringify({ title: "Test" });
32+
expect(parseLayout(staticLayout)).toEqual({ title: "Test" });
33+
});
34+
35+
it("parses sampleLayout when attributeLayout and staticLayout are empty", () => {
36+
const sampleLayout = JSON.stringify({ title: "Sample" });
37+
expect(parseLayout(undefined, undefined, sampleLayout)).toEqual({ title: "Sample" });
38+
});
39+
40+
it("parses attributeLayout and ignores sampleLayout if attributeLayout is present", () => {
41+
const attributeLayout = JSON.stringify({ title: "Attr" });
42+
const sampleLayout = JSON.stringify({ title: "Sample" });
43+
expect(parseLayout(undefined, attributeLayout, sampleLayout)).toEqual({ title: "Attr" });
44+
});
45+
});
46+
47+
describe("parseConfig", () => {
48+
it("returns empty object when configOptions is empty", () => {
49+
expect(parseConfig()).toEqual({});
50+
});
51+
52+
it("parses configOptions", () => {
53+
const configOptions = JSON.stringify({ responsive: true });
54+
expect(parseConfig(configOptions)).toEqual({ responsive: true });
55+
});
56+
});

0 commit comments

Comments
 (0)