Skip to content

Commit c4cedbc

Browse files
fix(configurator): align shade ramp probe with live framework cascade
1 parent 162787a commit c4cedbc

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

configurator/src/components/ShadeRamp.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* shade ramp — they expose only the subtle/muted/strong triplet.
1212
*/
1313
import { overrides, ui } from '../lib/store.svelte.js';
14-
import { measureBackground } from '../lib/probeHost.js';
14+
import { measureBackground, setProbeContext } from '../lib/probeHost.js';
1515
import { BRAND_COLOR_KEYS } from '../lib/brandColors.js';
1616
import { parseRgb } from '../lib/contrast.js';
1717
@@ -38,6 +38,11 @@
3838
for (const k in overrides) void overrides[k];
3939
void ui.previewTheme;
4040
queueMicrotask(() => {
41+
// Keep the probe host scoped to this component's live state. App.svelte
42+
// also refreshes the same singleton for contrast badges, but the shade
43+
// ramp must remain correct when mounted in isolation by component tests
44+
// and whenever the framework adds derived/registered color tokens.
45+
setProbeContext({ overrides, theme: ui.previewTheme });
4146
const next = {};
4247
for (const token of ALL_SHADE_TOKENS) {
4348
const rgb = measureBackground(`var(${token})`);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Component tests for the brand shade ramp added to the Colors panel.
3+
*
4+
* The framework now derives many color outputs through registered/relative
5+
* tokens, so the ramp must refresh the shared preview/probe cascade before it
6+
* measures swatches. jsdom cannot resolve OKLCH/color-mix into rgb(), so these
7+
* tests assert the rendered structure and the probe-host declarations instead
8+
* of requiring browser color serialization.
9+
*/
10+
import { describe, test, expect, beforeEach } from 'vitest';
11+
import { render, waitFor } from '@testing-library/svelte';
12+
import ShadeRamp from '../src/components/ShadeRamp.svelte';
13+
import { setOverride, clearAll, ui } from '../src/lib/store.svelte.js';
14+
15+
beforeEach(() => {
16+
clearAll();
17+
ui.previewTheme = 'light';
18+
});
19+
20+
describe('ShadeRamp', () => {
21+
test('renders the six brand rows with seven swatches each', () => {
22+
const { container } = render(ShadeRamp);
23+
24+
expect(container.querySelectorAll('.sr__row').length).toBe(6);
25+
expect(container.querySelectorAll('.sr__swatch').length).toBe(42);
26+
expect(container.textContent).toContain('Base');
27+
expect(container.textContent).toContain('Action');
28+
});
29+
30+
test('refreshes the probe cascade from live overrides and preview theme', async () => {
31+
setOverride('--sf-color-primary-light', 'oklch(0.65 0.2 40)');
32+
ui.previewTheme = 'dark';
33+
34+
const { container } = render(ShadeRamp);
35+
36+
await waitFor(() => {
37+
const hostStyle = document.getElementById('cfg-contrast-host')?.getAttribute('style') ?? '';
38+
expect(hostStyle).toContain('color-scheme: dark');
39+
expect(hostStyle).toContain('--sf-is-dark: 1');
40+
expect(hostStyle).toContain('--sf-color-primary-light: oklch(0.65 0.2 40)');
41+
expect(container.textContent).toContain('dark');
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)