Skip to content

Commit 2bc2d2d

Browse files
committed
test(chart): add smoke tests for chart feature module public API
This commit introduces smoke tests to verify that all exports are correctly re-exported through the feature barrel and that the module handles every registered chart type without throwing or returning a generic placeholder. Full rendering correctness is covered by chart-renderer.test.ts.
1 parent 5a325d8 commit 2bc2d2d

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

  • packages/layout-engine/painters/dom/src/features/chart
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* Smoke tests for the chart feature module public API.
3+
* Verifies that all exports are correctly re-exported through the feature
4+
* barrel and that the module handles every registered chart type without
5+
* throwing or returning a generic placeholder.
6+
*
7+
* Full rendering correctness is covered by chart-renderer.test.ts.
8+
*/
9+
10+
import { describe, it, expect, beforeEach } from 'vitest';
11+
import { JSDOM } from 'jsdom';
12+
import { createChartElement, createChartPlaceholder, formatTickValue } from './index.js';
13+
import type { ChartModel, DrawingGeometry } from '@superdoc/contracts';
14+
15+
let doc: Document;
16+
17+
beforeEach(() => {
18+
doc = new JSDOM('<!DOCTYPE html><html><body></body></html>').window.document;
19+
});
20+
21+
const geometry: DrawingGeometry = { width: 400, height: 300, rotation: 0, flipH: false, flipV: false };
22+
23+
const REGISTERED_CHART_TYPES: ChartModel['chartType'][] = [
24+
'barChart',
25+
'lineChart',
26+
'stockChart',
27+
'areaChart',
28+
'scatterChart',
29+
'bubbleChart',
30+
'radarChart',
31+
'pieChart',
32+
'doughnutChart',
33+
'ofPieChart',
34+
];
35+
36+
function makeChart(chartType: ChartModel['chartType']): ChartModel {
37+
return {
38+
chartType,
39+
series: [
40+
{ name: 'S1', categories: ['A', 'B', 'C'], values: [1, 2, 3], xValues: [1, 2, 3], bubbleSizes: [1, 2, 3] },
41+
],
42+
legendPosition: 'b',
43+
barDirection: 'col',
44+
};
45+
}
46+
47+
describe('chart feature module exports', () => {
48+
it('exports createChartElement as a function', () => {
49+
expect(typeof createChartElement).toBe('function');
50+
});
51+
52+
it('exports createChartPlaceholder as a function', () => {
53+
expect(typeof createChartPlaceholder).toBe('function');
54+
});
55+
56+
it('exports formatTickValue as a function', () => {
57+
expect(typeof formatTickValue).toBe('function');
58+
});
59+
});
60+
61+
describe('createChartElement via feature module', () => {
62+
it('returns a superdoc-chart element', () => {
63+
const el = createChartElement(doc, makeChart('barChart'), geometry);
64+
expect(el.classList.contains('superdoc-chart')).toBe(true);
65+
});
66+
67+
it('shows placeholder when chart data is missing', () => {
68+
const el = createChartElement(doc, undefined, geometry);
69+
expect(el.textContent).toContain('No chart data');
70+
});
71+
72+
it.each(REGISTERED_CHART_TYPES)('renders %s without throwing', (chartType) => {
73+
const el = createChartElement(doc, makeChart(chartType), geometry);
74+
expect(el.classList.contains('superdoc-chart')).toBe(true);
75+
expect(el.textContent).not.toContain(`Chart: ${chartType}`);
76+
});
77+
});
78+
79+
describe('createChartPlaceholder via feature module', () => {
80+
it('renders the label text', () => {
81+
const container = doc.createElement('div');
82+
const el = createChartPlaceholder(doc, container, 'Test label');
83+
expect(el.textContent).toContain('Test label');
84+
});
85+
});
86+
87+
describe('formatTickValue via feature module', () => {
88+
it('formats thousands', () => expect(formatTickValue(1_500)).toBe('1.5K'));
89+
it('formats millions', () => expect(formatTickValue(2_000_000)).toBe('2.0M'));
90+
it('formats plain numbers', () => expect(formatTickValue(42)).toBe('42'));
91+
});

0 commit comments

Comments
 (0)