|
@@ -22,19 +22,23 @@ const mockUserTheme = (theme: string | undefined) => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+const getRoot = () => document.querySelector(':root') as HTMLElement
|
|
|
+
|
|
|
const haveDOMTheme = (theme: string | undefined) => {
|
|
|
- const root = document.querySelector(':root') as HTMLElement
|
|
|
+ const root = getRoot()
|
|
|
+
|
|
|
if (!theme) {
|
|
|
root.removeAttribute('data-theme')
|
|
|
+ root.style.colorScheme = 'normal'
|
|
|
} else {
|
|
|
root.dataset.theme = theme
|
|
|
+ root.style.colorScheme = theme
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const getDOMTheme = () => {
|
|
|
- const root = document.querySelector(':root') as HTMLElement
|
|
|
- return root.dataset.theme
|
|
|
-}
|
|
|
+const getDOMTheme = () => getRoot().dataset.theme
|
|
|
+
|
|
|
+const getDOMColorScheme = () => getRoot().style.colorScheme
|
|
|
|
|
|
describe('useThemeStore', () => {
|
|
|
beforeEach(() => {
|
|
@@ -96,9 +100,9 @@ describe('useThemeStore', () => {
|
|
|
},
|
|
|
)
|
|
|
|
|
|
- const themStore = useThemeStore()
|
|
|
- const { updateTheme } = themStore
|
|
|
- const { currentTheme, savingTheme } = storeToRefs(themStore)
|
|
|
+ const themeStore = useThemeStore()
|
|
|
+ const { updateTheme } = themeStore
|
|
|
+ const { currentTheme, savingTheme } = storeToRefs(themeStore)
|
|
|
|
|
|
await updateTheme(EnumAppearanceTheme.Dark)
|
|
|
|
|
@@ -131,12 +135,14 @@ describe('useThemeStore', () => {
|
|
|
|
|
|
expect(currentTheme).toBe(EnumAppearanceTheme.Dark)
|
|
|
expect(getDOMTheme()).toBe(EnumAppearanceTheme.Dark)
|
|
|
+ expect(getDOMColorScheme()).toBe(EnumAppearanceTheme.Dark)
|
|
|
|
|
|
mockMediaTheme(EnumAppearanceTheme.Light)
|
|
|
addEventListener.mock.calls[0][1]()
|
|
|
|
|
|
expect(currentTheme).toBe(EnumAppearanceTheme.Dark)
|
|
|
expect(getDOMTheme()).toBe(EnumAppearanceTheme.Dark)
|
|
|
+ expect(getDOMColorScheme()).toBe(EnumAppearanceTheme.Dark)
|
|
|
})
|
|
|
|
|
|
describe('isDarkMode', () => {
|