theme-switcher.spec.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { test, expect } from '@playwright/test';
  2. import Homepage from '@/tests/POM/home-page';
  3. test.beforeEach(async ({ page }) => {
  4. await page.goto('/');
  5. });
  6. test.describe('Theme Switcher', () => {
  7. test('Auto should be selected by default', async ({ page, context }) => {
  8. const homepage = new Homepage(page, context);
  9. // 1. Open the settings drawer
  10. await homepage.openSettingsDrawer();
  11. // 2. get the current active theme
  12. const activeTheme = await page.locator('.ThemeSection_iconActive__Q_xs9 + span').textContent();
  13. expect(activeTheme).toBe('Auto');
  14. });
  15. test('Selecting a non-default theme should change the active theme', async ({
  16. page,
  17. context,
  18. }) => {
  19. let bodyTheme = await page.locator('body').getAttribute('data-theme');
  20. const homepage = new Homepage(page, context);
  21. // 1. Make sure the auto theme is the currently selected theme
  22. expect(bodyTheme).toBe('auto');
  23. // 2. Open the settings drawer
  24. await homepage.openSettingsDrawer();
  25. // 3. Click on the light theme
  26. await page.locator('button:has-text("Light")').click();
  27. // 4. Make sure the light theme is the currently selected theme
  28. bodyTheme = await page.locator('body').getAttribute('data-theme');
  29. expect(bodyTheme).toBe('light');
  30. });
  31. });