Skip to content

Commit

Permalink
test(history): add history bloc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GabinL21 committed Aug 5, 2023
1 parent 9b77cdb commit a157b9b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/history/bloc/history_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:kubrs_app/history/bloc/history_bloc.dart';
import 'package:kubrs_app/history/model/history.dart';
import 'package:kubrs_app/history/repository/history_repository.dart';
import 'package:kubrs_app/solve/model/solve.dart';
import 'package:mocktail/mocktail.dart';

class MockHistoryRepository extends Mock implements HistoryRepository {}

void main() {
group('HistoryBloc', () {
final mockSolves = List.generate(
3,
(_) => Solve(
uid: '',
timestamp: DateTime(2000),
time: const Duration(seconds: 10),
scramble: '',
),
);

late HistoryRepository historyRepository;

setUp(() {
historyRepository = MockHistoryRepository();
when(
() => historyRepository.getFirstHistory(),
).thenAnswer((_) => Future.value(History(mockSolves, null)));
});

blocTest<HistoryBloc, HistoryState>(
'emits initial state when history is created',
build: () => HistoryBloc(historyRepository: historyRepository),
verify: (bloc) => bloc.state == HistoryInitial(),
);

blocTest<HistoryBloc, HistoryState>(
'emits loading and loaded states when history is first fetched',
build: () => HistoryBloc(historyRepository: historyRepository),
act: (bloc) => bloc.add(const GetFirstHistory()),
expect: () =>
<HistoryState>[HistoryLoading(), HistoryLoaded(mockSolves, null)],
);
});
}
6 changes: 6 additions & 0 deletions test/timer/bloc/timer_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import 'package:kubrs_app/timer/bloc/timer_bloc.dart';

void main() {
group('TimerBloc', () {
blocTest<TimerBloc, TimerState>(
'emits initial state when timer is created',
build: TimerBloc.new,
verify: (bloc) => bloc.state == const TimerInitial(),
);

blocTest<TimerBloc, TimerState>(
'emits reset state when timer is reseted',
build: TimerBloc.new,
Expand Down

0 comments on commit a157b9b

Please sign in to comment.