mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-09 03:38:48 +01:00
* feat: create vite project * feat: it's alive! * feat: `make dev` working! * feat: replace custom serviceWorker with vite plugin * test: replace Jest with Vitest * fix: run prettier * fix: skip eslint for now. * chore: remove ui.old folder * refactor: replace lodash.pick with simple destructuring * fix: eslint errors (wip) * fix: eslint errors (wip) * fix: display-name eslint errors (wip) * fix: no-console eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: react-refresh/only-export-components eslint errors (wip) * fix: build * fix: pwa manifest * refactor: pwa manifest * refactor: simplify PORT configuration * refactor: rename simple JS files * test: cover playlistUtils * fix: react-image-lightbox * feat(ui): add sourcemaps to help debug issues
120 lines
3.6 KiB
JavaScript
120 lines
3.6 KiB
JavaScript
import React from 'react'
|
|
import { Provider } from 'react-redux'
|
|
import { createStore } from 'redux'
|
|
import mediaQuery from 'css-mediaquery'
|
|
import { renderHook } from '@testing-library/react-hooks'
|
|
import useCurrentTheme from './useCurrentTheme'
|
|
import { themeReducer } from '../reducers/themeReducer'
|
|
import { AUTO_THEME_ID } from '../consts'
|
|
|
|
function createMatchMedia(theme) {
|
|
return (query) => ({
|
|
matches: mediaQuery.match(query, { 'prefers-color-scheme': theme }),
|
|
addListener: () => {},
|
|
removeListener: () => {},
|
|
})
|
|
}
|
|
|
|
describe('useCurrentTheme', () => {
|
|
describe('with user preference theme as light', () => {
|
|
beforeAll(() => {
|
|
window.matchMedia = createMatchMedia('light')
|
|
})
|
|
it('sets theme as light in auto mode', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider store={createStore(themeReducer, { theme: AUTO_THEME_ID })}>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
expect(result.current.themeName).toMatch('Light')
|
|
})
|
|
it('sets theme as dark', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider store={createStore(themeReducer, { theme: 'DarkTheme' })}>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
|
|
expect(result.current.themeName).toMatch('Dark')
|
|
})
|
|
it('sets theme as light', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider store={createStore(themeReducer, { theme: 'LightTheme' })}>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
|
|
expect(result.current.themeName).toMatch('Light')
|
|
})
|
|
it('sets theme as spotify-ish', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider
|
|
store={createStore(themeReducer, { theme: 'SpotifyTheme' })}
|
|
>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
|
|
expect(result.current.themeName).toMatch('Spotify-ish')
|
|
})
|
|
})
|
|
describe('with user preference theme as dark', () => {
|
|
beforeAll(() => {
|
|
window.matchMedia = createMatchMedia('dark')
|
|
})
|
|
it('sets theme as dark in auto mode', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider store={createStore(themeReducer, { theme: AUTO_THEME_ID })}>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
|
|
expect(result.current.themeName).toMatch('Dark')
|
|
})
|
|
it('sets theme as dark', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider store={createStore(themeReducer, { theme: 'DarkTheme' })}>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
|
|
expect(result.current.themeName).toMatch('Dark')
|
|
})
|
|
it('sets theme as light', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider store={createStore(themeReducer, { theme: 'LightTheme' })}>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
|
|
expect(result.current.themeName).toMatch('Light')
|
|
})
|
|
it('sets theme as spotify-ish', () => {
|
|
const { result } = renderHook(() => useCurrentTheme(), {
|
|
wrapper: ({ children }) => (
|
|
<Provider
|
|
store={createStore(themeReducer, { theme: 'SpotifyTheme' })}
|
|
>
|
|
{children}
|
|
</Provider>
|
|
),
|
|
})
|
|
|
|
expect(result.current.themeName).toMatch('Spotify-ish')
|
|
})
|
|
})
|
|
})
|