diff --git a/src/components/UnitTestDesigner.tsx b/src/components/UnitTestDesigner.tsx index 6857755..a121c5f 100644 --- a/src/components/UnitTestDesigner.tsx +++ b/src/components/UnitTestDesigner.tsx @@ -2,16 +2,13 @@ import { useState } from 'react' import { UnitTest, TestCase } 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, Flask, Sparkle } from '@phosphor-icons/react' +import { Plus, Flask } from '@phosphor-icons/react' import { toast } from 'sonner' -import { Badge } from '@/components/ui/badge' +import unitTestDesignerCopy from '@/data/unit-test-designer.json' +import { TestSuiteList } from '@/components/unit-test-designer/TestSuiteList' +import { TestSuiteEditor } from '@/components/unit-test-designer/TestSuiteEditor' +import { TestCasesPanel } from '@/components/unit-test-designer/TestCasesPanel' interface UnitTestDesignerProps { tests: UnitTest[] @@ -25,7 +22,7 @@ export function UnitTestDesigner({ tests, onTestsChange }: UnitTestDesignerProps const handleAddTest = () => { const newTest: UnitTest = { id: `unit-test-${Date.now()}`, - name: 'New Test Suite', + name: unitTestDesignerCopy.defaults.testSuiteName, description: '', testType: 'component', targetFile: '', @@ -53,8 +50,8 @@ export function UnitTestDesigner({ tests, onTestsChange }: UnitTestDesignerProps if (!selectedTest) return const newCase: TestCase = { id: `case-${Date.now()}`, - description: 'should work correctly', - assertions: ['expect(...).toBe(...)'], + description: unitTestDesignerCopy.defaults.testCaseDescription, + assertions: [unitTestDesignerCopy.defaults.assertion], setup: '', teardown: '' } @@ -82,7 +79,7 @@ export function UnitTestDesigner({ tests, onTestsChange }: UnitTestDesignerProps const testCase = selectedTest.testCases.find(c => c.id === caseId) if (!testCase) return handleUpdateTestCase(caseId, { - assertions: [...testCase.assertions, 'expect(...).toBe(...)'] + assertions: [...testCase.assertions, unitTestDesignerCopy.defaults.assertion] }) } @@ -105,289 +102,64 @@ export function UnitTestDesigner({ tests, onTestsChange }: UnitTestDesignerProps } const handleGenerateWithAI = async () => { - const description = prompt('Describe the component/function you want to test:') + const description = prompt(unitTestDesignerCopy.prompts.generateDescription) if (!description) return try { - toast.info('Generating test with AI...') - const promptText = `You are a unit test generator. Create tests based on: "${description}" - -Return a valid JSON object with a single property "test": -{ - "test": { - "id": "unique-id", - "name": "ComponentName/FunctionName Tests", - "description": "Test suite description", - "testType": "component" | "function" | "hook" | "integration", - "targetFile": "/path/to/file.tsx", - "testCases": [ - { - "id": "case-id", - "description": "should render correctly", - "assertions": [ - "expect(screen.getByText('Hello')).toBeInTheDocument()", - "expect(result).toBe(true)" - ], - "setup": "const { getByText } = render()", - "teardown": "cleanup()" - } - ] - } -} - -Create comprehensive test cases with appropriate assertions for React Testing Library or Vitest.` - + toast.info(unitTestDesignerCopy.toasts.generating) + const promptText = unitTestDesignerCopy.prompts.generatePromptTemplate.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 suite generated successfully!') + toast.success(unitTestDesignerCopy.toasts.generateSuccess) } catch (error) { console.error(error) - toast.error('Failed to generate test') + toast.error(unitTestDesignerCopy.toasts.generateError) } } - const getTestTypeColor = (type: string) => { - const colors: Record = { - component: 'bg-blue-500', - function: 'bg-green-500', - hook: 'bg-purple-500', - integration: 'bg-orange-500' - } - return colors[type] || 'bg-gray-500' - } - return (
-
-
-

Test Suites

-
- - -
-
- -
- {tests.map(test => ( -
setSelectedTestId(test.id)} - > -
-
-
-
{test.name}
-
-
{test.targetFile || 'No file'}
-
{test.testCases.length} cases
-
- -
- ))} - {tests.length === 0 && ( -
- No test suites yet. Click + to create one. -
- )} -
- -
+
{selectedTest ? (
-
-

Test Suite Configuration

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