diff --git a/src/Api/PendingAwaitablePage.php b/src/Api/PendingAwaitablePage.php index f8aad8d9..d61d8010 100644 --- a/src/Api/PendingAwaitablePage.php +++ b/src/Api/PendingAwaitablePage.php @@ -70,6 +70,17 @@ public function inLightMode(): self ]); } + /** + * Allows you to run all tests in both color modes. + */ + public function inLightAndDarkMode(): ArrayablePendingAwaitablePage + { + return new ArrayablePendingAwaitablePage([ + $this->inLightMode(), + $this->inDarkMode(), + ]); + } + /** * Allows you to set a different locale, timezone, and location for the page. */ diff --git a/tests/Browser/Visit/SingleUrl.php b/tests/Browser/Visit/SingleUrl.php index 0f160719..f4ef48b0 100644 --- a/tests/Browser/Visit/SingleUrl.php +++ b/tests/Browser/Visit/SingleUrl.php @@ -73,6 +73,72 @@ $page->assertScreenshotMatches(); })->with(ColorScheme::cases())->skipOnCI(); +it('may visit a page in both light and dark modes', function (): void { + Route::get('/', fn (): string => ' + + + Example test page + + + +
+

Light and Dark Mode Test

+

This is a test for both light and dark modes.

+
This is only visible in dark mode
+
This is only visible in light mode
+
+ + + '); + + $pages = visit('/') + ->inLightAndDarkMode() + ->assertNoAccessibilityIssues(level: 3); + + $lightModePage = $pages[0]; + $darkModePage = $pages[1]; + + $lightModeColorScheme = $lightModePage->script('window.matchMedia("(prefers-color-scheme: light)").matches'); + $darkModeColorScheme = $darkModePage->script('window.matchMedia("(prefers-color-scheme: dark)").matches'); + + expect($lightModeColorScheme)->toBeTrue() + ->and($darkModeColorScheme)->toBeTrue(); + + $lightModePage->assertSee('This is only visible in light mode') + ->assertDontSee('This is only visible in dark mode'); + $darkModePage->assertSee('This is only visible in dark mode') + ->assertDontSee('This is only visible in light mode'); +}); + it('may visit a page with custom locale and timezone', function (): void { Route::get('/', fn (): string => '