[03-Developer] #226 Catalog Gallery 구현
- Drift schema v2: Protocols.category CHECK 6→7 (light_circadian/sleep/movement/
nutrition/focus_cognition/recovery_stress/emotion_relationship). schemaVersion
1→2 + onUpgrade migrateV1ToV2 (DROP+CREATE+reseed flag 클리어).
- protocols.json 34 항목 v2 재분류 (1차 효과 기준). emotion_relationship 0 매핑.
- 도메인: DisplayCategory enum (8) + CatalogItem sealed (Protocol/Break/Diet).
- 데이터: CatalogRepository.all/byId/referencesByIds (3 source 통합).
- 상태: catalog_providers.dart (catalogItems / groupedByCategory / refsByIds).
- UI: ProtocolGalleryScreen (카테고리 칩 + 카드 그리드) + ProtocolPreviewScreen
(모든 필드 + reference 펼치기 + "내 습관으로" disabled placeholder) +
CatalogCard / CategoryChipRow / ReferenceExpandCard. HabitListScreen 빈
상태 CTA + AppBar 액션.
- 테스트: migration_v1_to_v2 3건 + display_category 5건 + catalog_repository
9건 + gallery widget 3건 + preview widget 3건 = 23 신규. 기존 88 회귀 0,
flutter analyze 0 issues. 110 passed / 1 skipped.
설계서: docs/design/226-catalog-gallery/{README, fn-catalog_repository,
fn-migration_v1_to_v2}.md + ADR-0004.
Refs #226
This commit is contained in:
81
app/test/ui/protocol_preview_screen_test.dart
Normal file
81
app/test/ui/protocol_preview_screen_test.dart
Normal file
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:life_helper/domain/catalog/catalog_item.dart';
|
||||
import 'package:life_helper/domain/catalog/display_category.dart';
|
||||
import 'package:life_helper/state/catalog_providers.dart';
|
||||
import 'package:life_helper/ui/screens/protocol_preview_screen.dart';
|
||||
|
||||
ProtocolCatalogItem _sampleProtocol({List<String> refIds = const []}) =>
|
||||
ProtocolCatalogItem(
|
||||
id: 'morning_sunlight',
|
||||
title: '아침 햇빛',
|
||||
titleEn: 'Morning Sunlight',
|
||||
summary: '기상 후 햇빛',
|
||||
displayCategory: DisplayCategory.lightCircadian,
|
||||
evidenceStrength: 'strong_rct',
|
||||
referenceIds: refIds,
|
||||
what: '기상 후 햇빛 노출.',
|
||||
whenText: '기상 후 30~60분.',
|
||||
dose: '5~10분.',
|
||||
why: 'ipRGC 자극으로 일주기 리셋.',
|
||||
how: const ['밖으로 나간다', '하늘을 쳐다본다'],
|
||||
checkText: '60분 이내 외출',
|
||||
caution: '직사 응시 금지',
|
||||
defaultAnchor: const {'when': '기상 후', 'after_what': '세수'},
|
||||
minDoseForStart: '2분',
|
||||
sourceDoc: 'huberman-protocols.md',
|
||||
);
|
||||
|
||||
void main() {
|
||||
Widget buildHarness(CatalogItem item, {List<dynamic> refs = const []}) {
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
referencesByIdsProvider.overrideWith((ref, ids) async => []),
|
||||
],
|
||||
child: MaterialApp(home: ProtocolPreviewScreen(item: item)),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('Protocol: 모든 핵심 필드 표시', (tester) async {
|
||||
final item = _sampleProtocol();
|
||||
await tester.pumpWidget(buildHarness(item));
|
||||
await tester.pump();
|
||||
|
||||
// Header + 상단 가시 필드.
|
||||
expect(find.text('아침 햇빛'), findsAtLeastNWidgets(1));
|
||||
expect(find.text('Morning Sunlight'), findsOneWidget);
|
||||
expect(find.text('빛/일주기'), findsOneWidget);
|
||||
|
||||
// ListView lazy-builds — 하위 필드는 명시적 스크롤로 가져온다.
|
||||
final scrollable = find.byType(Scrollable).first;
|
||||
for (final t in [
|
||||
'ipRGC 자극으로 일주기 리셋.',
|
||||
'1. 밖으로 나간다',
|
||||
'2. 하늘을 쳐다본다',
|
||||
'60분 이내 외출',
|
||||
'직사 응시 금지',
|
||||
'2분',
|
||||
'huberman-protocols.md',
|
||||
]) {
|
||||
await tester.scrollUntilVisible(find.text(t), 100,
|
||||
scrollable: scrollable);
|
||||
expect(find.text(t), findsOneWidget, reason: 'missing: $t');
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('"내 습관으로" 버튼 disabled + tooltip', (tester) async {
|
||||
await tester.pumpWidget(buildHarness(_sampleProtocol()));
|
||||
await tester.pump();
|
||||
|
||||
final button = tester.widget<FilledButton>(find.byType(FilledButton));
|
||||
expect(button.onPressed, isNull);
|
||||
expect(find.byType(Tooltip), findsAtLeastNWidgets(1));
|
||||
});
|
||||
|
||||
testWidgets('reference 없으면 References 섹션 숨김', (tester) async {
|
||||
await tester.pumpWidget(buildHarness(_sampleProtocol(refIds: const [])));
|
||||
await tester.pump();
|
||||
expect(find.textContaining('참고 ('), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user