Skip to content

Commit

Permalink
test(history): add more solve list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GabinL21 committed Aug 5, 2023
1 parent 5c2bf32 commit 9b77cdb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/history/view/solves_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ void main() {
),
);

final mockExtraSolves = List.generate(
10,
(_) => Solve(
uid: '',
timestamp: DateTime(2000),
time: const Duration(seconds: 10),
scramble: '',
),
);

late HistoryBloc historyBloc;

setUp(() {
Expand Down Expand Up @@ -72,5 +82,32 @@ void main() {
await tester.pumpSolvesList(historyBloc);
expect(find.byType(SolveTile), findsNWidgets(mockSolves.length));
});

testWidgets('fetches first solves when history state is initial',
(tester) async {
when(() => historyBloc.state).thenReturn(HistoryInitial());
await tester.pumpSolvesList(historyBloc);
verify(() => historyBloc.add(const GetFirstHistory())).called(1);
});

testWidgets('fetches more solves when scrolled to the bottom',
(tester) async {
when(() => historyBloc.state)
.thenReturn(HistoryLoaded(mockExtraSolves, null));
await tester.pumpSolvesList(historyBloc);
await tester.drag(find.byType(SolvesList), const Offset(0, -2000));
verify(() => historyBloc.add(const GetNextHistory())).called(1);
});

testWidgets(
'fetches no solves '
'when scrolled to the bottom and history is fully loaded',
(tester) async {
when(() => historyBloc.state)
.thenReturn(HistoryFullyLoaded(mockExtraSolves, null));
await tester.pumpSolvesList(historyBloc);
await tester.drag(find.byType(SolvesList), const Offset(0, -2000));
verifyNever(() => historyBloc.add(const GetNextHistory()));
});
});
}

0 comments on commit 9b77cdb

Please sign in to comment.