Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/Settings.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import Settings from './Settings'

describe('Settings Component', () => {
Expand All @@ -24,12 +24,12 @@ describe('Settings Component', () => {
expect(screen.getByText('Appearance')).toBeInTheDocument()
})

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

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

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

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

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

expect(localStorage.getItem('papercache-apikey')).toBe('sk-new-key')
expect(window.electronAPI.closeWindow).toHaveBeenCalled()
await waitFor(() => {
expect(localStorage.getItem('papercache-apikey-secure')).toBe('sk-new-key')
expect(window.electronAPI.closeWindow).toHaveBeenCalled()
})
})

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

const quitButton = screen.getByText('Quit PaperCache')
const quitButton = screen.getByText('Quit')
fireEvent.click(quitButton)

expect(window.electronAPI.quitApp).toHaveBeenCalled()
Expand Down
2 changes: 2 additions & 0 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ if (!window.electronAPI) {
exportNote: async () => true,
openExternal: () => {},
openFile: () => {},
safeStorageEncrypt: async (val: string) => val,
safeStorageDecrypt: async (val: string) => val,
} as any
}
Loading