Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

Commit 4a7524b

Browse files
committed
Update themes tests
1 parent 5c817c9 commit 4a7524b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/player/src/test/mocks/plugin-fs.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from '@tauri-apps/plugin-fs';
2+
import { WatchEvent } from '@tauri-apps/plugin-fs';
23
import { type Mock } from 'vitest';
34

45
vi.mock('@tauri-apps/plugin-fs', () => ({
@@ -7,16 +8,21 @@ vi.mock('@tauri-apps/plugin-fs', () => ({
78
readDir: vi.fn(),
89
readTextFile: vi.fn(),
910
remove: vi.fn(),
10-
watch: vi.fn(async (_dir: string, cb: (evt: { paths: string[] }) => void) => {
11-
watchCb = cb;
12-
return () => {};
13-
}),
11+
watchImmediate: vi.fn(
12+
async (
13+
_paths: string | string[] | URL | URL[],
14+
cb: (event: WatchEvent) => void,
15+
) => {
16+
watchImmediateCb = cb;
17+
return () => {};
18+
},
19+
),
1420
BaseDirectory: {
1521
AppData: '/home/user/.local/share/com.nuclearplayer',
1622
},
1723
}));
1824

19-
export let watchCb: ((evt: { paths: string[] }) => void) | null = null;
25+
export let watchImmediateCb: ((event: WatchEvent) => void) | null = null;
2026

2127
const readTextFileMap: Record<string, string> = {};
2228

packages/player/src/views/Themes/Themes.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
stopAdvancedThemeWatcher,
1212
} from '../../services/advancedThemeDirService';
1313
import { useSettingsStore } from '../../stores/settingsStore';
14-
import { PluginFsMock, watchCb } from '../../test/mocks/plugin-fs';
14+
import { PluginFsMock, watchImmediateCb } from '../../test/mocks/plugin-fs';
1515
import { ThemesWrapper } from './Themes.test-wrapper';
1616

1717
vi.mock('@tauri-apps/plugin-store', async () => {
@@ -160,7 +160,7 @@ describe('Themes view', async () => {
160160
await ThemesWrapper.selectAdvancedTheme('My Theme');
161161
expect(themes.applyAdvancedTheme).toHaveBeenCalledTimes(1);
162162

163-
watchCb?.({ paths: ['themes/my.json'] });
163+
watchImmediateCb?.({ paths: ['themes/my.json'], type: 'any', attrs: {} });
164164

165165
await waitFor(() =>
166166
expect(themes.applyAdvancedTheme).toHaveBeenCalledTimes(2),
@@ -196,15 +196,15 @@ describe('Themes view', async () => {
196196
expect(themes.applyAdvancedTheme).toHaveBeenCalledTimes(1);
197197

198198
// Change unrelated file -> no reload
199-
watchCb?.({ paths: ['/appdata/themes/other.json'] });
199+
watchImmediateCb?.({ paths: ['/appdata/themes/other.json'] });
200200
await new Promise((r) => setTimeout(r, 0));
201201
expect(themes.applyAdvancedTheme).toHaveBeenCalledTimes(1);
202202

203203
// Switch back to Default (basic mode)
204204
await ThemesWrapper.selectDefaultTheme();
205205

206206
// Now even if the same file changes, no reload should occur
207-
watchCb?.({ paths: ['/appdata/themes/my.json'] });
207+
watchImmediateCb?.({ paths: ['/appdata/themes/my.json'] });
208208
expect(themes.applyAdvancedTheme).toHaveBeenCalledTimes(1);
209209
});
210210

0 commit comments

Comments
 (0)