@@ -13,7 +13,11 @@ import { renderUniwind } from '../utils'
1313
1414describe ( 'ScopedTheme' , ( ) => {
1515 afterEach ( ( ) => {
16- Uniwind . setTheme ( 'light' )
16+ act ( ( ) => {
17+ Uniwind . setTheme ( 'light' )
18+ Uniwind . updateCSSVariables ( 'light' , { '--color-background' : '#ffffff' } )
19+ Uniwind . updateCSSVariables ( 'dark' , { '--color-background' : '#000000' } )
20+ } )
1721 } )
1822
1923 test ( 'Component styles' , ( ) => {
@@ -212,4 +216,137 @@ describe('ScopedTheme', () => {
212216 expect ( nestedDark ) . toHaveBeenLastCalledWith ( 'dark' )
213217 expect ( nestedLightInDark ) . toHaveBeenLastCalledWith ( 'light' )
214218 } )
219+
220+ describe ( 'updateCSSVariables' , ( ) => {
221+ test ( 'Component styles' , ( ) => {
222+ const { getStylesFromId } = renderUniwind (
223+ < React . Fragment >
224+ < View className = "bg-background" testID = "base" />
225+ < ScopedTheme theme = "dark" >
226+ < View className = "bg-background" testID = "nested-dark" />
227+ < ScopedTheme theme = "light" >
228+ < View className = "bg-background" testID = "nested-light-in-dark" />
229+ </ ScopedTheme >
230+ </ ScopedTheme >
231+ </ React . Fragment > ,
232+ )
233+
234+ expect ( getStylesFromId ( 'base' ) . backgroundColor ) . toEqual ( '#ffffff' )
235+ expect ( getStylesFromId ( 'nested-dark' ) . backgroundColor ) . toEqual ( '#000000' )
236+ expect ( getStylesFromId ( 'nested-light-in-dark' ) . backgroundColor ) . toEqual ( '#ffffff' )
237+
238+ act ( ( ) => {
239+ Uniwind . updateCSSVariables ( 'dark' , { '--color-background' : '#123456' } )
240+ } )
241+
242+ expect ( getStylesFromId ( 'base' ) . backgroundColor ) . toEqual ( '#ffffff' )
243+ expect ( getStylesFromId ( 'nested-dark' ) . backgroundColor ) . toEqual ( '#123456' )
244+ expect ( getStylesFromId ( 'nested-light-in-dark' ) . backgroundColor ) . toEqual ( '#ffffff' )
245+ } )
246+
247+ test ( 'withUniwind' , ( ) => {
248+ const Component : React . FC < ActivityIndicatorProps > = ( props ) => < ActivityIndicator { ...props } />
249+ const WithUniwind = withUniwind ( Component )
250+
251+ const { getStylesFromId } = renderUniwind (
252+ < React . Fragment >
253+ < WithUniwind className = "bg-background" testID = "base" />
254+ < ScopedTheme theme = "dark" >
255+ < WithUniwind className = "bg-background" testID = "nested-dark" />
256+ < ScopedTheme theme = "light" >
257+ < WithUniwind className = "bg-background" testID = "nested-light-in-dark" />
258+ </ ScopedTheme >
259+ </ ScopedTheme >
260+ </ React . Fragment > ,
261+ )
262+
263+ expect ( getStylesFromId ( 'base' ) . backgroundColor ) . toEqual ( '#ffffff' )
264+ expect ( getStylesFromId ( 'nested-dark' ) . backgroundColor ) . toEqual ( '#000000' )
265+ expect ( getStylesFromId ( 'nested-light-in-dark' ) . backgroundColor ) . toEqual ( '#ffffff' )
266+
267+ act ( ( ) => {
268+ Uniwind . updateCSSVariables ( 'dark' , { '--color-background' : '#123456' } )
269+ } )
270+
271+ expect ( getStylesFromId ( 'base' ) . backgroundColor ) . toEqual ( '#ffffff' )
272+ expect ( getStylesFromId ( 'nested-dark' ) . backgroundColor ) . toEqual ( '#123456' )
273+ expect ( getStylesFromId ( 'nested-light-in-dark' ) . backgroundColor ) . toEqual ( '#ffffff' )
274+ } )
275+
276+ test ( 'useResolveClassNames' , ( ) => {
277+ const base = jest . fn ( )
278+ const nestedDark = jest . fn ( )
279+ const nestedLightInDark = jest . fn ( )
280+
281+ const Component = ( props : { test : jest . Mock } ) => {
282+ const { backgroundColor } = useResolveClassNames ( 'bg-background' )
283+
284+ props . test ( backgroundColor )
285+
286+ return null
287+ }
288+
289+ renderUniwind (
290+ < React . Fragment >
291+ < Component test = { base } />
292+ < ScopedTheme theme = "dark" >
293+ < Component test = { nestedDark } />
294+ < ScopedTheme theme = "light" >
295+ < Component test = { nestedLightInDark } />
296+ </ ScopedTheme >
297+ </ ScopedTheme >
298+ </ React . Fragment > ,
299+ )
300+
301+ expect ( base ) . toHaveBeenCalledWith ( '#ffffff' )
302+ expect ( nestedDark ) . toHaveBeenCalledWith ( '#000000' )
303+ expect ( nestedLightInDark ) . toHaveBeenCalledWith ( '#ffffff' )
304+
305+ act ( ( ) => {
306+ Uniwind . updateCSSVariables ( 'dark' , { '--color-background' : '#123456' } )
307+ } )
308+
309+ expect ( base ) . toHaveBeenLastCalledWith ( '#ffffff' )
310+ expect ( nestedDark ) . toHaveBeenLastCalledWith ( '#123456' )
311+ expect ( nestedLightInDark ) . toHaveBeenLastCalledWith ( '#ffffff' )
312+ } )
313+
314+ test ( 'useCSSVariable' , ( ) => {
315+ const base = jest . fn ( )
316+ const nestedDark = jest . fn ( )
317+ const nestedLightInDark = jest . fn ( )
318+
319+ const Component = ( props : { test : jest . Mock } ) => {
320+ const backgroundColor = useCSSVariable ( '--color-background' )
321+
322+ props . test ( backgroundColor )
323+
324+ return null
325+ }
326+
327+ renderUniwind (
328+ < React . Fragment >
329+ < Component test = { base } />
330+ < ScopedTheme theme = "dark" >
331+ < Component test = { nestedDark } />
332+ < ScopedTheme theme = "light" >
333+ < Component test = { nestedLightInDark } />
334+ </ ScopedTheme >
335+ </ ScopedTheme >
336+ </ React . Fragment > ,
337+ )
338+
339+ expect ( base ) . toHaveBeenCalledWith ( '#ffffff' )
340+ expect ( nestedDark ) . toHaveBeenCalledWith ( '#000000' )
341+ expect ( nestedLightInDark ) . toHaveBeenCalledWith ( '#ffffff' )
342+
343+ act ( ( ) => {
344+ Uniwind . updateCSSVariables ( 'dark' , { '--color-background' : '#123456' } )
345+ } )
346+
347+ expect ( base ) . toHaveBeenLastCalledWith ( '#ffffff' )
348+ expect ( nestedDark ) . toHaveBeenLastCalledWith ( '#123456' )
349+ expect ( nestedLightInDark ) . toHaveBeenLastCalledWith ( '#ffffff' )
350+ } )
351+ } )
215352} )
0 commit comments