@opendata-ai/openchart-vanilla 8.0.0-rc.2 → 8.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-W34KN7FD.js → chunk-2NAQRP66.js} +2 -2
- package/dist/chunk-DCODCLWI.js +234 -0
- package/dist/chunk-DCODCLWI.js.map +1 -0
- package/dist/{chunk-5EOV5JQZ.js → chunk-EKAUQAAX.js} +50 -46
- package/dist/chunk-EKAUQAAX.js.map +1 -0
- package/dist/{chunk-ENXSUXC5.js → chunk-KNT5AZ2O.js} +7309 -5490
- package/dist/chunk-KNT5AZ2O.js.map +1 -0
- package/dist/chunk-RM5XS6NR.js +113 -0
- package/dist/chunk-RM5XS6NR.js.map +1 -0
- package/dist/chunk-T32UHMZA.js +282 -0
- package/dist/chunk-T32UHMZA.js.map +1 -0
- package/dist/export-gif.d.ts +113 -0
- package/dist/export-gif.js +21 -0
- package/dist/export-gif.js.map +1 -0
- package/dist/index.d.ts +283 -24
- package/dist/index.js +2012 -763
- package/dist/index.js.map +1 -1
- package/dist/{mount-CUKQLeqD.d.ts → mount-Dvv8NYIv.d.ts} +117 -3
- package/dist/simulation-worker.js +83 -2
- package/dist/static.js +7 -69
- package/dist/static.js.map +1 -1
- package/dist/story/index.d.ts +3 -2
- package/dist/story/index.js +5 -3
- package/dist/story/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +14 -6
- package/dist/chunk-5EOV5JQZ.js.map +0 -1
- package/dist/chunk-ENXSUXC5.js.map +0 -1
- package/src/__test-fixtures__/dom.ts +0 -70
- package/src/__test-fixtures__/specs.ts +0 -214
- package/src/__tests__/animation.test.ts +0 -358
- package/src/__tests__/annotations-render.test.ts +0 -201
- package/src/__tests__/compound-labels.test.ts +0 -122
- package/src/__tests__/continuous-legend.test.ts +0 -91
- package/src/__tests__/crosshair.test.ts +0 -130
- package/src/__tests__/edit-events.test.ts +0 -902
- package/src/__tests__/events.test.ts +0 -387
- package/src/__tests__/export.test.ts +0 -241
- package/src/__tests__/font-race.test.ts +0 -199
- package/src/__tests__/gradient-ids.test.ts +0 -159
- package/src/__tests__/gradient-utils.test.ts +0 -125
- package/src/__tests__/known-bugs-render.test.ts +0 -183
- package/src/__tests__/map.test.ts +0 -293
- package/src/__tests__/mount.test.ts +0 -357
- package/src/__tests__/pattern-fills.test.ts +0 -105
- package/src/__tests__/resize-timing.test.ts +0 -218
- package/src/__tests__/sankey.test.ts +0 -133
- package/src/__tests__/selection-events.test.ts +0 -869
- package/src/__tests__/series-search.test.ts +0 -311
- package/src/__tests__/static.test.ts +0 -141
- package/src/__tests__/svg-renderer.test.ts +0 -895
- package/src/__tests__/table-keyboard.test.ts +0 -361
- package/src/__tests__/table-mount.test.ts +0 -639
- package/src/__tests__/tilemap.test.ts +0 -158
- package/src/__tests__/tooltip.test.ts +0 -337
- package/src/__tests__/transition.test.ts +0 -1777
- package/src/__tests__/you-draw-it.test.ts +0 -273
- package/src/animation-vars.ts +0 -42
- package/src/animation.ts +0 -76
- package/src/barlist-mount.ts +0 -383
- package/src/barlist-renderer.ts +0 -267
- package/src/dom-helpers.ts +0 -17
- package/src/export.ts +0 -482
- package/src/gradient-utils.ts +0 -138
- package/src/graph/__tests__/canvas-renderer.test.ts +0 -713
- package/src/graph/__tests__/graph-mount.test.ts +0 -213
- package/src/graph/__tests__/interaction.test.ts +0 -205
- package/src/graph/__tests__/keyboard.test.ts +0 -653
- package/src/graph/__tests__/search.test.ts +0 -88
- package/src/graph/__tests__/simulation.test.ts +0 -233
- package/src/graph/__tests__/spatial-index.test.ts +0 -142
- package/src/graph/__tests__/zoom.test.ts +0 -203
- package/src/graph/canvas-renderer.ts +0 -747
- package/src/graph/interaction.ts +0 -367
- package/src/graph/keyboard.ts +0 -208
- package/src/graph/search.ts +0 -50
- package/src/graph/simulation-worker-url.ts +0 -12
- package/src/graph/simulation-worker.ts +0 -278
- package/src/graph/simulation.ts +0 -422
- package/src/graph/spatial-index.ts +0 -121
- package/src/graph/types.ts +0 -47
- package/src/graph/worker-protocol.ts +0 -70
- package/src/graph/zoom.ts +0 -134
- package/src/graph-mount.ts +0 -888
- package/src/index.ts +0 -76
- package/src/interactions/chart-events.ts +0 -139
- package/src/interactions/crosshair.ts +0 -233
- package/src/interactions/drag-handler.ts +0 -175
- package/src/interactions/editing-drags.ts +0 -515
- package/src/interactions/index.ts +0 -25
- package/src/interactions/keyboard-nav.ts +0 -111
- package/src/interactions/legend-interaction.ts +0 -46
- package/src/interactions/selection.ts +0 -280
- package/src/interactions/tooltip-events.ts +0 -72
- package/src/map-camera.ts +0 -88
- package/src/map-mount.ts +0 -701
- package/src/map-renderer.ts +0 -338
- package/src/map-transition.ts +0 -83
- package/src/measure-text.ts +0 -134
- package/src/mount.ts +0 -1382
- package/src/pattern-utils.ts +0 -110
- package/src/renderers/annotations.ts +0 -388
- package/src/renderers/axes.ts +0 -351
- package/src/renderers/brand.ts +0 -87
- package/src/renderers/chrome.ts +0 -196
- package/src/renderers/endpoint-labels.ts +0 -150
- package/src/renderers/legend.ts +0 -311
- package/src/renderers/marks.ts +0 -561
- package/src/renderers/metrics.ts +0 -63
- package/src/renderers/svg-dom.ts +0 -40
- package/src/renderers/table-cells.ts +0 -446
- package/src/resize-observer.ts +0 -46
- package/src/sankey-mount.ts +0 -622
- package/src/sankey-renderer.ts +0 -614
- package/src/series-search.ts +0 -392
- package/src/static.ts +0 -251
- package/src/story/__tests__/camera-math.test.ts +0 -145
- package/src/story/__tests__/create-chart-story.test.ts +0 -317
- package/src/story/__tests__/progress-math.test.ts +0 -95
- package/src/story/__tests__/scroll-driver.test.ts +0 -130
- package/src/story/__tests__/tween.test.ts +0 -159
- package/src/story/camera-math.ts +0 -125
- package/src/story/create-chart-story.ts +0 -353
- package/src/story/crossfade.ts +0 -70
- package/src/story/index.ts +0 -39
- package/src/story/progress-math.ts +0 -85
- package/src/story/resolve-camera-target.ts +0 -119
- package/src/story/scroll-driver.ts +0 -206
- package/src/story/story-camera.ts +0 -49
- package/src/story/tween.ts +0 -112
- package/src/story/types.ts +0 -76
- package/src/svg-ids.ts +0 -23
- package/src/svg-renderer.ts +0 -383
- package/src/table-keyboard.ts +0 -266
- package/src/table-mount.ts +0 -567
- package/src/table-renderer.ts +0 -414
- package/src/text-edit-overlay.ts +0 -255
- package/src/theme-tokens.ts +0 -51
- package/src/tilemap-mount.ts +0 -511
- package/src/tilemap-renderer.ts +0 -396
- package/src/tooltip.ts +0 -177
- package/src/transition.ts +0 -2816
- package/src/you-draw-it.ts +0 -480
- /package/dist/{chunk-W34KN7FD.js.map → chunk-2NAQRP66.js.map} +0 -0
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Series search (`seriesSearch`) interaction tests.
|
|
3
|
-
*
|
|
4
|
-
* Mounts real charts via createChart into a happy-dom container and drives
|
|
5
|
-
* the combobox with real keyboard/input events, asserting on visible
|
|
6
|
-
* behavior: ARIA state, chips, and the stroke colors the renderer applies
|
|
7
|
-
* to line marks when the highlight set changes.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { ChartSpec } from '@opendata-ai/openchart-core';
|
|
11
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
12
|
-
import { createContainer } from '../__test-fixtures__/dom';
|
|
13
|
-
import { type ChartInstance, createChart } from '../mount';
|
|
14
|
-
|
|
15
|
-
/** Neutral gray the engine assigns to non-highlighted series. */
|
|
16
|
-
const MUTED = '#bfc3c8';
|
|
17
|
-
|
|
18
|
-
const COUNTRIES = ['United States', 'Germany', 'France', 'Georgia', 'México'];
|
|
19
|
-
|
|
20
|
-
function makeSearchSpec(overrides: Partial<ChartSpec> = {}): ChartSpec {
|
|
21
|
-
const data = COUNTRIES.flatMap((country, i) => [
|
|
22
|
-
{ year: '2020-01-01', value: 10 + i * 5, country },
|
|
23
|
-
{ year: '2021-01-01', value: 14 + i * 5, country },
|
|
24
|
-
]);
|
|
25
|
-
return {
|
|
26
|
-
mark: 'line',
|
|
27
|
-
data,
|
|
28
|
-
encoding: {
|
|
29
|
-
x: { field: 'year', type: 'temporal' },
|
|
30
|
-
y: { field: 'value', type: 'quantitative' },
|
|
31
|
-
color: { field: 'country', type: 'nominal' },
|
|
32
|
-
},
|
|
33
|
-
seriesSearch: true,
|
|
34
|
-
...overrides,
|
|
35
|
-
} as ChartSpec;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getInput(container: HTMLElement): HTMLInputElement {
|
|
39
|
-
const input = container.querySelector('.oc-series-search-input');
|
|
40
|
-
expect(input).not.toBeNull();
|
|
41
|
-
return input as HTMLInputElement;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getListbox(container: HTMLElement): HTMLUListElement {
|
|
45
|
-
return container.querySelector('.oc-series-search-listbox') as HTMLUListElement;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function optionLabels(container: HTMLElement): string[] {
|
|
49
|
-
return [...container.querySelectorAll('.oc-series-search-option')].map(
|
|
50
|
-
(el) => el.textContent ?? '',
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function chipLabels(container: HTMLElement): string[] {
|
|
55
|
-
return [...container.querySelectorAll('.oc-series-search-chip')].map((el) =>
|
|
56
|
-
(el.textContent ?? '').trim(),
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function typeText(input: HTMLInputElement, text: string): void {
|
|
61
|
-
input.value = text;
|
|
62
|
-
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function press(el: Element, key: string): void {
|
|
66
|
-
el.dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true }));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Stroke color the renderer applied to a series' line mark. */
|
|
70
|
-
function seriesStroke(container: HTMLElement, series: string): string | null {
|
|
71
|
-
const g = container.querySelector(`g.oc-mark-line[data-series="${series}"]`);
|
|
72
|
-
return g?.querySelector('path')?.getAttribute('stroke') ?? null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function removeChip(container: HTMLElement, series: string): void {
|
|
76
|
-
const button = container.querySelector(
|
|
77
|
-
`.oc-series-search-chip-remove[aria-label="Remove ${series}"]`,
|
|
78
|
-
) as HTMLButtonElement | null;
|
|
79
|
-
expect(button).not.toBeNull();
|
|
80
|
-
button!.click();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
describe('series search', () => {
|
|
84
|
-
let container: HTMLDivElement;
|
|
85
|
-
let chart: ChartInstance | null = null;
|
|
86
|
-
|
|
87
|
-
beforeEach(() => {
|
|
88
|
-
container = createContainer();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
afterEach(() => {
|
|
92
|
-
chart?.destroy();
|
|
93
|
-
chart = null;
|
|
94
|
-
document.body.innerHTML = '';
|
|
95
|
-
vi.restoreAllMocks();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('renders an ARIA combobox with the configured placeholder', () => {
|
|
99
|
-
chart = createChart(
|
|
100
|
-
container,
|
|
101
|
-
makeSearchSpec({ seriesSearch: { placeholder: 'Find a country' } }),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const input = getInput(container);
|
|
105
|
-
expect(input.getAttribute('role')).toBe('combobox');
|
|
106
|
-
expect(input.placeholder).toBe('Find a country');
|
|
107
|
-
expect(input.getAttribute('aria-expanded')).toBe('false');
|
|
108
|
-
expect(input.getAttribute('aria-autocomplete')).toBe('list');
|
|
109
|
-
|
|
110
|
-
const listbox = getListbox(container);
|
|
111
|
-
expect(listbox.getAttribute('role')).toBe('listbox');
|
|
112
|
-
expect(listbox.hidden).toBe(true);
|
|
113
|
-
expect(input.getAttribute('aria-controls')).toBe(listbox.id);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('supports the full keyboard path: arrows open and navigate, Enter selects, Escape closes', () => {
|
|
117
|
-
chart = createChart(container, makeSearchSpec());
|
|
118
|
-
const input = getInput(container);
|
|
119
|
-
input.focus();
|
|
120
|
-
|
|
121
|
-
// ArrowDown opens the list with every series suggested
|
|
122
|
-
press(input, 'ArrowDown');
|
|
123
|
-
expect(input.getAttribute('aria-expanded')).toBe('true');
|
|
124
|
-
expect(getListbox(container).hidden).toBe(false);
|
|
125
|
-
expect(optionLabels(container)).toEqual(COUNTRIES);
|
|
126
|
-
expect(input.getAttribute('aria-activedescendant')).toBeTruthy();
|
|
127
|
-
|
|
128
|
-
// Arrows move the active option (aria-activedescendant tracks it)
|
|
129
|
-
const first = input.getAttribute('aria-activedescendant');
|
|
130
|
-
press(input, 'ArrowDown');
|
|
131
|
-
const second = input.getAttribute('aria-activedescendant');
|
|
132
|
-
expect(second).not.toBe(first);
|
|
133
|
-
press(input, 'ArrowUp');
|
|
134
|
-
expect(input.getAttribute('aria-activedescendant')).toBe(first);
|
|
135
|
-
|
|
136
|
-
// Enter selects the active option as a chip and closes the list
|
|
137
|
-
press(input, 'Enter');
|
|
138
|
-
expect(chipLabels(container)).toEqual(['United States']);
|
|
139
|
-
expect(input.getAttribute('aria-expanded')).toBe('false');
|
|
140
|
-
|
|
141
|
-
// Escape closes a re-opened list
|
|
142
|
-
press(input, 'ArrowDown');
|
|
143
|
-
expect(input.getAttribute('aria-expanded')).toBe('true');
|
|
144
|
-
press(input, 'Escape');
|
|
145
|
-
expect(input.getAttribute('aria-expanded')).toBe('false');
|
|
146
|
-
expect(getListbox(container).hidden).toBe(true);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('typing "ger" then Enter saturates Germany; adding France gives two; removing chips restores', () => {
|
|
150
|
-
chart = createChart(container, makeSearchSpec());
|
|
151
|
-
const input = getInput(container);
|
|
152
|
-
|
|
153
|
-
// Capture the palette colors before any search interaction
|
|
154
|
-
const initialStrokes = new Map(COUNTRIES.map((c) => [c, seriesStroke(container, c)]));
|
|
155
|
-
for (const c of COUNTRIES) expect(initialStrokes.get(c)).not.toBe(MUTED);
|
|
156
|
-
|
|
157
|
-
// "ger" matches Germany only (Georgia shares "ge" but not "ger")
|
|
158
|
-
typeText(input, 'ger');
|
|
159
|
-
expect(optionLabels(container)).toEqual(['Germany']);
|
|
160
|
-
press(input, 'Enter');
|
|
161
|
-
|
|
162
|
-
expect(chipLabels(container)).toEqual(['Germany']);
|
|
163
|
-
expect(seriesStroke(container, 'Germany')).not.toBe(MUTED);
|
|
164
|
-
for (const c of COUNTRIES.filter((c) => c !== 'Germany')) {
|
|
165
|
-
expect(seriesStroke(container, c)).toBe(MUTED);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Add France: two saturated series
|
|
169
|
-
typeText(input, 'fra');
|
|
170
|
-
expect(optionLabels(container)).toEqual(['France']);
|
|
171
|
-
press(input, 'Enter');
|
|
172
|
-
expect(chipLabels(container)).toEqual(['Germany', 'France']);
|
|
173
|
-
expect(seriesStroke(container, 'Germany')).not.toBe(MUTED);
|
|
174
|
-
expect(seriesStroke(container, 'France')).not.toBe(MUTED);
|
|
175
|
-
expect(seriesStroke(container, 'United States')).toBe(MUTED);
|
|
176
|
-
|
|
177
|
-
// Removing both chips restores the original palette assignment
|
|
178
|
-
removeChip(container, 'France');
|
|
179
|
-
removeChip(container, 'Germany');
|
|
180
|
-
expect(chipLabels(container)).toEqual([]);
|
|
181
|
-
for (const c of COUNTRIES) {
|
|
182
|
-
expect(seriesStroke(container, c)).toBe(initialStrokes.get(c));
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('clearing the search restores the authored highlight baseline exactly', () => {
|
|
187
|
-
chart = createChart(
|
|
188
|
-
container,
|
|
189
|
-
makeSearchSpec({
|
|
190
|
-
encoding: {
|
|
191
|
-
x: { field: 'year', type: 'temporal' },
|
|
192
|
-
y: { field: 'value', type: 'quantitative' },
|
|
193
|
-
color: { field: 'country', type: 'nominal', highlight: ['United States'] },
|
|
194
|
-
},
|
|
195
|
-
} as Partial<ChartSpec>),
|
|
196
|
-
);
|
|
197
|
-
const input = getInput(container);
|
|
198
|
-
|
|
199
|
-
// Authored baseline: US saturated, everything else muted
|
|
200
|
-
const baselineStrokes = new Map(COUNTRIES.map((c) => [c, seriesStroke(container, c)]));
|
|
201
|
-
expect(baselineStrokes.get('United States')).not.toBe(MUTED);
|
|
202
|
-
expect(baselineStrokes.get('Germany')).toBe(MUTED);
|
|
203
|
-
|
|
204
|
-
// Selecting Germany adds to the baseline set (US stays saturated)
|
|
205
|
-
typeText(input, 'ger');
|
|
206
|
-
press(input, 'Enter');
|
|
207
|
-
expect(seriesStroke(container, 'Germany')).not.toBe(MUTED);
|
|
208
|
-
expect(seriesStroke(container, 'United States')).not.toBe(MUTED);
|
|
209
|
-
|
|
210
|
-
// Clearing restores the authored baseline for every series
|
|
211
|
-
removeChip(container, 'Germany');
|
|
212
|
-
for (const c of COUNTRIES) {
|
|
213
|
-
expect(seriesStroke(container, c)).toBe(baselineStrokes.get(c));
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('fires onHighlightChange with the full current set on every change', () => {
|
|
218
|
-
const onHighlightChange = vi.fn();
|
|
219
|
-
chart = createChart(
|
|
220
|
-
container,
|
|
221
|
-
makeSearchSpec({
|
|
222
|
-
encoding: {
|
|
223
|
-
x: { field: 'year', type: 'temporal' },
|
|
224
|
-
y: { field: 'value', type: 'quantitative' },
|
|
225
|
-
color: { field: 'country', type: 'nominal', highlight: ['United States'] },
|
|
226
|
-
},
|
|
227
|
-
} as Partial<ChartSpec>),
|
|
228
|
-
{ onHighlightChange },
|
|
229
|
-
);
|
|
230
|
-
const input = getInput(container);
|
|
231
|
-
|
|
232
|
-
typeText(input, 'ger');
|
|
233
|
-
press(input, 'Enter');
|
|
234
|
-
expect(onHighlightChange).toHaveBeenLastCalledWith(['United States', 'Germany']);
|
|
235
|
-
|
|
236
|
-
typeText(input, 'fra');
|
|
237
|
-
press(input, 'Enter');
|
|
238
|
-
expect(onHighlightChange).toHaveBeenLastCalledWith(['United States', 'Germany', 'France']);
|
|
239
|
-
|
|
240
|
-
removeChip(container, 'Germany');
|
|
241
|
-
expect(onHighlightChange).toHaveBeenLastCalledWith(['United States', 'France']);
|
|
242
|
-
|
|
243
|
-
removeChip(container, 'France');
|
|
244
|
-
expect(onHighlightChange).toHaveBeenLastCalledWith(['United States']);
|
|
245
|
-
expect(onHighlightChange).toHaveBeenCalledTimes(4);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('matches diacritic-insensitively', () => {
|
|
249
|
-
chart = createChart(container, makeSearchSpec());
|
|
250
|
-
const input = getInput(container);
|
|
251
|
-
|
|
252
|
-
typeText(input, 'mex');
|
|
253
|
-
expect(optionLabels(container)).toEqual(['México']);
|
|
254
|
-
|
|
255
|
-
typeText(input, 'MÉX');
|
|
256
|
-
expect(optionLabels(container)).toEqual(['México']);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('Backspace on an empty input removes the last chip', () => {
|
|
260
|
-
chart = createChart(container, makeSearchSpec());
|
|
261
|
-
const input = getInput(container);
|
|
262
|
-
|
|
263
|
-
typeText(input, 'ger');
|
|
264
|
-
press(input, 'Enter');
|
|
265
|
-
typeText(input, 'fra');
|
|
266
|
-
press(input, 'Enter');
|
|
267
|
-
expect(chipLabels(container)).toEqual(['Germany', 'France']);
|
|
268
|
-
|
|
269
|
-
press(input, 'Backspace');
|
|
270
|
-
expect(chipLabels(container)).toEqual(['Germany']);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('suppresses edit mode with a warning when both are enabled (search wins)', () => {
|
|
274
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
275
|
-
chart = createChart(container, makeSearchSpec(), {
|
|
276
|
-
onEdit: () => {},
|
|
277
|
-
onSelect: () => {},
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
expect(warn).toHaveBeenCalledWith(expect.stringContaining('mutually exclusive'));
|
|
281
|
-
|
|
282
|
-
// Search input mounted; edit affordances (focusable SVG) are not wired
|
|
283
|
-
expect(container.querySelector('.oc-series-search-input')).not.toBeNull();
|
|
284
|
-
const svg = container.querySelector('svg');
|
|
285
|
-
expect(svg?.getAttribute('tabindex')).toBeNull();
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('update() resets search selections to the new spec baseline', () => {
|
|
289
|
-
chart = createChart(container, makeSearchSpec());
|
|
290
|
-
const input = getInput(container);
|
|
291
|
-
|
|
292
|
-
typeText(input, 'ger');
|
|
293
|
-
press(input, 'Enter');
|
|
294
|
-
expect(chipLabels(container)).toEqual(['Germany']);
|
|
295
|
-
|
|
296
|
-
chart.update(makeSearchSpec());
|
|
297
|
-
expect(chipLabels(container)).toEqual([]);
|
|
298
|
-
for (const c of COUNTRIES) {
|
|
299
|
-
expect(seriesStroke(container, c)).not.toBe(MUTED);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it('destroy() removes the search control from the DOM', () => {
|
|
304
|
-
chart = createChart(container, makeSearchSpec());
|
|
305
|
-
expect(container.querySelector('.oc-series-search')).not.toBeNull();
|
|
306
|
-
|
|
307
|
-
chart.destroy();
|
|
308
|
-
chart = null;
|
|
309
|
-
expect(container.querySelector('.oc-series-search')).toBeNull();
|
|
310
|
-
});
|
|
311
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { LayerSpec } from '@opendata-ai/openchart-core';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { barSpec, lineSpec, pieSpec } from '../__test-fixtures__/specs';
|
|
4
|
-
import { renderStaticSVG } from '../static';
|
|
5
|
-
|
|
6
|
-
describe('renderStaticSVG', () => {
|
|
7
|
-
it('returns a valid SVG string', () => {
|
|
8
|
-
const svg = renderStaticSVG(lineSpec);
|
|
9
|
-
expect(svg).toContain('<svg');
|
|
10
|
-
expect(svg).toContain('</svg>');
|
|
11
|
-
expect(svg).toContain('viewBox');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('produces byte-identical output for the same spec', () => {
|
|
15
|
-
const first = renderStaticSVG(lineSpec, { width: 640, height: 420 });
|
|
16
|
-
const second = renderStaticSVG(lineSpec, { width: 640, height: 420 });
|
|
17
|
-
expect(first).toBe(second);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('includes a11y attributes', () => {
|
|
21
|
-
const svg = renderStaticSVG(lineSpec);
|
|
22
|
-
expect(svg).toContain('role=');
|
|
23
|
-
expect(svg).toContain('aria-label=');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('does not contain interactive elements', () => {
|
|
27
|
-
const svg = renderStaticSVG(lineSpec);
|
|
28
|
-
expect(svg).not.toContain('data-voronoi-overlay');
|
|
29
|
-
expect(svg).not.toContain('data-crosshair');
|
|
30
|
-
expect(svg).not.toContain('data-snap-dots');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('does not contain animation classes', () => {
|
|
34
|
-
const svg = renderStaticSVG(lineSpec);
|
|
35
|
-
expect(svg).not.toContain('oc-animate');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('includes the inlined style block with theme values', () => {
|
|
39
|
-
const svg = renderStaticSVG(lineSpec);
|
|
40
|
-
expect(svg).toContain('<style');
|
|
41
|
-
expect(svg).toContain('.oc-brand-dot');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('scopes custom properties to svg.oc-chart, not :root', () => {
|
|
45
|
-
const svg = renderStaticSVG(lineSpec);
|
|
46
|
-
expect(svg).toContain('svg.oc-chart');
|
|
47
|
-
expect(svg).not.toContain(':root');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('uses var() references in class rules for theme overridability', () => {
|
|
51
|
-
const svg = renderStaticSVG(lineSpec);
|
|
52
|
-
expect(svg).toContain('fill: var(--oc-accent)');
|
|
53
|
-
expect(svg).toContain('fill: var(--oc-text)');
|
|
54
|
-
expect(svg).toContain('fill: var(--oc-text-muted)');
|
|
55
|
-
expect(svg).toContain('font-family: var(--oc-font-family)');
|
|
56
|
-
expect(svg).not.toMatch(/\.oc-brand-dot \{ fill: #[0-9a-f]{6}/i);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders bar charts', () => {
|
|
60
|
-
const svg = renderStaticSVG(barSpec);
|
|
61
|
-
expect(svg).toContain('oc-mark-rect');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('renders pie charts', () => {
|
|
65
|
-
const svg = renderStaticSVG(pieSpec);
|
|
66
|
-
expect(svg).toContain('oc-mark-arc');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('renders layer specs', () => {
|
|
70
|
-
const layerSpec: LayerSpec = {
|
|
71
|
-
layer: [
|
|
72
|
-
{
|
|
73
|
-
mark: 'line',
|
|
74
|
-
data: [
|
|
75
|
-
{ x: '2020', y: 10 },
|
|
76
|
-
{ x: '2021', y: 20 },
|
|
77
|
-
],
|
|
78
|
-
encoding: {
|
|
79
|
-
x: { field: 'x', type: 'temporal' },
|
|
80
|
-
y: { field: 'y', type: 'quantitative' },
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
mark: 'point',
|
|
85
|
-
data: [
|
|
86
|
-
{ x: '2020', y: 10 },
|
|
87
|
-
{ x: '2021', y: 20 },
|
|
88
|
-
],
|
|
89
|
-
encoding: {
|
|
90
|
-
x: { field: 'x', type: 'temporal' },
|
|
91
|
-
y: { field: 'y', type: 'quantitative' },
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
};
|
|
96
|
-
const svg = renderStaticSVG(layerSpec);
|
|
97
|
-
expect(svg).toContain('<svg');
|
|
98
|
-
expect(svg).toContain('oc-mark-line');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('respects explicit width and height', () => {
|
|
102
|
-
const svg = renderStaticSVG(lineSpec, { width: 800, height: 500 });
|
|
103
|
-
expect(svg).toContain('viewBox="0 0 800 500"');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('renders dark mode when darkMode is "force"', () => {
|
|
107
|
-
const light = renderStaticSVG(lineSpec, { darkMode: 'off' });
|
|
108
|
-
const dark = renderStaticSVG(lineSpec, { darkMode: 'force' });
|
|
109
|
-
expect(light).not.toBe(dark);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('renders chrome elements', () => {
|
|
113
|
-
const svg = renderStaticSVG(lineSpec);
|
|
114
|
-
expect(svg).toContain('GDP Growth');
|
|
115
|
-
expect(svg).toContain('US vs UK over time');
|
|
116
|
-
expect(svg).toContain('World Bank');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('produces deterministic IDs across calls', () => {
|
|
120
|
-
const first = renderStaticSVG(lineSpec, { width: 640, height: 420 });
|
|
121
|
-
const second = renderStaticSVG(lineSpec, { width: 640, height: 420 });
|
|
122
|
-
const idPattern = /id="oc-[a-z]+-\d+"/g;
|
|
123
|
-
const firstIds = first.match(idPattern) ?? [];
|
|
124
|
-
const secondIds = second.match(idPattern) ?? [];
|
|
125
|
-
expect(firstIds).toEqual(secondIds);
|
|
126
|
-
expect(firstIds.length).toBeGreaterThan(0);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('does not pollute global document or window after rendering', () => {
|
|
130
|
-
const docBefore = globalThis.document;
|
|
131
|
-
const winBefore = globalThis.window;
|
|
132
|
-
renderStaticSVG(lineSpec);
|
|
133
|
-
expect(globalThis.document).toBe(docBefore);
|
|
134
|
-
expect(globalThis.window).toBe(winBefore);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('suppresses watermark when watermark is false', () => {
|
|
138
|
-
const svg = renderStaticSVG(lineSpec, { watermark: false });
|
|
139
|
-
expect(svg).not.toContain('oc-brand-text');
|
|
140
|
-
});
|
|
141
|
-
});
|