|
| 1 | +/** |
| 2 | + * UAT: Create new design end-to-end flow. |
| 3 | + * |
| 4 | + * Uses `testOnboarded` fixture (config pre-seeded with a valid provider). |
| 5 | + * Tests the full create flow: button → dialog → fill name → submit → workspace. |
| 6 | + * |
| 7 | + * If any step fails, we capture a screenshot and report verbatim — we do NOT |
| 8 | + * mask failures with fallbacks. The brief says "surface failures, don't paper |
| 9 | + * over them." |
| 10 | + */ |
| 11 | + |
| 12 | +import * as fs from 'node:fs'; |
| 13 | +import * as path from 'node:path'; |
| 14 | +import { expect, testOnboarded as test } from './fixtures/electron-app'; |
| 15 | + |
| 16 | +const SCREENSHOT_DIR = path.join(__dirname, '../test-results/screenshots'); |
| 17 | + |
| 18 | +function ensureDir(dir: string): void { |
| 19 | + fs.mkdirSync(dir, { recursive: true }); |
| 20 | +} |
| 21 | + |
| 22 | +test('create new design flow', async ({ firstWindow }) => { |
| 23 | + ensureDir(SCREENSHOT_DIR); |
| 24 | + |
| 25 | + // ── Step 1: wait for window.codesign bridge ──────────────────────────────── |
| 26 | + await firstWindow.waitForFunction( |
| 27 | + () => typeof (window as Window & { codesign?: unknown }).codesign !== 'undefined', |
| 28 | + { timeout: 10_000 }, |
| 29 | + ); |
| 30 | + |
| 31 | + // ── Step 2: wait for store to be exposed ────────────────────────────��───── |
| 32 | + await firstWindow.waitForFunction( |
| 33 | + () => |
| 34 | + (window as Window & { __codesign_test_store__?: unknown }).__codesign_test_store__ != null, |
| 35 | + { timeout: 10_000 }, |
| 36 | + ); |
| 37 | + |
| 38 | + // ── Step 3: wait for configHydrated ─────────────────────────────────────── |
| 39 | + await firstWindow.waitForFunction( |
| 40 | + () => { |
| 41 | + const w = window as Window & { |
| 42 | + __codesign_test_store__?: { getState: () => { configHydrated?: boolean } }; |
| 43 | + }; |
| 44 | + return w.__codesign_test_store__?.getState().configHydrated === true; |
| 45 | + }, |
| 46 | + { timeout: 10_000 }, |
| 47 | + ); |
| 48 | + |
| 49 | + // ── Step 4: click the new design button ─────────────────────────────────── |
| 50 | + const newDesignBtn = firstWindow.getByTestId('sidebar-button-new-design'); |
| 51 | + await expect(newDesignBtn).toBeVisible({ timeout: 8_000 }); |
| 52 | + await newDesignBtn.click(); |
| 53 | + |
| 54 | + // ── Step 5: wait for dialog ─────────────────────────────────────────────── |
| 55 | + const dialog = firstWindow.getByTestId('new-design-dialog'); |
| 56 | + await expect(dialog).toBeVisible({ timeout: 8_000 }); |
| 57 | + |
| 58 | + // ── Step 6: screenshot dialog open ─────────────────────────────────────── |
| 59 | + await firstWindow.screenshot({ |
| 60 | + path: path.join(SCREENSHOT_DIR, 'create-design-dialog-open.png'), |
| 61 | + }); |
| 62 | + |
| 63 | + // ── Step 7: fill name ───────────────────────────────────────────────────── |
| 64 | + const nameInput = firstWindow.getByTestId('new-design-dialog-input-name'); |
| 65 | + await nameInput.fill('E2E Smoke Design'); |
| 66 | + |
| 67 | + // ── Step 8: screenshot filled ───────────────────────────────────────────── |
| 68 | + await firstWindow.screenshot({ |
| 69 | + path: path.join(SCREENSHOT_DIR, 'create-design-dialog-filled.png'), |
| 70 | + }); |
| 71 | + |
| 72 | + // ── Step 9: click submit ────────────────────────────────────────────────── |
| 73 | + const submitBtn = firstWindow.getByTestId('new-design-dialog-button-submit'); |
| 74 | + await submitBtn.click(); |
| 75 | + |
| 76 | + // ── Step 10: wait for dialog to be hidden ──────────────────────────────── |
| 77 | + await expect(dialog).toBeHidden({ timeout: 10_000 }); |
| 78 | + |
| 79 | + // ── Step 11: wait for workspace view ────────────────────────────────────── |
| 80 | + // workspace-view div is hidden={view !== 'workspace'}, so wait for it to |
| 81 | + // become visible (the hidden attr gets removed when view switches). |
| 82 | + const workspaceView = firstWindow.getByTestId('workspace-view'); |
| 83 | + await expect(workspaceView).toBeVisible({ timeout: 15_000 }); |
| 84 | + |
| 85 | + // ── Step 12: assert currentDesignId ─────────────────────────────────────── |
| 86 | + const currentDesignId = await firstWindow.evaluate(() => { |
| 87 | + const w = window as Window & { |
| 88 | + __codesign_test_store__?: { getState: () => { currentDesignId?: string } }; |
| 89 | + }; |
| 90 | + return w.__codesign_test_store__?.getState().currentDesignId ?? null; |
| 91 | + }); |
| 92 | + expect(typeof currentDesignId).toBe('string'); |
| 93 | + expect(currentDesignId).not.toBe(''); |
| 94 | + expect(currentDesignId).not.toBeNull(); |
| 95 | + |
| 96 | + // ── Step 13: assert design name in store ────────────────────────────────── |
| 97 | + const foundInStore = await firstWindow.evaluate(() => { |
| 98 | + const w = window as Window & { |
| 99 | + __codesign_test_store__?: { getState: () => { designs?: Array<{ name: string }> } }; |
| 100 | + }; |
| 101 | + const designs = w.__codesign_test_store__?.getState().designs ?? []; |
| 102 | + return designs.some((d) => d.name === 'E2E Smoke Design'); |
| 103 | + }); |
| 104 | + expect(foundInStore).toBe(true); |
| 105 | + |
| 106 | + // ── Step 14: screenshot workspace ───────────────────────────────────────── |
| 107 | + await firstWindow.screenshot({ |
| 108 | + path: path.join(SCREENSHOT_DIR, 'create-design-workspace.png'), |
| 109 | + }); |
| 110 | + |
| 111 | + // ── Step 15: assert design visible in sidebar list ──────────────────────── |
| 112 | + const sidebarItem = firstWindow.getByTestId(`design-list-item-${currentDesignId}`); |
| 113 | + await expect(sidebarItem).toBeVisible({ timeout: 5_000 }); |
| 114 | + |
| 115 | + // ── Step 16: screenshot sidebar ─────────────────────────────────────────── |
| 116 | + await firstWindow.screenshot({ |
| 117 | + path: path.join(SCREENSHOT_DIR, 'create-design-in-sidebar.png'), |
| 118 | + }); |
| 119 | +}); |
0 commit comments