|
| 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