PHP Classes

File: tests/browser/custom-theme.spec.mjs

Recommend this page to a friend!
  Packages of Boss Ibrahim Mussa   Caelrik   tests/browser/custom-theme.spec.mjs   Download  
File: tests/browser/custom-theme.spec.mjs
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Caelrik
Build Web user interface from PHP components
Author: By
Last change:
Date: 8 days ago
Size: 2,184 bytes
 

 

Contents

Class file image Download
import { expect, test } from '@playwright/test'; import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { axeViolations, MODES, openComponents, THEMES } from './helpers.mjs'; // A stylesheet generated by Theme::toCss() (tests/browser/custom-theme.json, a teal palette) // restyles every base theme, in light and dark mode, and stays accessible. const theme = JSON.parse(readFileSync(join(import.meta.dirname, 'custom-theme.json'), 'utf8')); const rgb = (hex) => `rgb(${[1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16)).join(', ')})`; for (const base of THEMES) { for (const mode of MODES) { test.describe(`custom theme on ${base} ${mode}`, () => { test('components take the theme colors', async ({ page }) => { await openComponents(page, { theme: base, mode, custom: true }); const palette = theme[mode]; const style = (selector, property) => page.locator(selector).first() .evaluate((element, name) => getComputedStyle(element)[name], property); expect(await style('body', 'backgroundColor')).toBe(rgb(palette.bodyBg)); expect(await style('body', 'color')).toBe(rgb(palette.bodyColor)); expect(await style('#signup .btn-primary', 'backgroundColor')).toBe(rgb(palette.primary)); expect(await style('#signup .btn-primary', 'color')).toBe(rgb(palette.onPrimary)); expect(await style('#users_wrapper .page-item.active .page-link', 'backgroundColor')).toBe(rgb(palette.primary)); expect(await style('#signup-name', 'borderTopColor')).toBe(rgb(palette.inputBorder)); expect(await style('#signup-email-error', 'color')).toBe(rgb(palette.danger)); // The flat toolbar: the current view is filled with the primary color. expect(await style('#team-calendar .fc-button-active', 'backgroundColor')).toBe(rgb(palette.primary)); expect(await style('#users_wrapper', 'borderTopLeftRadius')).toBe('4px'); // 0.25rem }); test('no axe-core violations', async ({ page }) => { await openComponents(page, { theme: base, mode, custom: true }); expect(await axeViolations(page)).toEqual([]); }); }); } }