Skip to content

Commit f63537e

Browse files
Saurabh Kumar BajpaiSaurabh Kumar Bajpai
authored andcommitted
test: cover preferred export format hook
1 parent 6541979 commit f63537e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { act, renderHook } from '@testing-library/react'
2+
import { beforeEach, describe, expect, it } from 'vitest'
3+
import { usePreferredExportFormat } from '../../../src/hooks/usePreferredExportFormat'
4+
5+
const STORAGE_KEY = 'secuscan:preferred-export-format'
6+
7+
describe('usePreferredExportFormat', () => {
8+
beforeEach(() => {
9+
localStorage.clear()
10+
})
11+
12+
it('starts with no preferred format when storage is empty', () => {
13+
const { result } = renderHook(() => usePreferredExportFormat())
14+
15+
expect(result.current.preferred).toBeNull()
16+
})
17+
18+
it('restores a stored preferred format on first render', () => {
19+
localStorage.setItem(STORAGE_KEY, 'pdf')
20+
21+
const { result } = renderHook(() => usePreferredExportFormat())
22+
23+
expect(result.current.preferred).toBe('pdf')
24+
})
25+
26+
it('persists a newly selected preferred format', () => {
27+
const { result } = renderHook(() => usePreferredExportFormat())
28+
29+
act(() => {
30+
result.current.savePreference('csv')
31+
})
32+
33+
expect(result.current.preferred).toBe('csv')
34+
expect(localStorage.getItem(STORAGE_KEY)).toBe('csv')
35+
})
36+
})

0 commit comments

Comments
 (0)