퀘스트 목록 페이지 판정 · 다시 읽기 · 캠페인 응원 수를 고유 후원자 기준으로

This commit is contained in:
Sn-Kinos
2026-10-06 02:19:40 +09:00
parent 807e446b8b
commit 82662b9b9f
8 changed files with 164 additions and 18 deletions
+53
View File
@@ -132,6 +132,31 @@ void main() {
expect(find.text('12,290'), findsNothing);
});
testWidgets('첫 10장이 모두 걸러져도 11번째 이후 퀘스트가 보인다 (2026-10-06 실기기)', (tester) async {
await pumpWide(tester, QuestListScreen(repository: _PagedRepo()));
await tester.pumpAndSettle();
expect(find.text('열한 번째 퀘스트'), findsOneWidget);
});
testWidgets('탭 전환 · 당겨서 새로고침이 목록을 다시 읽는다 (내 퀘스트 상태 · 2026-10-06 실기기)', (tester) async {
final repo = _PagedRepo();
await pumpWide(tester, QuestListScreen(repository: repo));
await tester.pumpAndSettle();
final before = repo.loads;
await tester.tap(
find.descendant(of: find.byType(QuestTabStrip), matching: find.text(QuestTab.mine.label)),
);
await tester.pumpAndSettle();
expect(repo.loads, before + 1);
await tester.tap(
find.descendant(of: find.byType(QuestTabStrip), matching: find.text(QuestTab.all.label)),
);
await tester.pumpAndSettle();
await tester.fling(find.text('열한 번째 퀘스트'), const Offset(0, 400), 1000);
await tester.pumpAndSettle();
expect(repo.loads, before + 3);
});
testWidgets('목록 조회가 실패해도 로딩이 끝난다', (tester) async {
await pumpWide(tester, QuestListScreen(repository: _FailingList()));
await tester.pumpAndSettle();
@@ -513,6 +538,34 @@ class _BalanceRepo extends SampleQuestRepository {
Future<int?> popBalance() async => 12260;
}
/// 첫 페이지 10장이 모두 감춰지는(보상완료 관리자) 표본 — 11번째가 다음 페이지에 있다.
class _PagedRepo extends SampleQuestRepository {
var loads = 0;
static QuestCard _hidden(int i) => QuestCard(
id: 'h$i', title: '숨김 $i', categoryName: '출석', type: QuestType.attend,
author: QuestAuthor.admin, stage: QuestStage.rewarded, goal: 1, progress: 1,
rewardPop: 10, participants: 0,
);
@override
Future<List<QuestCard>> load({int limit = 10}) async {
loads += 1;
return [for (var i = 0; i < 10; i++) _hidden(i)];
}
@override
Future<List<QuestCard>> more({required int offset, int limit = 10}) async => offset >= 11
? const []
: const [
QuestCard(
id: 'u11', title: '열한 번째 퀘스트', categoryName: '건강', type: QuestType.steps,
author: QuestAuthor.user, stage: QuestStage.notStarted, goal: 1, progress: 0,
rewardPop: 10, participants: 0,
),
];
}
/// 목록이 실패하는 표본 — 로딩이 끝나지 않으면 탭 전체가 무한 로딩이다.
class _FailingList extends SampleQuestRepository {
@override
+28
View File
@@ -179,6 +179,34 @@ service cloud.firestore {
expect(cards.map((c) => c.id), contains('attend'));
});
test('비활성 문서가 첫 페이지를 채워도 11번째 이후 퀘스트가 보인다 (2026-10-06 실기기)', () async {
final db = FakeFirebaseFirestore();
// 문서 ID 순으로 앞 10건이 비활성(daily-*) — 걸러낸 뒤 개수로 끝을 판정하면 뒤가 사라진다.
for (var i = 0; i < 10; i++) {
await db.doc('quests/a-daily-$i').set({'type': 'attend', 'title': 'd$i', 'active': false});
}
await db.doc('quests/z-music').set({'type': 'music_shake', 'title': '박자 맞춰 흔들기'});
final repo = FirestoreQuestRepository(_RecordingBackend(db));
final first = await repo.load();
expect(first.map((c) => c.id), contains('z-music'));
// 10장보다 적으면 끝 — 다음 페이지는 비어 있다.
expect(first.length, lessThan(10));
expect(await repo.more(offset: first.length), isEmpty);
});
test('보이는 퀘스트가 10건을 넘으면 다음 페이지에서 11번째부터 온다', () async {
final db = FakeFirebaseFirestore();
for (var i = 0; i < 12; i++) {
await db.doc('quests/q${i.toString().padLeft(2, '0')}').set({'type': 'attend', 'title': 'q$i'});
}
final repo = FirestoreQuestRepository(_RecordingBackend(db));
final first = await repo.load();
expect(first, hasLength(10));
final next = await repo.more(offset: first.length);
expect(next, hasLength(2));
expect({...first, ...next}.map((c) => c.id).toSet(), hasLength(12));
});
test('내가 만든 퀘스트는 내 퀘스트 상태로 온다', () async {
final db = await _seed();
await db.doc('quests/mine').set({