From 43b3d29146b46b85cdbb0fdfec149165e63920c5 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sun, 18 Jan 2026 00:27:18 +0000 Subject: [PATCH] Refactor Playwright designer components --- src/components/PlaywrightDesigner.tsx | 275 +++--------------- .../playwright-designer/StepEditor.tsx | 103 +++++++ .../playwright-designer/TestEditor.tsx | 107 +++++++ .../playwright-designer/TestList.tsx | 76 +++++ src/data/playwright-designer.json | 65 +++++ 5 files changed, 384 insertions(+), 242 deletions(-) create mode 100644 src/components/playwright-designer/StepEditor.tsx create mode 100644 src/components/playwright-designer/TestEditor.tsx create mode 100644 src/components/playwright-designer/TestList.tsx create mode 100644 src/data/playwright-designer.json diff --git a/src/components/PlaywrightDesigner.tsx b/src/components/PlaywrightDesigner.tsx index 0037413..7e223de 100644 --- a/src/components/PlaywrightDesigner.tsx +++ b/src/components/PlaywrightDesigner.tsx @@ -2,15 +2,12 @@ import { useState } from 'react' import { PlaywrightTest, PlaywrightStep } from '@/types/project' -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' -import { Input } from '@/components/ui/input' -import { Label } from '@/components/ui/label' -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' -import { ScrollArea } from '@/components/ui/scroll-area' -import { Textarea } from '@/components/ui/textarea' -import { Plus, Trash, Play, Sparkle } from '@phosphor-icons/react' +import { Play, Plus } from '@phosphor-icons/react' import { toast } from 'sonner' +import copy from '@/data/playwright-designer.json' +import { TestList } from '@/components/playwright-designer/TestList' +import { TestEditor } from '@/components/playwright-designer/TestEditor' interface PlaywrightDesignerProps { tests: PlaywrightTest[] @@ -24,7 +21,7 @@ export function PlaywrightDesigner({ tests, onTestsChange }: PlaywrightDesignerP const handleAddTest = () => { const newTest: PlaywrightTest = { id: `test-${Date.now()}`, - name: 'New Test', + name: copy.defaults.newTestName, description: '', pageUrl: '/', steps: [] @@ -34,17 +31,15 @@ export function PlaywrightDesigner({ tests, onTestsChange }: PlaywrightDesignerP } const handleDeleteTest = (testId: string) => { - onTestsChange(tests.filter(t => t.id !== testId)) + const remaining = tests.filter(test => test.id !== testId) + onTestsChange(remaining) if (selectedTestId === testId) { - const remaining = tests.filter(t => t.id !== testId) setSelectedTestId(remaining[0]?.id || null) } } const handleUpdateTest = (testId: string, updates: Partial) => { - onTestsChange( - tests.map(t => t.id === testId ? { ...t, ...updates } : t) - ) + onTestsChange(tests.map(test => (test.id === testId ? { ...test, ...updates } : test))) } const handleAddStep = () => { @@ -63,270 +58,66 @@ export function PlaywrightDesigner({ tests, onTestsChange }: PlaywrightDesignerP const handleUpdateStep = (stepId: string, updates: Partial) => { if (!selectedTest) return handleUpdateTest(selectedTest.id, { - steps: selectedTest.steps.map(s => s.id === stepId ? { ...s, ...updates } : s) + steps: selectedTest.steps.map(step => (step.id === stepId ? { ...step, ...updates } : step)) }) } const handleDeleteStep = (stepId: string) => { if (!selectedTest) return handleUpdateTest(selectedTest.id, { - steps: selectedTest.steps.filter(s => s.id !== stepId) + steps: selectedTest.steps.filter(step => step.id !== stepId) }) } const handleGenerateWithAI = async () => { - const description = prompt('Describe the E2E test you want to generate:') + const description = prompt(copy.prompts.describeTest) if (!description) return try { - toast.info('Generating test with AI...') - const promptText = `You are a Playwright test generator. Create an E2E test based on: "${description}" - -Return a valid JSON object with a single property "test": -{ - "test": { - "id": "unique-id", - "name": "Test Name", - "description": "What this test does", - "pageUrl": "/path", - "steps": [ - { - "id": "step-id", - "action": "navigate" | "click" | "fill" | "expect" | "wait" | "select" | "check" | "uncheck", - "selector": "css selector or text", - "value": "value for fill/select actions", - "assertion": "expected value for expect action", - "timeout": 5000 - } - ] - } -} - -Create a complete test flow with appropriate selectors and assertions.` - + toast.info(copy.messages.generating) + const promptText = copy.prompts.template.replace('{description}', description) const response = await window.spark.llm(promptText, 'gpt-4o', true) const parsed = JSON.parse(response) onTestsChange([...tests, parsed.test]) setSelectedTestId(parsed.test.id) - toast.success('Test generated successfully!') + toast.success(copy.messages.generated) } catch (error) { console.error(error) - toast.error('Failed to generate test') + toast.error(copy.messages.failed) } } return (
-
-
-

E2E Tests

-
- - -
-
- -
- {tests.map(test => ( -
setSelectedTestId(test.id)} - > -
-
{test.name}
-
{test.pageUrl}
-
{test.steps.length} steps
-
- -
- ))} - {tests.length === 0 && ( -
- No tests yet. Click + to create one. -
- )} -
-
-
+
{selectedTest ? ( -
-
-

Test Configuration

- -
- - - - Test Details - - -
- - handleUpdateTest(selectedTest.id, { name: e.target.value })} - /> -
-
- -