Skip to content

Commit 4625479

Browse files
author
Eva
committed
fix(workspaces): keep chart helpers private
1 parent cf57f98 commit 4625479

2 files changed

Lines changed: 15 additions & 35 deletions

File tree

ui/src/lib/workspace/widgets/chart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function pointValue(value: unknown): number | undefined {
3535
return toFiniteNumber(value.y) ?? toFiniteNumber(value.value);
3636
}
3737

38-
export function normalizeChartData(value: unknown): ChartDataResult {
38+
function normalizeChartData(value: unknown): ChartDataResult {
3939
const points = Array.isArray(value)
4040
? value
4141
: isRecord(value) && Array.isArray(value.points)
@@ -58,7 +58,7 @@ export function normalizeChartData(value: unknown): ChartDataResult {
5858
return { ok: true, values };
5959
}
6060

61-
export function mapChart(widget: WorkspaceWidget, value: unknown): ChartModel {
61+
function mapChart(widget: WorkspaceWidget, value: unknown): ChartModel {
6262
const props = widgetProps(widget);
6363
const rawType = props.type === undefined ? "line" : props.type;
6464
if (typeof rawType !== "string" || !CHART_TYPES.has(rawType as ChartType)) {

ui/src/lib/workspace/widgets/widgets.test.ts

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { render } from "lit";
77
import { describe, expect, it } from "vitest";
88
import type { WorkspaceWidget } from "../types.ts";
99
import { mapActivity, renderActivity } from "./activity.ts";
10-
import { mapChart, normalizeChartData, renderChart } from "./chart.ts";
10+
import { renderChart } from "./chart.ts";
1111
import { mapCron, renderCron } from "./cron.ts";
1212
import { evaluateEmbedUrl, renderIframeEmbed } from "./iframe-embed.ts";
1313
import { mapInstances, renderInstances } from "./instances.ts";
@@ -238,38 +238,6 @@ describe("activity mapping", () => {
238238
});
239239

240240
describe("chart mapping", () => {
241-
it("accepts finite numeric series and rejects malformed chart data", () => {
242-
expect(normalizeChartData([1, 2, 3])).toEqual({ ok: true, values: [1, 2, 3] });
243-
expect(normalizeChartData({ points: [{ y: 4 }, { value: "5" }] })).toEqual({
244-
ok: true,
245-
values: [4, 5],
246-
});
247-
expect(normalizeChartData([1, "bad", 2])).toMatchObject({ ok: false });
248-
expect(normalizeChartData({ points: [{ label: "missing value" }] })).toMatchObject({
249-
ok: false,
250-
});
251-
expect(normalizeChartData({ points: Array.from({ length: 501 }, () => 1) })).toMatchObject({
252-
ok: false,
253-
});
254-
});
255-
256-
it("validates chart options and derives a bounded model", () => {
257-
expect(mapChart(widget({ props: { type: "bar" } }), [3, 1, 5])).toMatchObject({
258-
status: "ready",
259-
type: "bar",
260-
values: [3, 1, 5],
261-
min: 0,
262-
max: 5,
263-
dataMin: 1,
264-
dataMax: 5,
265-
});
266-
expect(mapChart(widget({ props: { type: "pie" } }), [1])).toMatchObject({ status: "error" });
267-
expect(mapChart(widget({ props: { type: null } }), [1])).toMatchObject({ status: "error" });
268-
expect(mapChart(widget({ props: { min: 10, max: 2 } }), [4])).toMatchObject({
269-
status: "error",
270-
});
271-
});
272-
273241
it("renders single-point and constant series visibly", () => {
274242
const line = renderToContainer(renderChart(widget({ props: { type: "line" } }), [5]));
275243
expect(line.querySelector(".workspace-chart__point")).not.toBeNull();
@@ -331,6 +299,18 @@ describe("chart mapping", () => {
331299
const invalid = renderToContainer(renderChart(widget(), [1, "bad"]));
332300
expect(invalid.querySelector('[data-test-id="workspace-chart-error"]')).not.toBeNull();
333301
expect(invalid.querySelector("svg")).toBeNull();
302+
303+
for (const [configuredWidget, value] of [
304+
[widget({ props: { type: "pie" } }), [1]],
305+
[widget({ props: { type: null } }), [1]],
306+
[widget({ props: { min: 10, max: 2 } }), [4]],
307+
[widget(), { points: [{ label: "missing value" }] }],
308+
[widget(), { points: Array.from({ length: 501 }, () => 1) }],
309+
] as const) {
310+
const error = renderToContainer(renderChart(configuredWidget, value));
311+
expect(error.querySelector('[data-test-id="workspace-chart-error"]')).not.toBeNull();
312+
expect(error.querySelector("svg")).toBeNull();
313+
}
334314
});
335315
});
336316

0 commit comments

Comments
 (0)