mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 19:11:58 +03:00
🧪 Add tests for getLaunchFile in storage
Added missing unit tests for the getLaunchFile function to verify behavior when not in Tauri and when the invoke call succeeds or fails. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
37cfd2144b
commit
f97801b2cc
1 changed files with 26 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
import { isTauri, loadSettings, saveSettings, defaultSettingsData, loadAppData, saveAppData, flushAppData, setDataDir, runBackups, backupDeletedSheet, openBackupsFolder, chooseFolder, dataDirHasDocuments, migrateDataDir, fetchRates, fetchHistoricalRates } from './storage';
|
import { isTauri, loadSettings, saveSettings, defaultSettingsData, loadAppData, saveAppData, flushAppData, setDataDir, runBackups, backupDeletedSheet, openBackupsFolder, chooseFolder, dataDirHasDocuments, migrateDataDir, fetchRates, fetchHistoricalRates, getLaunchFile } from './storage';
|
||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
|
||||||
vi.mock('@tauri-apps/api/core', () => ({
|
vi.mock('@tauri-apps/api/core', () => ({
|
||||||
|
|
@ -416,4 +416,29 @@ describe('storage', () => {
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getLaunchFile', () => {
|
||||||
|
it('returns null if not in Tauri', async () => {
|
||||||
|
vi.stubGlobal('window', {});
|
||||||
|
expect(await getLaunchFile()).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns launch file path if in Tauri', async () => {
|
||||||
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
|
vi.mocked(invoke).mockResolvedValueOnce('/path/to/file.numi');
|
||||||
|
|
||||||
|
const result = await getLaunchFile();
|
||||||
|
expect(invoke).toHaveBeenCalledWith('get_launch_file', undefined);
|
||||||
|
expect(result).toBe('/path/to/file.numi');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null if invoke fails', async () => {
|
||||||
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
|
vi.mocked(invoke).mockRejectedValueOnce(new Error('invoke failed'));
|
||||||
|
|
||||||
|
const result = await getLaunchFile();
|
||||||
|
expect(invoke).toHaveBeenCalledWith('get_launch_file', undefined);
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue