@@ -2,17 +2,12 @@ import React from 'react';
22import { act , render } from '@testing-library/react' ;
33import { assertNotNull , TestUtils } from '@deephaven/utils' ;
44import { ThemeContextValue , ThemeProvider } from './ThemeProvider' ;
5- import {
6- DEFAULT_DARK_THEME_KEY ,
7- DEFAULT_LIGHT_THEME_KEY ,
8- ThemeData ,
9- ThemePreloadData ,
10- } from './ThemeModel' ;
5+ import { DEFAULT_LIGHT_THEME_KEY , ThemeData } from './ThemeModel' ;
116import {
127 calculatePreloadStyleContent ,
138 getActiveThemes ,
149 getDefaultBaseThemes ,
15- getThemePreloadData ,
10+ getDefaultSelectedThemeKey ,
1611 setThemePreloadData ,
1712} from './ThemeUtils' ;
1813import { useTheme } from './useTheme' ;
@@ -24,13 +19,17 @@ jest.mock('./ThemeUtils', () => {
2419 return {
2520 ...actual ,
2621 calculatePreloadStyleContent : jest . fn ( ) ,
27- getThemePreloadData : jest . fn ( actual . getThemePreloadData ) ,
22+ getDefaultSelectedThemeKey : jest . fn ( ) ,
23+ getThemeKeyOverride : jest . fn ( ) ,
2824 setThemePreloadData : jest . fn ( ) ,
2925 } ;
3026} ) ;
3127
32- const customThemes = [ { themeKey : 'themeA' } ] as [ ThemeData ] ;
33- const preloadA : ThemePreloadData = { themeKey : 'themeA' } ;
28+ const customThemes = [
29+ { themeKey : 'themeA' } ,
30+ { themeKey : 'mockDefaultSelectedThemeKey' } ,
31+ ] as ThemeData [ ] ;
32+ const defaultSelectedThemeKey = 'mockDefaultSelectedThemeKey' ;
3433
3534beforeEach ( ( ) => {
3635 jest . clearAllMocks ( ) ;
@@ -41,7 +40,10 @@ beforeEach(() => {
4140 . mockName ( 'calculatePreloadStyleContent' )
4241 . mockReturnValue ( ':root{mock-preload-content}' ) ;
4342
44- asMock ( getThemePreloadData ) . mockName ( 'getThemePreloadData' ) ;
43+ asMock ( getDefaultSelectedThemeKey )
44+ . mockName ( 'getDefaultSelectedThemeKey' )
45+ . mockReturnValue ( defaultSelectedThemeKey ) ;
46+
4547 asMock ( setThemePreloadData ) . mockName ( 'setThemePreloadData' ) ;
4648} ) ;
4749
@@ -57,16 +59,9 @@ describe('ThemeProvider', () => {
5759 themeContextValueRef . current = null ;
5860 } ) ;
5961
60- it . each ( [
61- [ null , null ] ,
62- [ null , preloadA ] ,
63- [ customThemes , null ] ,
64- [ customThemes , preloadA ] ,
65- ] as const ) (
66- 'should load themes based on preload data or default: %s, %s' ,
67- ( themes , preloadData ) => {
68- asMock ( getThemePreloadData ) . mockReturnValue ( preloadData ) ;
69-
62+ it . each ( [ null , customThemes ] ) (
63+ 'should load themes based on default selected theme key. customThemes: %o' ,
64+ themes => {
7065 const component = render (
7166 < ThemeProvider themes = { themes } >
7267 < MockChild />
@@ -79,31 +74,24 @@ describe('ThemeProvider', () => {
7974 expect ( themeContextValueRef . current . activeThemes ) . toBeNull ( ) ;
8075 } else {
8176 expect ( themeContextValueRef . current . activeThemes ) . toEqual (
82- getActiveThemes ( preloadData ?. themeKey ?? DEFAULT_DARK_THEME_KEY , {
77+ getActiveThemes ( defaultSelectedThemeKey , {
8378 base : getDefaultBaseThemes ( ) ,
8479 custom : themes ,
8580 } )
8681 ) ;
8782
8883 expect ( themeContextValueRef . current . selectedThemeKey ) . toEqual (
89- preloadData ?. themeKey ?? DEFAULT_DARK_THEME_KEY
84+ defaultSelectedThemeKey
9085 ) ;
9186 }
9287
9388 expect ( component . baseElement ) . toMatchSnapshot ( ) ;
9489 }
9590 ) ;
9691
97- it . each ( [
98- [ null , null ] ,
99- [ null , preloadA ] ,
100- [ customThemes , null ] ,
101- [ customThemes , preloadA ] ,
102- ] as const ) (
103- 'should set preload data when active themes change: %s, %s' ,
104- ( themes , preloadData ) => {
105- asMock ( getThemePreloadData ) . mockReturnValue ( preloadData ) ;
106-
92+ it . each ( [ null , customThemes ] as const ) (
93+ 'should set preload data when active themes change: %o' ,
94+ themes => {
10795 render (
10896 < ThemeProvider themes = { themes } >
10997 < MockChild />
@@ -114,14 +102,14 @@ describe('ThemeProvider', () => {
114102 expect ( setThemePreloadData ) . not . toHaveBeenCalled ( ) ;
115103 } else {
116104 expect ( setThemePreloadData ) . toHaveBeenCalledWith ( {
117- themeKey : preloadData ?. themeKey ?? DEFAULT_DARK_THEME_KEY ,
118- preloadStyleContent : calculatePreloadStyleContent ( ) ,
105+ themeKey : defaultSelectedThemeKey ,
106+ preloadStyleContent : calculatePreloadStyleContent ( { } ) ,
119107 } ) ;
120108 }
121109 }
122110 ) ;
123111
124- describe . each ( [ null , customThemes ] ) ( 'setSelectedThemeKey: %s ' , themes => {
112+ describe . each ( [ null , customThemes ] ) ( 'setSelectedThemeKey: %o ' , themes => {
125113 it . each ( [ DEFAULT_LIGHT_THEME_KEY , customThemes [ 0 ] . themeKey ] ) (
126114 'should change selected theme: %s' ,
127115 themeKey => {
0 commit comments