SPB Git

Repository Public

shot-helpers.ts 2.5 KB 27 lines typescript

1import type { Page } from '@playwright/test';2import { apiLogin, apiPost, demoProjectId, MOCK, resetMock } from './helpers';34export const THEMES = ['light', 'dark'] as const;5export type ShotTheme = (typeof THEMES)[number];67/** Seeds a believable working state in the dev mock (all of it real mock state, nothing drawn by hand). */8export async function seed(page: Page): Promise<{ shell: string; claude: string; pid: string }> {9  await resetMock(page);10  await apiLogin(page);11  const pid = await demoProjectId(page);12  const shell = await apiPost<{ id: string }>(page, '/sessions', { projectId: pid, kind: 'shell', title: 'api server' });13  const claude = await apiPost<{ id: string }>(page, '/sessions', { projectId: pid, kind: 'claude', title: 'refactor parser' });14  await apiPost(page, '/sessions', { projectId: pid, kind: 'shell', title: 'db migrations' });15  await page.request.post(`${MOCK}/__mock/session-state`, { data: { id: claude.id, state: 'WAITING_FOR_INPUT', waitingReason: 'Claude needs your permission to run a command' } });16  await apiPost(page, '/tasks', { projectId: pid, title: 'Unit tests', command: 'echo "42 passed"; exit 0', idempotent: true });17  await apiPost(page, '/tasks', { projectId: pid, title: 'Build release', command: 'for i in 1 2 3 4 5 6 7 8; do echo "compiling module $i"; sleep 20; done' });18  return { shell: shell.id, claude: claude.id, pid };19}20export async function setTheme(page: Page, theme: ShotTheme): Promise<void> {21  await page.addInitScript((t) => localStorage.setItem('cr.theme', t), theme);22}23export const shot = (page: Page, name: string) => page.screenshot({ path: `e2e/screenshots/${name}.png` });24/** Colourful, realistic terminal content: ANSI colours, git-style diff, dim text, box drawing. */25export const DEMO_OUTPUT =26  "clear; printf '\\033[1mGit status\\033[0m\\n \\033[31mM\\033[0m src/util.ts\\n\\033[32m?? untracked.txt\\033[0m\\n\\n\\033[36m@@ -1 +1,2 @@\\033[0m\\n export const add = (a, b) => a + b;\\n\\033[32m+export const sub = (a, b) => a - b;\\033[0m\\n\\033[31m-const unused = 1;\\033[0m\\n\\n\\033[90m╭────────────────────────────────╮\\033[0m\\n\\033[90m│\\033[0m \\033[38;5;208m✻\\033[0m Welcome back                 \\033[90m│\\033[0m\\n\\033[90m│\\033[0m \\033[2mdim helper text\\033[0m \\033[33mwarn\\033[0m \\033[34minfo\\033[0m \\033[35mnote\\033[0m \\033[90m│\\033[0m\\n\\033[90m╰────────────────────────────────╯\\033[0m\\n'; ls\n";27
Files main
Menu

Theme