File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
redisinsight/ui/src/pages/settings/components/theme-settings Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 88 screen ,
99 waitFor ,
1010} from 'uiSrc/utils/test-utils'
11- import { Theme , THEMES } from 'uiSrc/constants'
11+ import { DEFAULT_THEME , Theme , THEMES } from 'uiSrc/constants'
1212import { TelemetryEvent } from 'uiSrc/telemetry'
1313import { updateUserConfigSettingsAction } from 'uiSrc/slices/user/user-settings'
1414
@@ -42,6 +42,17 @@ describe('ThemeSettings', () => {
4242 expect ( render ( < ThemeSettings /> ) ) . toBeTruthy ( )
4343 } )
4444
45+ it ( 'should render the default theme option selected when there is no previous config' , async ( ) => {
46+ render ( < ThemeSettings /> )
47+
48+ const selectedTheme = THEMES . find ( ( t ) => t . value === DEFAULT_THEME )
49+ expect ( selectedTheme ) . not . toBeUndefined ( )
50+
51+ await waitFor ( ( ) => {
52+ expect ( screen . getByText ( selectedTheme ?. inputDisplay as string ) ) . toBeInTheDocument ( )
53+ } )
54+ } )
55+
4556 it ( 'should update the selected theme and dispatch telemetry on change' , async ( ) => {
4657 const initialTheme = Theme . Dark
4758 const newTheme = Theme . Light
Original file line number Diff line number Diff line change @@ -8,21 +8,22 @@ import {
88} from 'uiSrc/slices/user/user-settings'
99import { ThemeContext } from 'uiSrc/contexts/themeContext'
1010import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
11- import { THEMES } from 'uiSrc/constants'
11+ import { DEFAULT_THEME , THEMES } from 'uiSrc/constants'
1212
1313const ThemeSettings = ( ) => {
1414 const dispatch = useDispatch ( )
15- const [ selectedTheme , setSelectedTheme ] = useState ( '' )
15+ const [ selectedTheme , setSelectedTheme ] = useState < string > ( DEFAULT_THEME )
1616 const options = THEMES
1717 const themeContext = useContext ( ThemeContext )
1818 const { theme, changeTheme } = themeContext
1919 const { config } = useSelector ( userSettingsSelector )
2020 const previousThemeRef = useRef < string > ( theme )
2121
2222 useEffect ( ( ) => {
23- if ( config ) {
24- setSelectedTheme ( config . theme )
25- previousThemeRef . current = config . theme
23+ if ( config && config . theme ) {
24+ const configTheme = config . theme
25+ setSelectedTheme ( configTheme )
26+ previousThemeRef . current = configTheme
2627 }
2728 } , [ config ] )
2829
You can’t perform that action at this time.
0 commit comments