hololake-platform/src/hooks/useGuanghuTheme.test.ts

31 lines
1.3 KiB
TypeScript
Raw Normal View History

import { act, renderHook } from '@testing-library/react'
import { beforeEach, describe, expect, it } from 'vitest'
import { GUANGHU_THEME_STORAGE_KEY } from '../lib/guanghuTheme'
import { THEME_MODE_STORAGE_KEY } from '../lib/themeMode'
import { useGuanghuTheme } from './useGuanghuTheme'
describe('useGuanghuTheme', () => {
beforeEach(() => {
window.localStorage.clear()
document.documentElement.removeAttribute('data-guanghu-theme')
document.documentElement.removeAttribute('data-theme')
document.documentElement.classList.remove('dark')
})
it('makes the lake presets visibly switch the document between light and dark', () => {
window.localStorage.setItem(GUANGHU_THEME_STORAGE_KEY, 'lake-light')
const { result } = renderHook(() => useGuanghuTheme())
expect(document.documentElement).toHaveAttribute('data-guanghu-theme', 'lake-light')
expect(document.documentElement).toHaveAttribute('data-theme', 'light')
expect(window.localStorage.getItem(THEME_MODE_STORAGE_KEY)).toBe('light')
act(() => result.current.cycleTheme())
expect(document.documentElement).toHaveAttribute('data-guanghu-theme', 'lake-dark')
expect(document.documentElement).toHaveAttribute('data-theme', 'dark')
expect(document.documentElement).toHaveClass('dark')
expect(window.localStorage.getItem(THEME_MODE_STORAGE_KEY)).toBe('dark')
})
})