Skip to content

Commit 7644dfd

Browse files
committed
test: fix broken tests after UI and safe storage updates
1 parent f4be610 commit 7644dfd

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/Settings.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest'
2-
import { render, screen, fireEvent } from '@testing-library/react'
2+
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
33
import Settings from './Settings'
44

55
describe('Settings Component', () => {
@@ -24,12 +24,12 @@ describe('Settings Component', () => {
2424
expect(screen.getByText('Appearance')).toBeInTheDocument()
2525
})
2626

27-
it('loads initial state from localStorage', () => {
28-
localStorage.setItem('papercache-apikey', 'sk-test-key')
27+
it('loads initial state from localStorage', async () => {
28+
localStorage.setItem('papercache-apikey-secure', 'sk-test-key')
2929
render(<Settings />)
3030

3131
const apiKeyInput = screen.getByPlaceholderText('sk-...') as HTMLInputElement
32-
expect(apiKeyInput.value).toBe('sk-test-key')
32+
await waitFor(() => expect(apiKeyInput.value).toBe('sk-test-key'))
3333
})
3434

3535
it('updates state when inputs change', () => {
@@ -41,7 +41,7 @@ describe('Settings Component', () => {
4141
expect((apiKeyInput as HTMLInputElement).value).toBe('sk-new-key')
4242
})
4343

44-
it('saves settings to localStorage on Save Settings button click', () => {
44+
it('saves settings to localStorage on Save Settings button click', async () => {
4545
render(<Settings />)
4646

4747
const apiKeyInput = screen.getByPlaceholderText('sk-...')
@@ -50,14 +50,16 @@ describe('Settings Component', () => {
5050
const saveButton = screen.getByText('Save Settings')
5151
fireEvent.click(saveButton)
5252

53-
expect(localStorage.getItem('papercache-apikey')).toBe('sk-new-key')
54-
expect(window.electronAPI.closeWindow).toHaveBeenCalled()
53+
await waitFor(() => {
54+
expect(localStorage.getItem('papercache-apikey-secure')).toBe('sk-new-key')
55+
expect(window.electronAPI.closeWindow).toHaveBeenCalled()
56+
})
5557
})
5658

5759
it('calls quitApp when Quit PaperCache is clicked', () => {
5860
render(<Settings />)
5961

60-
const quitButton = screen.getByText('Quit PaperCache')
62+
const quitButton = screen.getByText('Quit')
6163
fireEvent.click(quitButton)
6264

6365
expect(window.electronAPI.quitApp).toHaveBeenCalled()

src/setupTests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ if (!window.electronAPI) {
3131
exportNote: async () => true,
3232
openExternal: () => {},
3333
openFile: () => {},
34+
safeStorageEncrypt: async (val: string) => val,
35+
safeStorageDecrypt: async (val: string) => val,
3436
} as any
3537
}

0 commit comments

Comments
 (0)