#!/usr/bin/env tsx /** * Test script to verify Block Tester duplicate titles and warnings are fixed */ import * as fs from 'fs'; import * as path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const BLOCK_TESTER_LAYOUT = path.join(__dirname, '../src/renderer/components/tools/block-tester/BlockTesterLayout.tsx'); const BLOCK_EDITOR = path.join(__dirname, '../src/renderer/components/tools/block-tester/editors/BlockEditor.tsx'); function checkFile(filePath: string, fileName: string): { hasDuplicates: boolean; issues: string[] } { const content = fs.readFileSync(filePath, 'utf-8'); const lines = content.split('\n'); const issues: string[] = []; if (fileName === 'BlockTesterLayout.tsx') { lines.forEach((line, index) => { if (line.includes('>Block Editor<') || line.includes('"Block Editor"')) { issues.push(`Line ${index + 1}: Found "Block Editor" title that should be removed`); } }); const editorPanelStart = lines.findIndex(line => line.includes('const EditorPanel')); if (editorPanelStart !== -1) { const editorPanelEnd = lines.findIndex((line, idx) => idx > editorPanelStart && line.match(/^const \w+/)); const editorPanelContent = lines.slice(editorPanelStart, editorPanelEnd).join('\n'); if (editorPanelContent.includes('validateBlock()')) { issues.push(`EditorPanel: Found validateBlock() call that causes duplicate validation`); } if (editorPanelContent.includes('warnings.length') && editorPanelContent.includes('Badge')) { issues.push(`EditorPanel: Found validation badges display that duplicates BlockEditor`); } } } if (fileName === 'BlockEditor.tsx') { if (content.includes('const validation = validateBlock(')) { issues.push(`BlockEditor: Still computing validation independently instead of using props`); } if (!content.includes('validation?:') && !content.includes('validation:')) { issues.push(`BlockEditor: Missing validation prop in interface`); } if (content.includes('Badge') && content.includes('validation.warnings.length')) { issues.push(`BlockEditor: Still displaying validation badges that duplicate parent`); } } return { hasDuplicates: issues.length > 0, issues }; } console.log('šŸ” Testing Block Tester Duplicate Fixes...\n'); const layoutResult = checkFile(BLOCK_TESTER_LAYOUT, 'BlockTesterLayout.tsx'); if (layoutResult.hasDuplicates) { console.log('āŒ BlockTesterLayout.tsx still has duplicate issues:'); layoutResult.issues.forEach(issue => console.log(` - ${issue}`)); } else { console.log('āœ… BlockTesterLayout.tsx: No duplicate titles or validation display'); } const editorResult = checkFile(BLOCK_EDITOR, 'BlockEditor.tsx'); if (editorResult.hasDuplicates) { console.log('āŒ BlockEditor.tsx still has issues:'); editorResult.issues.forEach(issue => console.log(` - ${issue}`)); } else { console.log('āœ… BlockEditor.tsx: Properly using validation from props'); } console.log('\nšŸ“Š Test Results:'); if (!layoutResult.hasDuplicates && !editorResult.hasDuplicates) { console.log('āœ… All duplicate title and validation issues have been fixed!'); console.log('\nšŸŽ‰ Block Tester UX is now clean with:'); console.log(' • Single "Block Tester" page title'); console.log(' • No duplicate "Block Editor" text'); console.log(' • Single validation display per section'); console.log(' • Clear component hierarchy'); process.exit(0); } else { console.log('āŒ Some duplicate issues remain. Please review the implementation.'); process.exit(1); }