@@ -43,7 +43,7 @@ test.describe('App Loading', () => {
4343} ) ;
4444
4545test . describe ( 'Dark Mode' , ( ) => {
46- test ( 'should toggle dark mode' , async ( { page } ) => {
46+ test ( 'should toggle dark mode via Settings modal ' , async ( { page } ) => {
4747 await page . goto ( '/' ) ;
4848 await expect ( page . locator ( '.app-spinner-container' ) ) . toBeHidden ( { timeout : 30000 } ) ;
4949
@@ -52,13 +52,37 @@ test.describe('Dark Mode', () => {
5252 document . documentElement . getAttribute ( 'data-theme' )
5353 ) ;
5454
55- // Find the dark mode toggle - assert it exists
56- const darkModeToggle = page . locator ( '[data-testid="toggle-dark-mode"]' ) ;
57- await expect ( darkModeToggle , 'Dark mode toggle should be visible' ) . toBeVisible ( ) ;
55+ // Open Settings modal - the gear icon button in sidebar
56+ const settingsButton = page . getByRole ( 'button' , { name : 'Settings' } ) ;
57+ await expect ( settingsButton ) . toBeVisible ( ) ;
58+ await settingsButton . click ( ) ;
5859
59- // Click the toggle
60+ // Wait for the Settings modal to appear
61+ const settingsModal = page . getByRole ( 'dialog' ) ;
62+ await expect ( settingsModal ) . toBeVisible ( { timeout : 5000 } ) ;
63+
64+ // Find and click the Dark Mode toggle inside the modal
65+ // The react-dark-mode-toggle library renders a button element
66+ // Find the section containing "Dark Mode" text, then locate the button within it
67+ const darkModeSection = settingsModal . locator ( 'div' ) . filter ( { hasText : / ^ D a r k M o d e / } ) . first ( ) ;
68+ const darkModeToggle = darkModeSection . locator ( 'button' ) . first ( ) ;
69+ await expect ( darkModeToggle , 'Dark mode toggle should be visible in Settings modal' ) . toBeVisible ( ) ;
6070 await darkModeToggle . click ( ) ;
6171
72+ // Close the modal
73+ const closeButton = settingsModal . getByRole ( 'button' , { name : / c l o s e / i } ) . or (
74+ settingsModal . locator ( '[aria-label="Close"]' )
75+ ) ;
76+ if ( await closeButton . isVisible ( ) ) {
77+ await closeButton . click ( ) ;
78+ } else {
79+ // Press Escape to close modal
80+ await page . keyboard . press ( 'Escape' ) ;
81+ }
82+
83+ // Wait for modal to close
84+ await expect ( settingsModal ) . toBeHidden ( { timeout : 3000 } ) ;
85+
6286 // Theme should change
6387 const newTheme = await page . evaluate ( ( ) =>
6488 document . documentElement . getAttribute ( 'data-theme' )
0 commit comments