|
| 1 | +--- |
| 2 | +description: Create a Cypress-based video demo for a feature branch with cursor, click effects, and captions. |
| 3 | +--- |
| 4 | + |
| 5 | +# /cypress-demo Command |
| 6 | + |
| 7 | +Create a polished Cypress demo test that records a human-paced video walkthrough of UI features on the current branch. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +``` |
| 12 | +/cypress-demo # Auto-detect features from branch diff |
| 13 | +/cypress-demo chat input refactoring # Describe what to demo |
| 14 | +``` |
| 15 | + |
| 16 | +## User Input |
| 17 | + |
| 18 | +```text |
| 19 | +$ARGUMENTS |
| 20 | +``` |
| 21 | + |
| 22 | +## Behavior |
| 23 | + |
| 24 | +When invoked, Claude will create a Cypress test file in `e2e/cypress/e2e/` that records a demo video with: |
| 25 | + |
| 26 | +- **Synthetic cursor** (white dot) that glides smoothly to each interaction target |
| 27 | +- **Click ripple** (blue expanding ring) on every click action |
| 28 | +- **Caption bar** (compact dark bar at top of viewport) describing each step |
| 29 | +- **Human-paced timing** so every action is clearly visible |
| 30 | +- **`--no-runner-ui`** flag to exclude the Cypress sidebar from the recording |
| 31 | + |
| 32 | +### 1. Determine what to demo |
| 33 | + |
| 34 | +- If `$ARGUMENTS` is provided, use it as the demo description |
| 35 | +- If empty, run `git diff main..HEAD --stat` to identify changed files and infer features |
| 36 | +- Read the changed/new component files to understand what UI to showcase |
| 37 | +- Ask the user if clarification is needed on which features to highlight |
| 38 | + |
| 39 | +### 2. Check prerequisites |
| 40 | + |
| 41 | +- Verify `e2e/.env.test` or `e2e/.env` exists with `TEST_TOKEN` |
| 42 | +- Check if `ANTHROPIC_API_KEY` is available (needed if the demo requires Running state for workflows, agents, or commands) |
| 43 | +- Verify the kind cluster is up: `kubectl get pods -n ambient-code` |
| 44 | +- Verify the frontend is accessible: `curl -s -o /dev/null -w "%{http_code}" http://localhost` |
| 45 | +- If the frontend was rebuilt from this branch, verify imagePullPolicy is `Never` or `IfNotPresent` |
| 46 | + |
| 47 | +### 3. Create the demo test file |
| 48 | + |
| 49 | +Create `e2e/cypress/e2e/<feature-name>-demo.cy.ts` using the template structure below. |
| 50 | + |
| 51 | +#### Required helpers (copy into every demo file) |
| 52 | + |
| 53 | +```typescript |
| 54 | +// Timing constants — adjust per demo, aim for ~2 min total video |
| 55 | +const LONG = 3200 // hold on important visuals |
| 56 | +const PAUSE = 2400 // standard pause between actions |
| 57 | +const SHORT = 1600 // brief pause after small actions |
| 58 | +const TYPE_DELAY = 80 // ms per keystroke |
| 59 | + |
| 60 | +// Target first element (session page renders desktop + mobile layout) |
| 61 | +const chatInput = () => cy.get('textarea[placeholder*="message"]').first() |
| 62 | + |
| 63 | +// Caption: compact bar at TOP of viewport |
| 64 | +function caption(text: string) { |
| 65 | + cy.document().then((doc) => { |
| 66 | + let el = doc.getElementById('demo-caption') |
| 67 | + if (!el) { |
| 68 | + el = doc.createElement('div') |
| 69 | + el.id = 'demo-caption' |
| 70 | + el.style.cssText = [ |
| 71 | + 'position:fixed', 'top:0', 'left:0', 'right:0', 'z-index:99998', |
| 72 | + 'background:rgba(0,0,0,0.80)', 'color:#fff', 'font-size:14px', |
| 73 | + 'font-weight:500', 'font-family:system-ui,-apple-system,sans-serif', |
| 74 | + 'padding:6px 20px', 'text-align:center', 'letter-spacing:0.2px', |
| 75 | + 'pointer-events:none', 'transition:opacity 0.4s ease', |
| 76 | + ].join(';') |
| 77 | + doc.body.appendChild(el) |
| 78 | + } |
| 79 | + el.textContent = text |
| 80 | + el.style.opacity = '1' |
| 81 | + }) |
| 82 | +} |
| 83 | + |
| 84 | +function clearCaption() { |
| 85 | + cy.document().then((doc) => { |
| 86 | + const el = doc.getElementById('demo-caption') |
| 87 | + if (el) el.style.opacity = '0' |
| 88 | + }) |
| 89 | +} |
| 90 | + |
| 91 | +// Synthetic cursor + click ripple |
| 92 | +function initCursor() { |
| 93 | + cy.document().then((doc) => { |
| 94 | + if (doc.getElementById('demo-cursor')) return |
| 95 | + const cursor = doc.createElement('div') |
| 96 | + cursor.id = 'demo-cursor' |
| 97 | + cursor.style.cssText = [ |
| 98 | + 'position:fixed', 'z-index:99999', 'pointer-events:none', |
| 99 | + 'width:20px', 'height:20px', 'border-radius:50%', |
| 100 | + 'background:rgba(255,255,255,0.9)', 'border:2px solid #333', |
| 101 | + 'box-shadow:0 0 6px rgba(0,0,0,0.4)', |
| 102 | + 'transform:translate(-50%,-50%)', |
| 103 | + 'transition:left 0.5s cubic-bezier(0.25,0.1,0.25,1), top 0.5s cubic-bezier(0.25,0.1,0.25,1)', |
| 104 | + 'left:-40px', 'top:-40px', |
| 105 | + ].join(';') |
| 106 | + doc.body.appendChild(cursor) |
| 107 | + const ripple = doc.createElement('div') |
| 108 | + ripple.id = 'demo-ripple' |
| 109 | + ripple.style.cssText = [ |
| 110 | + 'position:fixed', 'z-index:99999', 'pointer-events:none', |
| 111 | + 'width:40px', 'height:40px', 'border-radius:50%', |
| 112 | + 'border:3px solid rgba(59,130,246,0.8)', |
| 113 | + 'transform:translate(-50%,-50%) scale(0)', |
| 114 | + 'opacity:0', 'left:-40px', 'top:-40px', |
| 115 | + ].join(';') |
| 116 | + doc.body.appendChild(ripple) |
| 117 | + const style = doc.createElement('style') |
| 118 | + style.textContent = ` |
| 119 | + @keyframes demo-ripple-anim { |
| 120 | + 0% { transform: translate(-50%,-50%) scale(0); opacity: 1; } |
| 121 | + 100% { transform: translate(-50%,-50%) scale(2.5); opacity: 0; } |
| 122 | + } |
| 123 | + ` |
| 124 | + doc.head.appendChild(style) |
| 125 | + }) |
| 126 | +} |
| 127 | + |
| 128 | +// Move cursor smoothly to element center |
| 129 | +function moveTo(selector: string, options?: { first?: boolean }) { |
| 130 | + const chain = options?.first ? cy.get(selector).first() : cy.get(selector) |
| 131 | + chain.then(($el) => { |
| 132 | + const rect = $el[0].getBoundingClientRect() |
| 133 | + cy.document().then((doc) => { |
| 134 | + const cursor = doc.getElementById('demo-cursor') |
| 135 | + if (cursor) { |
| 136 | + cursor.style.left = `${rect.left + rect.width / 2}px` |
| 137 | + cursor.style.top = `${rect.top + rect.height / 2}px` |
| 138 | + } |
| 139 | + }) |
| 140 | + cy.wait(600) |
| 141 | + }) |
| 142 | +} |
| 143 | + |
| 144 | +function moveToText(text: string, tag?: string) { |
| 145 | + const chain = tag ? cy.contains(tag, text) : cy.contains(text) |
| 146 | + chain.then(($el) => { |
| 147 | + const rect = $el[0].getBoundingClientRect() |
| 148 | + cy.document().then((doc) => { |
| 149 | + const cursor = doc.getElementById('demo-cursor') |
| 150 | + if (cursor) { |
| 151 | + cursor.style.left = `${rect.left + rect.width / 2}px` |
| 152 | + cursor.style.top = `${rect.top + rect.height / 2}px` |
| 153 | + } |
| 154 | + }) |
| 155 | + cy.wait(600) |
| 156 | + }) |
| 157 | +} |
| 158 | + |
| 159 | +function moveToEl($el: JQuery<HTMLElement>) { |
| 160 | + const rect = $el[0].getBoundingClientRect() |
| 161 | + cy.document().then((doc) => { |
| 162 | + const cursor = doc.getElementById('demo-cursor') |
| 163 | + if (cursor) { |
| 164 | + cursor.style.left = `${rect.left + rect.width / 2}px` |
| 165 | + cursor.style.top = `${rect.top + rect.height / 2}px` |
| 166 | + } |
| 167 | + }) |
| 168 | + cy.wait(600) |
| 169 | +} |
| 170 | + |
| 171 | +function clickEffect() { |
| 172 | + cy.document().then((doc) => { |
| 173 | + const cursor = doc.getElementById('demo-cursor') |
| 174 | + const ripple = doc.getElementById('demo-ripple') |
| 175 | + if (cursor && ripple) { |
| 176 | + ripple.style.left = cursor.style.left |
| 177 | + ripple.style.top = cursor.style.top |
| 178 | + ripple.style.animation = 'none' |
| 179 | + void ripple.offsetHeight |
| 180 | + ripple.style.animation = 'demo-ripple-anim 0.5s ease-out forwards' |
| 181 | + } |
| 182 | + }) |
| 183 | +} |
| 184 | + |
| 185 | +// Compound: move → ripple → click |
| 186 | +function cursorClickText(text: string, tag?: string, options?: { force?: boolean }) { |
| 187 | + moveToText(text, tag) |
| 188 | + clickEffect() |
| 189 | + const chain = tag ? cy.contains(tag, text) : cy.contains(text) |
| 190 | + chain.click({ force: options?.force }) |
| 191 | +} |
| 192 | +``` |
| 193 | + |
| 194 | +#### Test structure |
| 195 | + |
| 196 | +```typescript |
| 197 | +describe('<Feature> Demo', () => { |
| 198 | + const workspaceName = `demo-${Date.now()}` |
| 199 | + |
| 200 | + // ... helpers above ... |
| 201 | + |
| 202 | + Cypress.on('uncaught:exception', (err) => { |
| 203 | + if (err.message.includes('Minified React error') || err.message.includes('Hydration')) { |
| 204 | + return false |
| 205 | + } |
| 206 | + return true |
| 207 | + }) |
| 208 | + |
| 209 | + after(() => { |
| 210 | + if (!Cypress.env('KEEP_WORKSPACES')) { |
| 211 | + const token = Cypress.env('TEST_TOKEN') |
| 212 | + cy.request({ |
| 213 | + method: 'DELETE', |
| 214 | + url: `/api/projects/${workspaceName}`, |
| 215 | + headers: { Authorization: `Bearer ${token}` }, |
| 216 | + failOnStatusCode: false, |
| 217 | + }) |
| 218 | + } |
| 219 | + }) |
| 220 | + |
| 221 | + it('demonstrates <feature>', () => { |
| 222 | + // ... single continuous test for one video file ... |
| 223 | + }) |
| 224 | +}) |
| 225 | +``` |
| 226 | + |
| 227 | +### 4. Key patterns to follow |
| 228 | + |
| 229 | +| Pattern | Rule | |
| 230 | +|---------|------| |
| 231 | +| **Dual layout** | Session page renders desktop + mobile. Always use `.first()` on element queries that match both | |
| 232 | +| **Caption scoping** | When asserting page content with `cy.contains`, scope to a tag (e.g., `cy.contains('p', 'text')`) to avoid matching the caption overlay | |
| 233 | +| **Workspace setup** | Create workspace → poll `/api/projects/:name` until 200 → configure runner-secrets if API key needed | |
| 234 | +| **Running state** | If demo needs agents/commands, configure `ANTHROPIC_API_KEY` via runner-secrets, select a workflow, and wait for `textarea[placeholder*="attach"]` (Running placeholder) with 180s timeout | |
| 235 | +| **Operator pull policy** | For kind clusters, set `IMAGE_PULL_POLICY=IfNotPresent` on the operator to avoid re-pulling the 879MB runner image every session | |
| 236 | +| **File attachment** | Use `cy.get('input[type="file"]').first().selectFile({...}, { force: true })` with a `Cypress.Buffer` — no real file needed | |
| 237 | +| **Caption position** | Always `top:0` — bottom position obscures the chat toolbar | |
| 238 | +| **Timing** | Aim for ~2 min total. LONG=3.2s, PAUSE=2.4s, SHORT=1.6s, TYPE_DELAY=80ms. Adjust if video feels too fast or slow | |
| 239 | +| **Video output** | `e2e/cypress/videos/<name>.cy.ts.mp4` at 2560x1440 (Retina) | |
| 240 | + |
| 241 | +### 5. Run the demo |
| 242 | + |
| 243 | +```bash |
| 244 | +cd e2e |
| 245 | +npx cypress run --no-runner-ui --spec "cypress/e2e/<name>-demo.cy.ts" |
| 246 | +``` |
| 247 | + |
| 248 | +- Verify the video plays at human-readable speed |
| 249 | +- Check that captions don't overlap important UI elements |
| 250 | +- Re-run and iterate if needed — adjust timing or add/remove steps |
| 251 | + |
| 252 | +### 6. Commit and push |
| 253 | + |
| 254 | +- Commit the demo test file and any config changes (`cypress.config.ts`) |
| 255 | +- Push to the current branch |
| 256 | +- If a PR exists, note the demo in the PR description |
| 257 | + |
| 258 | +## Reference implementation |
| 259 | + |
| 260 | +See `e2e/cypress/e2e/chatbox-demo.cy.ts` for a complete working example that demonstrates: |
| 261 | +- Workspace creation, session creation |
| 262 | +- WelcomeExperience (streaming text, workflow cards) |
| 263 | +- Workflow selection ("Fix a bug") with Running state wait |
| 264 | +- File attachments (AttachmentPreview) |
| 265 | +- Autocomplete popovers (@agents, /commands) with real workflow data |
| 266 | +- Message queueing (QueuedMessageBubble) |
| 267 | +- Message history and queued message editing |
| 268 | +- Settings dropdown |
| 269 | +- Breadcrumb navigation |
| 270 | + |
| 271 | +## Config requirements |
| 272 | + |
| 273 | +`e2e/cypress.config.ts` must load `.env.test` and wire `TEST_TOKEN`: |
| 274 | + |
| 275 | +```typescript |
| 276 | +// Load env files: .env.local > .env > .env.test |
| 277 | +const envFiles = ['.env.local', '.env', '.env.test'].map(f => path.resolve(__dirname, f)) |
| 278 | +for (const envFile of envFiles) { |
| 279 | + if (fs.existsSync(envFile)) { dotenv.config({ path: envFile }) } |
| 280 | +} |
| 281 | + |
| 282 | +// In setupNodeEvents: |
| 283 | +config.env.TEST_TOKEN = process.env.CYPRESS_TEST_TOKEN || process.env.TEST_TOKEN || config.env.TEST_TOKEN || '' |
| 284 | +config.env.ANTHROPIC_API_KEY = process.env.CYPRESS_ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY || '' |
| 285 | +``` |
0 commit comments