Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/Api/PendingAwaitablePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
66 changes: 66 additions & 0 deletions tests/Browser/Visit/SingleUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '
<html lang="en">
<head>
<title>Example test page</title>
<style>
body {
font-family: sans-serif;
padding: 2rem;
}
.text-red-500 {
color: #fb2c36;
}
.text-red-600 {
color: #e7000b;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #121212;
color: #f1f1f1;
}
.light {
display: none;
}
}
@media (prefers-color-scheme: light) {
body {
background-color: #ffffff;
color: #000000;
}
.dark {
display: none;
}
}
</style>
</head>
<body>
<main>
<h1>Light and Dark Mode Test</h1>
<p>This is a test for both light and dark modes.</p>
<div class="dark text-red-500">This is only visible in dark mode</div>
<div class="light text-red-600">This is only visible in light mode</div>
</main>
</body>
</html>
');

$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 => '
<html>
Expand Down