@@ -4,15 +4,10 @@ import { Text } from 'react-native'
44import { UnistylesRuntime } from 'react-native-unistyles'
55
66import { ThemeContextProvider } from '../ThemeContext'
7- import { darkTheme } from '../darkTheme'
8- import { lightTheme } from '../lightTheme'
7+ import { darkTheme , lightTheme } from '../themes'
98import { componentTokens , fontTokens , semanticTokens } from '../tokens'
10- import darkComponentTokens from '../tokens/components/dark.json'
11- import lightComponentTokens from '../tokens/components/light.json'
129import darkSemanticColorSchemeTokens from '../tokens/semantic/colorScheme/dark.json'
1310import lightSemanticColorSchemeTokens from '../tokens/semantic/colorScheme/light.json'
14- import semanticDimensions from '../tokens/semantic/dimensions.json'
15- import semanticEffects from '../tokens/semantic/effects.json'
1611import { ThemeVariant } from '../types'
1712
1813describe ( 'ThemeContextProvider' , ( ) => {
@@ -40,7 +35,7 @@ describe('ThemeContextProvider', () => {
4035 expect ( UnistylesRuntime . setTheme ) . toHaveBeenCalledWith ( 'light' )
4136 } )
4237
43- test ( 'при передаче fonts обновляет обе темы' , ( ) => {
38+ test ( 'при legacy-формате fonts обновляет обе темы' , ( ) => {
4439 const fonts = { primary : 'Roboto' , secondary : 'Inter' }
4540
4641 render (
@@ -59,14 +54,41 @@ describe('ThemeContextProvider', () => {
5954 )
6055
6156 const [ , updater ] = jest . mocked ( UnistylesRuntime . updateTheme ) . mock . calls [ 0 ]
62- const theme = UnistylesRuntime . getTheme ( 'light' )
57+ const theme = lightTheme
6358
6459 expect ( updater ( theme ) ) . toStrictEqual ( {
6560 ...theme ,
6661 fonts : {
6762 ...theme . fonts ,
63+ fontFamily : {
64+ ...theme . fonts . fontFamily ,
65+ heading : fonts . primary ,
66+ base : fonts . secondary ,
67+ } ,
6868 ...fonts ,
69- fontFamily : { base : fonts . secondary , heading : fonts . primary } ,
69+ } ,
70+ } )
71+ } )
72+
73+ test ( 'при актуальном формате fonts обновляет обе темы' , ( ) => {
74+ const fonts = { heading : 'Roboto' , base : 'Inter' }
75+
76+ render (
77+ < ThemeContextProvider fonts = { fonts } >
78+ < Text > child</ Text >
79+ </ ThemeContextProvider >
80+ )
81+
82+ const [ , updater ] = jest . mocked ( UnistylesRuntime . updateTheme ) . mock . calls [ 0 ]
83+ const theme = lightTheme
84+
85+ expect ( updater ( theme ) ) . toStrictEqual ( {
86+ ...theme ,
87+ fonts : {
88+ ...theme . fonts ,
89+ fontFamily : { ...theme . fonts . fontFamily , ...fonts } ,
90+ primary : fonts . heading ,
91+ secondary : fonts . base ,
7092 } ,
7193 } )
7294 } )
@@ -81,51 +103,57 @@ describe('ThemeContextProvider', () => {
81103 expect ( UnistylesRuntime . updateTheme ) . not . toHaveBeenCalled ( )
82104 } )
83105
84- test ( 'каждая тема содержит только соответствующую цветовую схему ' , ( ) => {
106+ test ( 'каждая тема содержит соответствующие semantic-токены ' , ( ) => {
85107 expect ( lightTheme . semantic . colorScheme ) . toBe ( lightSemanticColorSchemeTokens )
86108 expect ( darkTheme . semantic . colorScheme ) . toBe ( darkSemanticColorSchemeTokens )
87- expect ( lightTheme . semantic ) . not . toHaveProperty ( ' dimension' )
88- expect ( lightTheme . semantic ) . not . toHaveProperty ( ' effects' )
109+ expect ( lightTheme . semantic . dimension ) . toBe ( semanticTokens . dimension )
110+ expect ( lightTheme . semantic . effects ) . toBe ( semanticTokens . effects )
89111 } )
90112
91113 test ( 'общие semantic-токены не зависят от темы' , ( ) => {
92- expect ( semanticTokens . dimension ) . toBe ( semanticDimensions )
93- expect ( semanticTokens . effects ) . toBe ( semanticEffects )
114+ expect ( lightTheme . semantic . dimension ) . toBe ( darkTheme . semantic . dimension )
115+ expect ( lightTheme . semantic . effects ) . toBe ( darkTheme . semantic . effects )
94116 } )
95117
96- test ( 'component-токены не входят в публичные темы ' , ( ) => {
97- expect ( lightTheme ) . not . toHaveProperty ( 'components' )
98- expect ( darkTheme ) . not . toHaveProperty ( 'components' )
118+ test ( 'каждая тема содержит соответствующие component-токены ' , ( ) => {
119+ expect ( lightTheme . components ) . toBe ( componentTokens . light )
120+ expect ( darkTheme . components ) . toBe ( componentTokens . dark )
99121 } )
100122
101- test ( 'внутренняя карта component-токенов содержит обе темы ' , ( ) => {
102- expect ( componentTokens . light ) . toBe ( lightComponentTokens )
103- expect ( componentTokens . dark ) . toBe ( darkComponentTokens )
123+ test ( 'каждая тема содержит общие шрифтовые токены ' , ( ) => {
124+ expect ( lightTheme . fonts . fontSize ) . toBe ( fontTokens . fontSize )
125+ expect ( darkTheme . fonts . fontSize ) . toBe ( fontTokens . fontSize )
104126 } )
105127
106- test ( 'внутренняя тема Unistyles содержит сгенерированные токены' , ( ) => {
107- const internalLightTheme = UnistylesRuntime . getTheme ( 'light' )
108- const internalDarkTheme = UnistylesRuntime . getTheme ( 'dark' )
109-
110- expect ( internalLightTheme ) . toMatchObject ( {
111- components : lightComponentTokens ,
112- fonts : fontTokens ,
113- semantic : {
114- colorScheme : lightSemanticColorSchemeTokens ,
115- dimension : semanticDimensions ,
116- effects : semanticEffects ,
117- } ,
118- } )
128+ test ( 'публичные темы сохраняют legacy-алиасы шрифтов' , ( ) => {
129+ expect ( lightTheme . fonts ) . toStrictEqual (
130+ expect . objectContaining ( {
131+ primary : fontTokens . fontFamily . heading ,
132+ secondary : fontTokens . fontFamily . base ,
133+ } )
134+ )
135+ } )
119136
120- expect ( internalDarkTheme ) . toMatchObject ( {
121- components : darkComponentTokens ,
122- fonts : fontTokens ,
123- semantic : {
124- colorScheme : darkSemanticColorSchemeTokens ,
125- dimension : semanticDimensions ,
126- effects : semanticEffects ,
127- } ,
128- } )
129- expect ( internalLightTheme . fonts ) . toStrictEqual ( internalDarkTheme . fonts )
137+ test ( 'публичные темы сохраняют legacy-токены' , ( ) => {
138+ const legacyKeys = [
139+ 'background' ,
140+ 'border' ,
141+ 'colors' ,
142+ 'custom' ,
143+ 'effects' ,
144+ 'global' ,
145+ 'shadow' ,
146+ 'sizing' ,
147+ 'spacing' ,
148+ 'theme' ,
149+ 'typography' ,
150+ ]
151+
152+ expect ( Object . keys ( lightTheme ) ) . toStrictEqual (
153+ expect . arrayContaining ( legacyKeys )
154+ )
155+ expect ( Object . keys ( darkTheme ) ) . toStrictEqual (
156+ expect . arrayContaining ( legacyKeys )
157+ )
130158 } )
131159} )
0 commit comments