Skip to content

Commit 20b5645

Browse files
committed
chore: refactor the test locations
1 parent 3a4d1e4 commit 20b5645

File tree

6 files changed

+55
-57
lines changed

6 files changed

+55
-57
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, it, expect } from 'vitest'
2+
import { render, waitFor } from '@/tests/testing-library'
3+
import { ThemeToggle } from '@/features/theme/components/theme-toggle'
4+
import { executeComponentTest } from '@/tests/test-component'
5+
6+
describe('when the theme is toggled to dark', () => {
7+
it('the theme is set to dark', async () => {
8+
return executeComponentTest(
9+
() => render(<ThemeToggle />),
10+
async (component, user) => {
11+
user.click(await component.findByTestId('theme-toggle-menu'))
12+
user.click(await component.findByText('Dark'))
13+
14+
await waitFor(() => expect(document.documentElement.classList.contains('dark')).toBe(true))
15+
}
16+
)
17+
})
18+
})
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, it, expect, afterEach, beforeEach } from 'vitest'
2+
import { render, waitFor } from '@/tests/testing-library'
3+
import MatchMediaMock from '@/tests/mock-match-media'
4+
import { executeComponentTest } from '@/tests/test-component'
5+
6+
describe('when using the default system light theme', () => {
7+
it('the theme is set to light', () => {
8+
return executeComponentTest(
9+
() => render(<div />),
10+
async () => {
11+
await waitFor(() => expect(document.documentElement.classList.contains('light')).toBe(true))
12+
}
13+
)
14+
})
15+
})
16+
17+
describe('when using the default system dark theme', async () => {
18+
const matchMediaMock = new MatchMediaMock()
19+
20+
beforeEach(() => {
21+
// Set system theme to dark
22+
matchMediaMock.useMediaQuery('(prefers-color-scheme: dark)')
23+
})
24+
afterEach(() => {
25+
matchMediaMock.clear()
26+
})
27+
28+
it('the theme is set to dark', () => {
29+
return executeComponentTest(
30+
() => render(<div />),
31+
async () => {
32+
await waitFor(() => expect(document.documentElement.classList.contains('dark')).toBe(true))
33+
}
34+
)
35+
})
36+
})
File renamed without changes.

tests/donkey.test.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/theme.test.tsx

Lines changed: 0 additions & 50 deletions
This file was deleted.

vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import path from 'path'
77
export default defineConfig({
88
plugins: [react()],
99
test: {
10-
root: 'tests',
1110
environment: 'happy-dom',
12-
setupFiles: ['setup/clean-up-dom.ts'],
11+
setupFiles: ['src/tests/setup/clean-up-dom.ts'],
1312
},
1413

1514
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`

0 commit comments

Comments
 (0)