이벤트 가져오기 위젯 테스트 추가 및 테스트 훅 도입

This commit is contained in:
2025-09-12 06:33:44 +09:00
parent 107abc963f
commit a5f2544d11
121 changed files with 39277 additions and 3911 deletions
+31 -23
View File
@@ -15,6 +15,8 @@ class EventExcelParser {
final events = <Map<String, dynamic>>[];
int invalidRows = 0;
int processedRows = 0;
final List<int> invalidRowIndices = [];
final Map<int, String> invalidRowReasons = {};
// 첫 번째 시트 사용
final sheet = excel.tables.keys.first;
@@ -56,48 +58,52 @@ class EventExcelParser {
// 각 셀 처리
for (var j = 0; j < headers.length && j < row.length; j++) {
final header = headers[j];
final value = row[j]?.value;
// 날짜 필드 특별 처리
if (header == 'startdate' || header == 'enddate') {
DateTime? date = _parseDate(value);
// 날짜 값 설정
if (date != null) {
// 헤더 이름 정규화 (startdate -> startDate)
final normalizedHeader = header == 'startdate' ? 'startDate' : 'endDate';
event[normalizedHeader] = date.toIso8601String();
} else {
// 날짜 파싱 실패 시 startDate는 필수이므로 현재 날짜 사용
if (header == 'startdate') {
event['startDate'] = DateTime.now().toIso8601String();
} else {
// endDate는 선택적이므로 null 설정
event['endDate'] = null;
}
}
DateTime? date = _parseDate(row[j]?.value);
// 날짜 값 설정: 파싱 성공 시만 값 지정, 실패 시 null 유지
final normalizedHeader = header == 'startdate' ? 'startDate' : 'endDate';
event[normalizedHeader] = (date != null) ? date.toIso8601String() : null;
} else {
// 문자열 필드의 경우 빈 문자열은 null로 처리
final stringValue = value?.toString().trim() ?? '';
// 문자열/일반 필드: excel v4의 TextCellValue 등 실제 값 추출
String raw = '';
final cellVal = row[j]?.value;
if (cellVal is TextCellValue) {
raw = cellVal.value.toString();
} else if (cellVal != null) {
raw = cellVal.toString();
}
final stringValue = raw.trim();
// 헤더 이름 정규화 (특별한 경우)
String normalizedHeader = header;
if (header == 'title' || header == 'description' || header == 'location' ||
header == 'status' || header == 'type' || header == 'maxparticipants') {
// 첫 글자를 소문자로 유지하고 나머지는 원래 형식 유지
normalizedHeader = header == 'maxparticipants' ? 'maxParticipants' : header;
}
// 빈 문자열은 null로 처리
event[normalizedHeader] = stringValue.isEmpty ? null : stringValue;
}
}
// 필수 필드가 있는 경우만 추가
if (event.containsKey('title') && event.containsKey('startDate')) {
final hasTitle = event.containsKey('title') && (event['title']?.toString().trim().isNotEmpty ?? false);
final hasStart = event.containsKey('startDate') && (event['startDate']?.toString().trim().isNotEmpty ?? false);
if (hasTitle && hasStart) {
events.add(event);
} else {
invalidRows++;
// 데이터 행 기준(헤더 제외) 1-based가 아닌, 테스트 기대값에 맞춰 i 사용
// 즉, 헤더가 0, 첫 데이터 행이 i=1이므로 무효 행 번호로 i를 기록
final rowNo = i;
invalidRowIndices.add(rowNo);
final reasons = <String>[];
if (!hasTitle) reasons.add('title 누락');
if (!hasStart) reasons.add('startDate 누락');
invalidRowReasons[rowNo] = reasons.join(', ');
}
}
@@ -105,6 +111,8 @@ class EventExcelParser {
'processedRows': processedRows,
'validEvents': events,
'invalidRows': invalidRows,
'invalidRowIndices': invalidRowIndices,
'invalidRowReasons': invalidRowReasons,
'error': events.isEmpty ? '유효한 이벤트 데이터가 없습니다.' : null
};
}