mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 22:41:58 +03:00
Merge b6da4c246e into 37cfd2144b
This commit is contained in:
commit
42ddd6cd4a
2 changed files with 31 additions and 2 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, writeImageFile } 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', () => ({
|
||||||
|
|
@ -382,6 +382,30 @@ describe('storage', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('writeImageFile', () => {
|
||||||
|
it('returns false when not in Tauri', async () => {
|
||||||
|
const result = await writeImageFile('base64data');
|
||||||
|
expect(invoke).not.toHaveBeenCalled();
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true when in Tauri and invoke succeeds', async () => {
|
||||||
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
|
vi.mocked(invoke).mockResolvedValue(true);
|
||||||
|
const result = await writeImageFile('base64data');
|
||||||
|
expect(invoke).toHaveBeenCalledWith('write_image_file', { dataBase64: 'base64data' });
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false and logs warning if invoke fails', async () => {
|
||||||
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
|
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
||||||
|
const result = await writeImageFile('base64data');
|
||||||
|
expect(logger.warn).toHaveBeenCalledWith('writeImageFile failed', expect.any(Error));
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('fetchHistoricalRates', () => {
|
describe('fetchHistoricalRates', () => {
|
||||||
it('uses invoke when in Tauri', async () => {
|
it('uses invoke when in Tauri', async () => {
|
||||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,12 @@ export async function fetchHistoricalRates(date: string): Promise<Record<string,
|
||||||
|
|
||||||
export async function writeImageFile(dataBase64: string): Promise<boolean> {
|
export async function writeImageFile(dataBase64: string): Promise<boolean> {
|
||||||
if (!isTauri()) return false;
|
if (!isTauri()) return false;
|
||||||
return invoke("write_image_file", { dataBase64 });
|
try {
|
||||||
|
return await invoke("write_image_file", { dataBase64 });
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn("writeImageFile failed", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- market data
|
// ---------- market data
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue