import { FASTING_PLANS, FastingPlan } from '@/constants/Fasting'; import { fastingNotificationTester } from '@/utils/fastingNotificationTest'; import React, { useState } from 'react'; import { Alert, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; interface FastingNotificationTestPanelProps { onClose: () => void; } export const FastingNotificationTestPanel: React.FC = ({ onClose, }) => { const [isRunning, setIsRunning] = useState(false); const [testResults, setTestResults] = useState>([]); const runTest = async (plan: FastingPlan) => { setIsRunning(true); setTestResults([]); try { const results = await fastingNotificationTester.runFullTestSuite(plan); setTestResults(results); const passedCount = results.filter(r => r.passed).length; const totalCount = results.length; Alert.alert( '测试完成', `测试结果: ${passedCount}/${totalCount} 通过`, [{ text: '确定', onPress: () => { } }] ); } catch (error) { Alert.alert( '测试失败', `测试过程中发生错误: ${error instanceof Error ? error.message : '未知错误'}`, [{ text: '确定', onPress: () => { } }] ); } finally { setIsRunning(false); } }; const clearResults = () => { setTestResults([]); fastingNotificationTester.clearResults(); }; return ( 断食通知测试 × 选择测试方案 {FASTING_PLANS.map((plan) => ( runTest(plan)} disabled={isRunning} > {plan.title} {plan.subtitle} ))} {testResults.length > 0 && ( 测试结果 清除 {testResults.map((result, index) => ( {result.testName} {result.message} {result.timestamp.toLocaleTimeString()} ))} )} {isRunning && ( 正在运行测试... )} ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#F5F5F5', }, header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 16, backgroundColor: '#FFFFFF', borderBottomWidth: 1, borderBottomColor: '#E0E0E0', }, title: { fontSize: 18, fontWeight: '600', color: '#333333', }, closeButton: { width: 32, height: 32, borderRadius: 16, backgroundColor: '#F0F0F0', justifyContent: 'center', alignItems: 'center', }, closeButtonText: { fontSize: 18, fontWeight: '600', color: '#666666', }, content: { flex: 1, padding: 16, }, section: { marginBottom: 24, }, sectionHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12, }, sectionTitle: { fontSize: 16, fontWeight: '600', color: '#333333', marginBottom: 12, }, planButton: { backgroundColor: '#FFFFFF', padding: 12, borderRadius: 8, marginBottom: 8, borderWidth: 1, borderColor: '#E0E0E0', }, disabledButton: { opacity: 0.5, }, planButtonText: { fontSize: 14, fontWeight: '500', color: '#333333', }, planSubtitle: { fontSize: 12, color: '#666666', marginTop: 2, }, clearButton: { paddingHorizontal: 12, paddingVertical: 6, backgroundColor: '#F0F0F0', borderRadius: 4, }, clearButtonText: { fontSize: 12, color: '#666666', }, resultItem: { padding: 12, borderRadius: 8, marginBottom: 8, borderLeftWidth: 4, }, passedResult: { backgroundColor: '#F0F9F0', borderLeftColor: '#4CAF50', }, failedResult: { backgroundColor: '#FFF3F3', borderLeftColor: '#F44336', }, resultTestName: { fontSize: 14, fontWeight: '500', color: '#333333', }, resultMessage: { fontSize: 12, color: '#666666', marginTop: 2, }, resultTime: { fontSize: 10, color: '#999999', marginTop: 4, }, runningText: { fontSize: 14, color: '#666666', textAlign: 'center', fontStyle: 'italic', }, });