|
1 | 1 | import { expect, test } from 'vitest' |
2 | | -import { evaluateExpression, replaceCssCalc, replaceCssVarsWithFallbacks } from './index' |
3 | | -import { State } from '../state' |
| 2 | +import { |
| 3 | + addThemeValues, |
| 4 | + evaluateExpression, |
| 5 | + replaceCssCalc, |
| 6 | + replaceCssVarsWithFallbacks, |
| 7 | +} from './index' |
| 8 | +import { State, TailwindCssSettings } from '../state' |
4 | 9 | import { DesignSystem } from '../v4' |
5 | 10 |
|
6 | 11 | test('replacing CSS variables with their fallbacks (when they have them)', () => { |
@@ -62,36 +67,45 @@ test('Evaluating CSS calc expressions', () => { |
62 | 67 | ) |
63 | 68 | }) |
64 | 69 |
|
65 | | -// test('Inlicing calc expressions using the design system', () => { |
66 | | -// let map = new Map<string, string>([['--spacing', '0.25rem']]) |
67 | | - |
68 | | -// let state: State = { |
69 | | -// enabled: true, |
70 | | -// designSystem: { |
71 | | -// resolveThemeValue: (name) => map.get(name) ?? null, |
72 | | -// } as DesignSystem, |
73 | | -// } |
74 | | - |
75 | | -// expect(inlineCalc(state, 'calc(var(--spacing) * 4)')).toBe('1rem') |
76 | | -// expect(inlineCalc(state, 'calc(var(--spacing) / 4)')).toBe('0.0625rem') |
77 | | -// expect(inlineCalc(state, 'calc(var(--spacing) * 1)')).toBe('0.25rem') |
78 | | -// expect(inlineCalc(state, 'calc(var(--spacing) * -1)')).toBe('-0.25rem') |
79 | | -// expect(inlineCalc(state, 'calc(1.25 / 0.875)')).toBe('1.4286') |
80 | | -// }) |
81 | | - |
82 | | -// test('Inlicing calc expressions using the design system', () => { |
83 | | -// let map = new Map<string, string>([['--spacing', '0.25rem']]) |
84 | | - |
85 | | -// let state: State = { |
86 | | -// enabled: true, |
87 | | -// designSystem: { |
88 | | -// resolveThemeValue: (name) => map.get(name) ?? null, |
89 | | -// } as DesignSystem, |
90 | | -// } |
91 | | - |
92 | | -// let settings: TailwindCssSettings = { |
93 | | -// rootFontSize: 10, |
94 | | -// } as any |
95 | | - |
96 | | -// expect(addThemeValues('calc(var(--spacing) * 4)', state, settings)).toBe('1rem') |
97 | | -// }) |
| 70 | +test('Inlicing calc expressions using the design system', () => { |
| 71 | + let map = new Map<string, string>([['--spacing', '0.25rem']]) |
| 72 | + |
| 73 | + let state: State = { |
| 74 | + enabled: true, |
| 75 | + designSystem: { |
| 76 | + resolveThemeValue: (name) => map.get(name) ?? null, |
| 77 | + } as DesignSystem, |
| 78 | + } |
| 79 | + |
| 80 | + let settings: TailwindCssSettings = { |
| 81 | + rootFontSize: 10, |
| 82 | + } as any |
| 83 | + |
| 84 | + expect(addThemeValues('calc(var(--spacing) * 4)', state, settings)).toBe( |
| 85 | + 'calc(var(--spacing) * 4) /* 1rem = 10px */', |
| 86 | + ) |
| 87 | + |
| 88 | + expect(addThemeValues('calc(var(--spacing) / 4)', state, settings)).toBe( |
| 89 | + 'calc(var(--spacing) / 4) /* 0.0625rem = 0.625px */', |
| 90 | + ) |
| 91 | + |
| 92 | + expect(addThemeValues('calc(var(--spacing) * 1)', state, settings)).toBe( |
| 93 | + 'calc(var(--spacing) * 1) /* 0.25rem = 2.5px */', |
| 94 | + ) |
| 95 | + |
| 96 | + expect(addThemeValues('calc(var(--spacing) * -1)', state, settings)).toBe( |
| 97 | + 'calc(var(--spacing) * -1) /* -0.25rem = -2.5px */', |
| 98 | + ) |
| 99 | + |
| 100 | + expect(addThemeValues('calc(var(--spacing) + 1rem)', state, settings)).toBe( |
| 101 | + 'calc(var(--spacing) + 1rem) /* 1.25rem = 12.5px */', |
| 102 | + ) |
| 103 | + |
| 104 | + expect(addThemeValues('calc(var(--spacing) - 1rem)', state, settings)).toBe( |
| 105 | + 'calc(var(--spacing) - 1rem) /* -0.75rem = -7.5px */', |
| 106 | + ) |
| 107 | + |
| 108 | + expect(addThemeValues('calc(var(--spacing) + 1px)', state, settings)).toBe( |
| 109 | + 'calc(var(--spacing) /* 0.25rem = 2.5px */ + 1px)', |
| 110 | + ) |
| 111 | +}) |
0 commit comments