import { useState, useMemo } from 'react'; import { Feature } from "../App"; import Sidebar from '../components/Sidebar'; interface FeaturesPageProps { features: Feature[]; onCreateFeature: (name: string, language: 'es' | 'en') => void; onNavigateToEditor: (featureId: string) => void; onDeleteFeature: (featureId: string) => void; } // --- Utility function to sanitize file names --- const sanitizeFileName = (name: string) => { return name .toString() .normalize('NFD') // Decompose accented letters into letter + accent .replace(/[\u0300-\u036f]/g, '') // Remove the accent characters .toLowerCase() .replace(/\s+/g, '_') // Replace spaces with underscores .replace(/[^a-z0-9_]/g, ''); // Remove all non-alphanumeric characters except underscores }; function FeaturesPage({ features, onCreateFeature, onNavigateToEditor, onDeleteFeature }: FeaturesPageProps) { const [newFeatureName, setNewFeatureName] = useState(''); const [language, setLanguage] = useState<'es' | 'en'>('es'); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (newFeatureName.trim()) { const sanitizedName = sanitizeFileName(newFeatureName); if (sanitizedName) { onCreateFeature(sanitizedName, language); setNewFeatureName(''); } else { alert('Please enter a valid feature name.'); } } }; const handleDeleteClick = (e: React.MouseEvent, featureId: string) => { e.stopPropagation(); if (window.confirm('Are you sure you want to delete this feature and all its scenarios?')) { onDeleteFeature(featureId); } }; const featuresCount = features.length; const scenariosCount = useMemo(() => features.reduce((acc, f) => acc + (f.scenarios?.length || 0), 0), [features]); return (

Gherkins Build

Design and generate .feature test cases visually

Create a New Feature

Define a new feature to begin creating test cases.

setNewFeatureName(e.target.value)} />

Spaces and special characters will be automatically converted.

Existing Features

Or select an existing feature to continue working.

{features.length > 0 ? features.map(feature => (
onNavigateToEditor(feature.id)} className="group flex items-center justify-between p-4 bg-card-light dark:bg-card-dark rounded-lg border border-border-light dark:border-border-dark hover:border-primary dark:hover:border-primary transition-all cursor-pointer"> {feature.name}.feature
{feature.scenarios.length} scenarios
)) : (

No features found. Create one to get started!

)}
); } export default FeaturesPage;