Skip to content

Commit 5940ce0

Browse files
committed
chore: fix download function
1 parent ddfe864 commit 5940ce0

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

apps/web/src/hooks/__tests__/useInstrumentVisualization.test.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
55

66
import { useInstrumentVisualization } from '../useInstrumentVisualization';
77

8-
const mockInstrument = {
9-
useInstrument: vi.fn(() => ({
10-
instrument: {
11-
internal: {
12-
name: 'test'
13-
}
8+
const mockUseInstrument = vi.hoisted(() =>
9+
vi.fn(() => ({
10+
internal: {
11+
name: 'test'
1412
}
1513
}))
16-
};
14+
);
15+
16+
const mockRecords = [
17+
{
18+
__date__: new Date().getDate(),
19+
__time__: new Date().getTime(),
20+
someValue: 'abc'
21+
}
22+
];
1723

1824
vi.mock('@/hooks/useInstrument', () => ({
19-
useInstrument: () => mockInstrument
25+
useInstrument: mockUseInstrument
2026
}));
2127

2228
const mockStore = {
@@ -27,9 +33,9 @@ const mockStore = {
2733
}
2834
}))
2935
};
30-
const mockDownload = {
31-
useDownload: vi.fn()
32-
};
36+
37+
const mockUseDownload = vi.fn();
38+
3339
const mockNotification = {
3440
useNotificationsStore: vi.fn()
3541
};
@@ -50,7 +56,7 @@ vi.mock('@/store', () => ({
5056
}));
5157

5258
vi.mock('@douglasneuroinformatics/libui/hooks', () => ({
53-
useDownload: () => mockDownload,
59+
useDownload: () => mockUseDownload,
5460
useNotificationsStore: () => mockNotification,
5561
useTranslation: () => mockTranslation
5662
}));
@@ -61,14 +67,7 @@ vi.mock('react', async (importOriginal) => {
6167
...actual,
6268
useEffect: vi.fn(),
6369
useMemo: vi.fn(),
64-
useState: vi.fn(() => [
65-
'mockedRecords',
66-
vi.fn(() => ({
67-
__date__: new Date().getDate(),
68-
__time__: new Date().getTime(),
69-
someValue: 'abc'
70-
}))
71-
])
70+
useState: vi.fn(() => [mockRecords, 'setRecords'])
7271
};
7372
});
7473

@@ -92,8 +91,6 @@ describe('useInstrumentVisualization tests', () => {
9291
params: { subjectId: 'testId' }
9392
});
9493
act(() => dl('CSV'));
95-
expect(mockInstrument.useInstrument).toHaveBeenCalledOnce();
96-
expect(mockStore.useAppStore).toHaveBeenCalled();
9794
expect(records).toBeDefined();
9895
});
9996
});

0 commit comments

Comments
 (0)