@@ -102,4 +102,68 @@ describe('useChonkTheme', () => {
102102 expect ( result . current ) . toBe ( DO_NOT_USE_darkChonkTheme ) ;
103103 } ) ;
104104 } ) ;
105+
106+ describe ( 'enforce states' , ( ) => {
107+ it ( 'returns light chonk theme if the organization has chonk-ui-enforce feature and user prefers chonk theme' , ( ) => {
108+ ConfigStore . loadInitialData (
109+ ConfigFixture ( {
110+ user : UserFixture ( {
111+ options : { ...UserFixture ( ) . options , prefersChonkUI : true , theme : 'light' } ,
112+ } ) ,
113+ } )
114+ ) ;
115+ OrganizationStore . onUpdate ( OrganizationFixture ( { features : [ 'chonk-ui-enforce' ] } ) ) ;
116+ const { result} = renderHookWithProviders ( useThemeSwitcher ) ;
117+ expect ( result . current ) . toBe ( DO_NOT_USE_lightChonkTheme ) ;
118+ } ) ;
119+
120+ it ( 'returns dark chonk theme if the organization has chonk-ui-enforce feature and user prefers chonk theme' , ( ) => {
121+ ConfigStore . loadInitialData (
122+ ConfigFixture ( {
123+ user : UserFixture ( {
124+ options : { ...UserFixture ( ) . options , prefersChonkUI : true , theme : 'dark' } ,
125+ } ) ,
126+ } )
127+ ) ;
128+ OrganizationStore . onUpdate ( OrganizationFixture ( { features : [ 'chonk-ui-enforce' ] } ) ) ;
129+ const { result} = renderHookWithProviders ( useThemeSwitcher ) ;
130+ expect ( result . current ) . toBe ( DO_NOT_USE_darkChonkTheme ) ;
131+ } ) ;
132+
133+ it . each ( [ 'light' , 'dark' , 'system' ] as const ) (
134+ 'opt-out is respected for opted out users' ,
135+ theme => {
136+ ConfigStore . loadInitialData (
137+ ConfigFixture ( {
138+ user : UserFixture ( {
139+ options : { ...UserFixture ( ) . options , prefersChonkUI : false , theme} ,
140+ } ) ,
141+ } )
142+ ) ;
143+ OrganizationStore . onUpdate ( OrganizationFixture ( { features : [ 'chonk-ui-enforce' ] } ) ) ;
144+ const { result} = renderHookWithProviders ( useThemeSwitcher ) ;
145+ expect ( result . current ) . toBe (
146+ theme === 'light' || theme === 'system' ? lightTheme : darkTheme
147+ ) ;
148+ }
149+ ) ;
150+
151+ it . each ( [ 'light' , 'dark' , 'system' ] as const ) (
152+ 'opt-out is respected for opted out users' ,
153+ theme => {
154+ ConfigStore . loadInitialData (
155+ ConfigFixture ( {
156+ user : UserFixture ( {
157+ options : { ...UserFixture ( ) . options , prefersChonkUI : false , theme} ,
158+ } ) ,
159+ } )
160+ ) ;
161+ OrganizationStore . onUpdate ( OrganizationFixture ( { features : [ 'chonk-ui' ] } ) ) ;
162+ const { result} = renderHookWithProviders ( useThemeSwitcher ) ;
163+ expect ( result . current ) . toBe (
164+ theme === 'light' || theme === 'system' ? lightTheme : darkTheme
165+ ) ;
166+ }
167+ ) ;
168+ } ) ;
105169} ) ;
0 commit comments