Skip to content

Commit

Permalink
test(playwright): add tests for editor theme selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenltnguyen committed Apr 22, 2024
1 parent 0be289d commit 017580c
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions e2e/editor.spec.ts
Expand Up @@ -28,3 +28,73 @@ test.describe('Editor Component', () => {
await expect(text).toBeVisible();
});
});

test.describe('Editor theme', () => {
test.describe('If the user is signed in', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test('should be in dark mode if the user selected theme is dark', async ({
page
}) => {
await page.getByRole('button', { name: 'Menu' }).click();

const toggle = page.getByRole('button', { name: 'Night Mode' });
const isDarkMode = await toggle.getAttribute('aria-pressed');

if (isDarkMode === 'false') {
const listItem = page.getByRole('listitem').filter({ has: toggle });

// The button's click event is intercepted by the `li`,
// so we need to click on the `li` to trigger the theme change action.
await listItem.click();
}

const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs-dark/);
});

test('should be in light mode if the user selected theme is light', async ({
page
}) => {
await page.getByRole('button', { name: 'Menu' }).click();

const toggle = page.getByRole('button', { name: 'Night Mode' });
const isDarkMode = await toggle.getAttribute('aria-pressed');

if (isDarkMode === 'true') {
const listItem = page.getByRole('listitem').filter({ has: toggle });

// The button's click event is intercepted by the `li`,
// so we need to click on the `li` to trigger the theme change action.
await listItem.click();
}

const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs(?!\w)/);
});
});

test.describe('If the user is signed out and the system theme is dark', () => {
test.use({
storageState: { cookies: [], origins: [] },
colorScheme: 'dark'
});

test('should be in dark mode', async ({ page }) => {
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs-dark/);
});
});

test.describe('If the user is signed out and the system theme is light', () => {
test.use({
storageState: { cookies: [], origins: [] },
colorScheme: 'light'
});

test('should be in light mode', async ({ page }) => {
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs(?!\w)/);
});
});
});

0 comments on commit 017580c

Please sign in to comment.