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
4 changes: 4 additions & 0 deletions .changeset/theme-toggle-followup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

test(e2e): name the theme navigation test for what it checks, fix tooltip test indentation, add a page-object html locator
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BaseComponent } from '../base.component';
export class ThemeToggleComponent extends BaseComponent {
readonly button = this.page.getByTestId('theme-toggle');
readonly tooltip = this.page.getByTestId('theme-toggle-tooltip');
readonly html = this.page.locator('html');

async toggle(): Promise<void> {
await this.button.click();
Expand Down
48 changes: 23 additions & 25 deletions packages/bruno-api-docs/e2e/tests/theming/theme-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,75 @@ test.describe('Theme switcher', () => {
await page.goto('/');
});

test('starts in light mode, with the toggle offering "Switch to dark theme"', async ({ page, themeToggle }) => {
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
test('starts in light mode, with the toggle offering "Switch to dark theme"', async ({ themeToggle }) => {
await expect(themeToggle.html).toHaveAttribute('data-theme', 'light');
await expect(themeToggle.button).toHaveAccessibleName('Switch to dark theme');
});

test('names the action in a tooltip on hover', async ({ themeToggle }) => {
await themeToggle.button.hover();
test('names the action in a tooltip on hover', async ({ themeToggle }) => {
await themeToggle.button.hover();

await expect(themeToggle.tooltip).toHaveText('Switch to dark theme');
});
await expect(themeToggle.tooltip).toHaveText('Switch to dark theme');
});

test('switches the whole app to dark mode when the toggle is clicked', async ({ page, themeToggle }) => {
await themeToggle.toggle();
test('switches the whole app to dark mode when the toggle is clicked', async ({ themeToggle }) => {
await themeToggle.toggle();

await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');

await expect(themeToggle.button).toHaveAccessibleName('Switch to light theme');
});

test('switches back to light mode when the toggle is clicked again', async ({ page, themeToggle }) => {
test('switches back to light mode when the toggle is clicked again', async ({ themeToggle }) => {
await themeToggle.toggle();
await themeToggle.toggle();

await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'light');
});

test('remembers the chosen theme across a page reload', async ({ page, themeToggle }) => {
await themeToggle.toggle();
await page.reload();

await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');
});

test('remembers the chosen theme across Overview, Environments, and a request', async ({
page,
test('keeps the chosen theme while moving between Overview, Environments, and a request', async ({
sidebar,
themeToggle,
overviewPage,
environmentsPage,
requestPage
}) => {
await themeToggle.toggle();
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');

await sidebar.overview.click();
await expect(overviewPage.root).toBeVisible();
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');

await sidebar.environments.click();
await expect(environmentsPage.root).toBeVisible();
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');

await sidebar.open(['echo json']);
await expect(requestPage.root).toBeVisible();
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.button).toHaveAccessibleName('Switch to light theme');
});

test('remembers the chosen theme when the doc is opened in a new tab', async ({
page,
context,
themeToggle
}) => {
await themeToggle.toggle();
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');

const reopened = await context.newPage();
await reopened.goto('/');
const reopenedToggle = new ThemeToggleComponent(reopened);

await expect(reopened.locator('html')).toHaveAttribute('data-theme', 'dark');
await expect(reopenedToggle.html).toHaveAttribute('data-theme', 'dark');
await expect(reopenedToggle.button).toHaveAccessibleName('Switch to light theme');
});
});
Expand All @@ -94,18 +92,18 @@ test.describe('Theme switcher', () => {
await page.goto('/');
});

test('starts in dark mode, with the toggle offering "Switch to light theme"', async ({ page, themeToggle }) => {
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
test('starts in dark mode, with the toggle offering "Switch to light theme"', async ({ themeToggle }) => {
await expect(themeToggle.html).toHaveAttribute('data-theme', 'dark');
await expect(themeToggle.button).toHaveAccessibleName('Switch to light theme');
});

test('keeps an explicit light choice after reload, even though the OS prefers dark', async ({ page, themeToggle }) => {
await themeToggle.toggle();
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'light');

await page.reload();

await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
await expect(themeToggle.html).toHaveAttribute('data-theme', 'light');
await expect(themeToggle.button).toHaveAccessibleName('Switch to dark theme');
});
});
Expand Down
Loading