mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
Merge 04e3f4c19a into 37cfd2144b
This commit is contained in:
commit
822b0309e9
1 changed files with 35 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { logger } from "./logger";
|
||||
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, fetchMarketData } from './storage';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
|
||||
vi.mock('@tauri-apps/api/core', () => ({
|
||||
|
|
@ -34,6 +34,40 @@ describe('storage', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('fetchMarketData', () => {
|
||||
it('returns empty object when not in Tauri', async () => {
|
||||
const result = await fetchMarketData(['AAPL', 'MSFT']);
|
||||
expect(result).toEqual({});
|
||||
expect(invoke).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns empty object when symbols array is empty', async () => {
|
||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||
const result = await fetchMarketData([]);
|
||||
expect(result).toEqual({});
|
||||
expect(invoke).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses invoke when in Tauri and returns data', async () => {
|
||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||
const mockData = { AAPL: 150.0, MSFT: 300.0 };
|
||||
vi.mocked(invoke).mockResolvedValue(mockData);
|
||||
|
||||
const result = await fetchMarketData(['AAPL', 'MSFT']);
|
||||
expect(invoke).toHaveBeenCalledWith('fetch_market_data', { symbols: ['AAPL', 'MSFT'] });
|
||||
expect(result).toEqual(mockData);
|
||||
});
|
||||
|
||||
it('returns empty object and logs warning if invoke fails', async () => {
|
||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||
vi.mocked(invoke).mockRejectedValue(new Error('Network error'));
|
||||
|
||||
const result = await fetchMarketData(['AAPL', 'MSFT']);
|
||||
expect(logger.warn).toHaveBeenCalledWith('fetchMarketData failed', expect.any(Error));
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadSettings', () => {
|
||||
it('loads from localStorage when not in Tauri', async () => {
|
||||
vi.mocked(localStorage.getItem).mockReturnValue(JSON.stringify({ precision: 5 }));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue