Files
yellowjacket/frontend/test/stores/theme-store.test.ts
T
logan 5ca6cad45a
Build & publish Arch package / arch-package (push) Successful in 2m8s
CI / check (push) Failing after 1m56s
CI / e2e (push) Skipped
Search index maintenance / maintain-index (push) Successful in 13s
feat(harness): agent-drivable dev harness and CI that gates
A coding agent could develop this repo's Go packages and could not
develop the application: every path to running YellowJacket ended in a
blocking GTK window, so 265 bound methods, 46 events, 33 component
directories and 13 stores had exactly one form of verification
available — `tsc --noEmit`.

The unlock is that `wails dev`'s dev server on :34115 serves the real
frontend with the real generated bindings against the same Go backend a
desktop window attaches to, so a plain Chromium under Xvfb gets a fully
functional app. Four test tiers now exist, cheapest first:

- `make ui-test` — 313 Vitest tests in a real browser in ~2 s, no app,
  no backend, no display. Works because `frontend/wailsjs/` is a pure
  passthrough to `window.go`/`window.runtime`, so faking just those two
  globals runs the real bindings and the real store code.
- `make test` — services in-process, asserting on the payload the
  frontend would receive, via a new `events.Emit` wrapper.
- `make dev-headless` + `playwright-cli` — the real app, driven
  interactively, with an event bridge on `window.__yjEvents` and a
  dev-only control surface at `/__test/`.
- `make e2e` — 19 of those flows frozen as Playwright specs.

`events.Emit(ctx, …)` replaces all 35 direct `runtime.EventsEmit` call
sites: wails' `getEvents` `log.Fatalf`s on any context without its
runtime, so those paths could not run under test and a background
worker could take the app down. Four packages had each hand-rolled the
same guard; nine more guarded on `ctx != nil`, which does not help.
`TestNoDirectRuntimeEmits` fails the build on a new one.

Fixtures are generated, not committed (`make testdata`), and seeds are
built by *running the app* — never by hand-writing config and DB rows,
which would be a second description of a valid YJ_HOME.

`.gitea/workflows/ci.yml` is the first workflow here that tests
anything; the other three only package, so `gitea_ci` reported only
packaging jobs and misled anyone asking whether a push was healthy.
Both jobs were prototyped to green in a bare ubuntu:24.04 container
before the YAML was written, which immediately caught `make lint`
linting three configurations that nothing builds: all three passes
omitted `webkit2_41`, so wails resolved webkit2gtk-4.0 — which Arch
still ships and Ubuntu 24.04 dropped.

Operational instructions live in `.pi/skills/yellowjacket-dev/`,
measured discoveries in `.planning/NOTES.md`, and architecture in
`CLAUDE.md` — split by tense, not by topic, because a topical split
gives every new fact two plausible homes. `make skill-check` fails a
commit if the skill cites a make target that does not exist.
2026-08-10 23:20:42 -04:00

148 lines
4.3 KiB
TypeScript

/**
* The theme store is the only store that writes to the document: it
* derives a whole custom-property ramp from two settings and applies it
* to :root, where every shadow root inherits it. Asserting on the
* computed values of the real document is the point of running in a
* browser at all.
*/
import { describe, expect, it, beforeEach } from 'vitest';
import { themeStore } from '@store/theme-store';
import { Events } from '../../src/events';
import { emit, lastArgs } from '@test/support/harness';
/** Push a theme, as the backend's config change event does. */
function applyTheme(AccentColor: string, BackgroundShade: string): void {
emit(Events.ThemeConfigChanged, { AccentColor, BackgroundShade });
}
function cssVar(name: string): string {
return document.documentElement.style.getPropertyValue(name).trim();
}
describe('theme store: derived variables', () => {
beforeEach(() => {
applyTheme('#ffd43b', 'dark');
});
it('caches the pushed theme', () => {
expect(themeStore.getState()).toEqual({
accentColor: '#ffd43b',
backgroundShade: 'dark',
});
});
it('sets the accent verbatim', () => {
expect(cssVar('--yj-accent')).toBe('#ffd43b');
});
it('derives a lighter hover accent and a darker muted one', () => {
expect([cssVar('--yj-accent-hover'), cssVar('--yj-accent-muted')]).toEqual([
'#ffda58',
'#806a1e',
]);
});
it('derives translucent accent backgrounds as rgba, for layering', () => {
expect(cssVar('--yj-accent-bg')).toBe('rgba(255, 212, 59, 0.1)');
});
it('expands a three-digit hex before deriving from it', () => {
applyTheme('#fff', 'dark');
expect(cssVar('--yj-accent-hover')).toBe('#ffffff');
});
it('swaps the whole background ramp with the shade', () => {
applyTheme('#ffd43b', 'darker');
const darker = cssVar('--yj-bg-surface');
applyTheme('#ffd43b', 'light');
expect([darker, cssVar('--yj-bg-surface')]).toEqual(['#121212', '#f8f9fa']);
});
it('keeps semantic colours fixed across shades', () => {
const dark = cssVar('--yj-error');
applyTheme('#ffd43b', 'light');
expect([dark, cssVar('--yj-error')]).toEqual(['#e03131', '#e03131']);
});
});
describe('theme store: document integration', () => {
it('flags dark shades to Web Awesome, which otherwise renders white surfaces', () => {
applyTheme('#ffd43b', 'dark');
const darkFlagged = document.documentElement.classList.contains('wa-dark');
applyTheme('#ffd43b', 'light');
expect([
darkFlagged,
document.documentElement.classList.contains('wa-dark'),
]).toEqual([true, false]);
});
it('sets color-scheme so native controls and scrollbars match', () => {
applyTheme('#ffd43b', 'light');
const light = document.documentElement.style.colorScheme;
applyTheme('#ffd43b', 'darker');
expect([light, document.documentElement.style.colorScheme]).toEqual([
'light',
'dark',
]);
});
it('bridges the surface ramp onto Web Awesome custom properties', () => {
applyTheme('#ffd43b', 'darker');
expect([
cssVar('--wa-color-surface-default'),
cssVar('--wa-color-surface-raised'),
cssVar('--wa-color-surface-lowered'),
]).toEqual(['#000000', '#121212', '#1e1e1e']);
});
it('is inherited through a shadow root', () => {
applyTheme('#ff0000', 'dark');
const host = document.createElement('div');
const root = host.attachShadow({ mode: 'open' });
const inner = document.createElement('span');
inner.style.color = 'var(--yj-accent)';
root.append(inner);
document.body.append(host);
const colour = getComputedStyle(inner).color;
host.remove();
expect(colour).toBe('rgb(255, 0, 0)');
});
});
describe('theme store: writes', () => {
it('sends a new accent to the backend rather than applying it locally', async () => {
applyTheme('#ffd43b', 'dark');
await themeStore.setAccentColor('#00ff00');
// The backend is the writer; the store waits for ThemeConfigChanged.
expect([
lastArgs('config.Config.SetThemeAccentColor'),
themeStore.getState().accentColor,
]).toEqual([['#00ff00'], '#ffd43b']);
});
it('sends a new shade to the backend', async () => {
await themeStore.setBackgroundShade('light');
expect(lastArgs('config.Config.SetThemeBackgroundShade')).toEqual([
'light',
]);
});
});