import React, { useState } from 'react'; import { testStripGenerator } from '../../utils/testStripGenerator'; const TestStripTester = ({ onTestResult }) => { const [selectedScenario, setSelectedScenario] = useState('excellent_water'); const [testOptions, setTestOptions] = useState({ lighting: 'normal', background: 'white', addImperfections: true, imperfectionLevel: 'medium', addLabels: false }); const [generatedTest, setGeneratedTest] = useState(null); const [testResults, setTestResults] = useState([]); // Safely get scenarios with fallback const scenarios = testStripGenerator?.getAvailableScenarios?.() || [ { name: 'excellent_water', description: 'Excellent quality drinking water' }, { name: 'good_water', description: 'Good quality water with minor issues' }, { name: 'poor_water', description: 'Poor quality water needing treatment' }, { name: 'contaminated_water', description: 'Contaminated water - unsafe for consumption' } ]; const generateTestImage = () => { try { if (!testStripGenerator?.generateFromScenario) { console.error('Test strip generator not available'); return; } const testStrip = testStripGenerator.generateFromScenario(selectedScenario, testOptions); setGeneratedTest(testStrip); if (onTestResult) { onTestResult(testStrip); } } catch (error) { console.error('Failed to generate test strip:', error); alert('Failed to generate test strip. Please try again.'); } }; const generateFullTestSuite = () => { try { if (!testStripGenerator?.generateTestSuite) { console.error('Test suite generator not available'); return; } const testSuite = testStripGenerator.generateTestSuite({ scenarios: ['excellent_water', 'good_water', 'poor_water', 'contaminated_water'], lightingConditions: ['dim', 'normal', 'bright'], backgrounds: ['white', 'colored'] }); setTestResults(testSuite); console.log('Generated test suite with', testSuite.length, 'test images'); } catch (error) { console.error('Failed to generate test suite:', error); alert('Failed to generate test suite. Please try again.'); } }; const downloadTestSuite = () => { try { if (testResults.length === 0) { generateFullTestSuite(); return; } if (!testStripGenerator?.exportTestSuite) { console.error('Export function not available'); return; } const exportData = testStripGenerator.exportTestSuite(testResults); const blob = new Blob([exportData], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `aqua-lens-test-suite-${new Date().toISOString().split('T')[0]}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); } catch (error) { console.error('Failed to download test suite:', error); alert('Failed to download test suite. Please try again.'); } }; return (

🧪 AquaLens Accuracy Tester

{/* Scenario Selection */}
{/* Test Options */}
{/* Options Checkboxes */}
{/* Action Buttons */}
{/* Generated Test Display */} {generatedTest && (

Generated Test Strip

Generated test strip
Expected Results:
pH: {generatedTest.expectedResults.ph}
Chlorine: {generatedTest.expectedResults.chlorine} ppm
Nitrates: {generatedTest.expectedResults.nitrates} ppm
Hardness: {generatedTest.expectedResults.hardness} ppm
Alkalinity: {generatedTest.expectedResults.alkalinity} ppm
Bacteria: {generatedTest.expectedResults.bacteria ? 'Present' : 'Safe'}
Overall Quality: {generatedTest.expectedResults.overallQuality}
Safety Level: {generatedTest.expectedResults.safetyLevel}
)} {/* Test Suite Summary */} {testResults.length > 0 && (

Test Suite Generated

Generated {testResults.length} test images covering various scenarios and conditions.

• Multiple lighting conditions (dim, normal, bright)
• Different backgrounds (white, colored, textured)
• Various water quality scenarios
• Realistic imperfections and variations
)}
); }; export default TestStripTester;