11import { 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'
33import Settings from './Settings'
44
55describe ( '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 ( )
0 commit comments