|
1 | 1 | /** @vitest-environment jsdom */ |
2 | 2 | import { describe, expect, it } from 'vitest' |
3 | | -import { SIM_ARTIFACT_SHELL } from '@/lib/workspace-files/artifact-stylesheet' |
| 3 | +import { SIM_ARTIFACT_SHELL, simTokenOverrides } from '@/lib/workspace-files/artifact-stylesheet' |
4 | 4 | import { compileSimPage } from '@/lib/workspace-files/page-compile' |
5 | 5 |
|
6 | 6 | function runShell(source: string) { |
@@ -39,3 +39,20 @@ describe('shell layout decisions', () => { |
39 | 39 | ).toContain('is-disabled') |
40 | 40 | }) |
41 | 41 | }) |
| 42 | + |
| 43 | +describe('simTokenOverrides', () => { |
| 44 | + // The overrides pin the app's LIVE token values — which are one theme's |
| 45 | + // palette. Scoping them to the app's current theme is what keeps the |
| 46 | + // page's own light/dark toggle alive: pinning both `[data-theme]` states |
| 47 | + // (the pre-fix behavior) froze the preview on the app's palette no matter |
| 48 | + // what the toggle set. |
| 49 | + it('pins the live tokens only under the current app theme', () => { |
| 50 | + document.documentElement.style.setProperty('--bg', '#123456') |
| 51 | + const block = simTokenOverrides('light') |
| 52 | + expect(block).toContain(':root[data-theme="light"]') |
| 53 | + expect(block).toContain('--bg:#123456') |
| 54 | + expect(block).not.toContain('[data-theme="dark"]') |
| 55 | + expect(block).not.toMatch(/(^|\{|,):root[,{]/) |
| 56 | + document.documentElement.style.removeProperty('--bg') |
| 57 | + }) |
| 58 | +}) |
0 commit comments