1+ import { describe , it , expect } from 'vitest' ;
2+ import { createTokens } from './tokens' ;
3+
4+ describe ( 'createTokens' , ( ) => {
5+ it ( 'should create styles function' , ( ) => {
6+ const { styles } = createTokens ( {
7+ colors : {
8+ primary : '#000000' ,
9+ secondary : '#ffffff' ,
10+ } ,
11+ spacing : {
12+ sm : 8 ,
13+ md : 16 ,
14+ } ,
15+ } ) ;
16+
17+ expect ( typeof styles ) . toBe ( 'function' ) ;
18+ } ) ;
19+
20+ it ( 'should resolve token references in styles' , ( ) => {
21+ const { styles } = createTokens ( {
22+ colors : {
23+ primary : '#000000' ,
24+ } ,
25+ spacing : {
26+ sm : 8 ,
27+ } ,
28+ } ) ;
29+
30+ const result = styles ( {
31+ base : {
32+ backgroundColor : '$colors.primary' ,
33+ padding : '$spacing.sm' ,
34+ } ,
35+ variants : { } ,
36+ } ) ;
37+
38+ expect ( result ( ) ) . toEqual ( {
39+ backgroundColor : '#000000' ,
40+ padding : 8 ,
41+ } ) ;
42+ } ) ;
43+
44+ it ( 'should resolve token references in variants' , ( ) => {
45+ const { styles } = createTokens ( {
46+ colors : {
47+ primary : '#000000' ,
48+ } ,
49+ borderStyles : {
50+ default : 'solid' ,
51+ } ,
52+ } ) ;
53+
54+ const result = styles ( {
55+ base : { } ,
56+ variants : {
57+ type : {
58+ primary : {
59+ backgroundColor : '$colors.primary' ,
60+ borderStyle : '$borderStyles.default' ,
61+ } ,
62+ } ,
63+ } ,
64+ } ) ;
65+
66+ expect ( result ( { type : 'primary' } ) ) . toEqual ( {
67+ backgroundColor : '#000000' ,
68+ borderStyle : 'solid' ,
69+ } ) ;
70+ } ) ;
71+
72+ it ( 'should handle compound variants' , ( ) => {
73+ const { styles } = createTokens ( {
74+ colors : {
75+ primary : '#000000' ,
76+ } ,
77+ spacing : {
78+ sm : 8 ,
79+ } ,
80+ } ) ;
81+
82+ const result = styles ( {
83+ base : { } ,
84+ variants : {
85+ size : { small : { } } ,
86+ type : { primary : { } } ,
87+ } ,
88+ compoundVariants : [ {
89+ variants : { size : 'small' as const , type : 'primary' as const } ,
90+ style : {
91+ backgroundColor : '$colors.primary' ,
92+ padding : '$spacing.sm' ,
93+ } ,
94+ } ] ,
95+ } ) ;
96+
97+ expect ( result ( { size : 'small' , type : 'primary' } ) ) . toEqual ( {
98+ backgroundColor : '#000000' ,
99+ padding : 8 ,
100+ } ) ;
101+ } ) ;
102+
103+ it ( 'should ignore missing token references' , ( ) => {
104+ const { styles } = createTokens ( {
105+ colors : {
106+ primary : '#000000' ,
107+ } ,
108+ } ) ;
109+
110+ const result = styles ( {
111+ base : {
112+ backgroundColor : '$colors.nonexistent' ,
113+ color : '$colors.primary' ,
114+ } ,
115+ variants : { } ,
116+ } ) ;
117+
118+ expect ( result ( ) ) . toEqual ( {
119+ color : '#000000' ,
120+ } ) ;
121+ } ) ;
122+
123+ it ( 'should support all allowed token categories' , ( ) => {
124+ const { styles } = createTokens ( {
125+ colors : { primary : '#000000' } ,
126+ spacing : { sm : 8 } ,
127+ fontSizes : { base : 16 } ,
128+ fonts : { body : 'Arial' } ,
129+ lineHeight : { normal : 1.5 } ,
130+ borderWidth : { thin : 1 } ,
131+ borderStyles : { default : 'solid' } ,
132+ } ) ;
133+
134+ const result = styles ( {
135+ base : {
136+ color : '$colors.primary' ,
137+ padding : '$spacing.sm' ,
138+ fontSize : '$fontSizes.base' ,
139+ fontFamily : '$fonts.body' ,
140+ lineHeight : '$lineHeight.normal' ,
141+ borderWidth : '$borderWidth.thin' ,
142+ borderStyle : '$borderStyles.default' ,
143+ } ,
144+ variants : { } ,
145+ } ) ;
146+
147+ expect ( result ( ) ) . toEqual ( {
148+ color : '#000000' ,
149+ padding : 8 ,
150+ fontSize : 16 ,
151+ fontFamily : 'Arial' ,
152+ lineHeight : 1.5 ,
153+ borderWidth : 1 ,
154+ borderStyle : 'solid' ,
155+ } ) ;
156+ } ) ;
157+ } ) ;
0 commit comments