import { Feature, Scenario } from "../App"; import { generateFeatureFile } from "../utils/export"; import { downloadFile } from "../utils/download"; import { KEYWORDS } from "../utils/keywords"; interface BddCodePanelProps { feature: Feature | null; selectedScenario: Scenario | null; // Keep for potential future use (e.g., highlighting) } function BddCodePanel({ feature, selectedScenario: _selectedScenario }: BddCodePanelProps) { const generateBddCode = () => { if (!feature) { return ''; } // BUG FIX: Always generate the code for the entire feature, not just the selected scenario. return generateFeatureFile(feature.name, feature.scenarios, feature.language || 'es'); }; const code = generateBddCode(); const handleDownload = () => { if (feature && code) { downloadFile(`${feature.name}.feature`, code); } }; const handleCopy = () => { if (code) { navigator.clipboard.writeText(code).then(() => { alert('Copied to clipboard!'); }); } }; return (

Generated BDD Code (.feature)

{(() => { const lang = feature?.language || 'es'; const kw = KEYWORDS[lang]; const stepStarts = [kw.given, kw.when, kw.then]; return code.split('\n').map((line, index) => { const trimmed = line.trim(); const startsWithStep = stepStarts.some(k => trimmed.startsWith(k)); return (
{line.includes(`${kw.feature}:`) && <>{kw.feature}:{line.substring(line.indexOf(':') + 1)}} {line.includes(`${kw.scenario}:`) && <>{kw.scenario}:{line.substring(line.indexOf(':') + 1)}} {line.includes(`${kw.scenarioOutline}:`) && <>{kw.scenarioOutline}:{line.substring(line.indexOf(':') + 1)}} {line.includes(`${kw.examples}:`) && <>{kw.examples}:{line.substring(line.indexOf(':') + 1)}} {startsWithStep && ( <> {trimmed.split(' ')[0]} {trimmed.substring(trimmed.indexOf(' ') + 1)} )} {trimmed.startsWith('#') && {line}}
); }) })()}
); } export default BddCodePanel;