|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { |
| 3 | + buildScriptGenerationPrompt, |
| 4 | + buildGeneralDemoPrompt, |
| 5 | +} from '../../packages/core/src/generator/prompts.js'; |
| 6 | +import type { ScriptPromptOptions } from '../../packages/core/src/generator/prompts.js'; |
| 7 | + |
| 8 | +const BASE_OPTIONS: ScriptPromptOptions = { |
| 9 | + baseUrl: 'http://localhost:3000', |
| 10 | + diff: 'diff --git a/src/Button.tsx b/src/Button.tsx\n+export function Button() {}', |
| 11 | + routes: [{ route: '/', file: 'src/Button.tsx' }], |
| 12 | + demoFlow: 'Navigate to home and click the button', |
| 13 | + maxDuration: 30, |
| 14 | + viewport: { width: 1280, height: 720 }, |
| 15 | +}; |
| 16 | + |
| 17 | +describe('buildScriptGenerationPrompt', () => { |
| 18 | + it('includes hint under App-specific notes when provided', () => { |
| 19 | + const prompt = buildScriptGenerationPrompt({ |
| 20 | + ...BASE_OPTIONS, |
| 21 | + hint: 'Log in with demo@example.com / password', |
| 22 | + }); |
| 23 | + expect(prompt).toContain('## App-specific notes'); |
| 24 | + expect(prompt).toContain('Log in with demo@example.com / password'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('omits App-specific notes section when hint is not provided', () => { |
| 28 | + const prompt = buildScriptGenerationPrompt(BASE_OPTIONS); |
| 29 | + expect(prompt).not.toContain('## App-specific notes'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('omits App-specific notes section when hint is empty string', () => { |
| 33 | + const prompt = buildScriptGenerationPrompt({ ...BASE_OPTIONS, hint: '' }); |
| 34 | + expect(prompt).not.toContain('## App-specific notes'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('places hint before the Diff section', () => { |
| 38 | + const prompt = buildScriptGenerationPrompt({ |
| 39 | + ...BASE_OPTIONS, |
| 40 | + hint: 'my hint', |
| 41 | + }); |
| 42 | + const hintPos = prompt.indexOf('## App-specific notes'); |
| 43 | + const diffPos = prompt.indexOf('## Diff'); |
| 44 | + expect(hintPos).toBeGreaterThan(-1); |
| 45 | + expect(hintPos).toBeLessThan(diffPos); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +describe('buildGeneralDemoPrompt', () => { |
| 50 | + const BASE_GENERAL = { |
| 51 | + baseUrl: 'http://localhost:3000', |
| 52 | + maxDuration: 30, |
| 53 | + viewport: { width: 1280, height: 720 }, |
| 54 | + }; |
| 55 | + |
| 56 | + it('includes hint under App-specific notes when provided', () => { |
| 57 | + const prompt = buildGeneralDemoPrompt({ |
| 58 | + ...BASE_GENERAL, |
| 59 | + hint: 'Use test account admin / secret', |
| 60 | + }); |
| 61 | + expect(prompt).toContain('## App-specific notes'); |
| 62 | + expect(prompt).toContain('Use test account admin / secret'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('omits App-specific notes section when hint is not provided', () => { |
| 66 | + const prompt = buildGeneralDemoPrompt(BASE_GENERAL); |
| 67 | + expect(prompt).not.toContain('## App-specific notes'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('omits App-specific notes section when hint is empty string', () => { |
| 71 | + const prompt = buildGeneralDemoPrompt({ ...BASE_GENERAL, hint: '' }); |
| 72 | + expect(prompt).not.toContain('## App-specific notes'); |
| 73 | + }); |
| 74 | +}); |
0 commit comments