mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
refactor(theme): share one base theme between backoffice and portal
The two apps had drifted into unrelated themes. The portal's carried a full type scale, radius scale, shadow ramp and component defaults; the backoffice's had none of them — 55 lines defining two colour ramps and little else. With nothing to inherit, its 23 features each invented their own sizing, which is the real source of the inconsistency the UI reads with. Promote the portal's structure to `libs/shared` as `baseTheme`, and reduce both themes to what they should differ on: brand. The backoffice keeps #1e40af and the portal keeps Coastal Modern — a distinct accent tells an officer which of the two systems they are in, and the ramps are not interchangeable in contrast. Both export names are preserved, so no consumer import changes. Two properties are deliberately held back rather than shared: - `colors.gray`: the portal's blue-tinted neutrals retint every dimmed label, neutral badge and table border. The backoffice adopts them as its own reviewed change, not as a side effect of sharing a base. - `primaryShade.dark`: moves every filled control in dark mode; waits until dark mode is verified end to end. Also fixes a live bug: PageLoader coloured its primary label `navy.9`, which is defined in neither theme. Mantine drops unresolved colour keys silently, so the label in a component used by 20 files had been rendering an inherited colour. Adds a visual-regression harness to make all of this reviewable. It runs against a static gallery route rather than real pages, so it needs no API, database or auth — a theme diff cannot be masked by a migration or an expired token. The portal is the control group: it is pixel-identical across all four light/dark × desktop/tablet baselines, which is what makes the refactor provably lossless. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
61
apps/e2e/visual/theme.spec.ts
Normal file
61
apps/e2e/visual/theme.spec.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { test, expect, type Page } from '@playwright/test';
|
||||
import { VISUAL } from '../visual.config';
|
||||
|
||||
/**
|
||||
* Theme baselines.
|
||||
*
|
||||
* These exist so a change to the shared theme can be reviewed as a diff rather
|
||||
* than trusted. The gallery route renders every primitive the theme controls,
|
||||
* so one screenshot per app per scheme per width covers the whole surface.
|
||||
*
|
||||
* Update baselines deliberately, never reflexively:
|
||||
* npx playwright test -c apps/e2e/visual.config.ts --update-snapshots
|
||||
* A diff you did not intend is the entire point of the suite.
|
||||
*/
|
||||
|
||||
const WIDTHS = [
|
||||
{ name: 'desktop', width: 1440, height: 1200 },
|
||||
{ name: 'tablet', width: 768, height: 1200 },
|
||||
] as const;
|
||||
|
||||
const SCHEMES = ['light', 'dark'] as const;
|
||||
|
||||
const APPS = [
|
||||
{ name: 'backoffice', url: VISUAL.backofficeUrl },
|
||||
{ name: 'portal', url: VISUAL.portalUrl },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Set the scheme the way the app itself does — the pre-paint script in
|
||||
* index.html reads this key. Setting it before navigation means the very first
|
||||
* paint is already correct, so no screenshot catches a flash of the wrong one.
|
||||
*/
|
||||
async function gotoGallery(page: Page, baseUrl: string, scheme: string) {
|
||||
await page.addInitScript((value) => {
|
||||
window.localStorage.setItem('mantine-color-scheme-value', value);
|
||||
}, scheme);
|
||||
|
||||
await page.goto(`${baseUrl}/__gallery`, { waitUntil: 'networkidle' });
|
||||
|
||||
// The gallery is static, but web fonts are not: screenshotting before they
|
||||
// settle bakes a fallback-font baseline that every later run then fails
|
||||
// against.
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
await expect(page.getByRole('heading', { name: 'Theme Gallery' })).toBeVisible();
|
||||
}
|
||||
|
||||
for (const app of APPS) {
|
||||
for (const scheme of SCHEMES) {
|
||||
for (const size of WIDTHS) {
|
||||
test(`${app.name} gallery — ${scheme} — ${size.name}`, async ({ page }) => {
|
||||
await page.setViewportSize({ width: size.width, height: size.height });
|
||||
await gotoGallery(page, app.url, scheme);
|
||||
|
||||
await expect(page).toHaveScreenshot(
|
||||
`${app.name}-gallery-${scheme}-${size.name}.png`,
|
||||
{ fullPage: true },
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user