Skip to content

Commit 1f9c8bd

Browse files
authored
RI-7154: Color Theme select box shown incorrectly
* fix empty value set for theme if user has not configured it before * add test case for default selection in theme dropdown
1 parent 2629329 commit 1f9c8bd

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

redisinsight/ui/src/pages/settings/components/theme-settings/ThemeSettings.spec.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
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'
1212
import { TelemetryEvent } from 'uiSrc/telemetry'
1313
import { 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

redisinsight/ui/src/pages/settings/components/theme-settings/ThemeSettings.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ import {
88
} from 'uiSrc/slices/user/user-settings'
99
import { ThemeContext } from 'uiSrc/contexts/themeContext'
1010
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
11-
import { THEMES } from 'uiSrc/constants'
11+
import { DEFAULT_THEME, THEMES } from 'uiSrc/constants'
1212

1313
const 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

0 commit comments

Comments
 (0)