- Created 8 separate BLoCs (Home, Library, BookDetails, AddBook, Scanner, Categories, Wishlist, Settings) - Each BLoC has its own event, state, and bloc files - Added 70 comprehensive tests covering all BLoC functionality - All tests passing (70/70) - Fixed linting issues and updated deprecated APIs - Improved code organization and maintainability
85 lines
2.6 KiB
Dart
85 lines
2.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:bookshelf_flutter/bloc/home/home_bloc.dart';
|
|
import 'package:bookshelf_flutter/bloc/home/home_event.dart';
|
|
import 'package:bookshelf_flutter/bloc/home/home_state.dart';
|
|
import 'package:bookshelf_flutter/models/models.dart';
|
|
|
|
void main() {
|
|
group('HomeBloc', () {
|
|
late HomeBloc homeBloc;
|
|
|
|
setUp(() {
|
|
homeBloc = HomeBloc();
|
|
});
|
|
|
|
tearDown(() {
|
|
homeBloc.close();
|
|
});
|
|
|
|
test('initial state is HomeState.initial()', () {
|
|
expect(homeBloc.state, isA<HomeState>());
|
|
expect(homeBloc.state.isLoading, true);
|
|
});
|
|
|
|
group('LoadHomeData', () {
|
|
test('loads home data with default screen', () async {
|
|
homeBloc.add(const LoadHomeData());
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.library);
|
|
expect(homeBloc.state.isLoading, false);
|
|
});
|
|
});
|
|
|
|
group('NavigateToScreen', () {
|
|
test('navigates to library screen', () async {
|
|
homeBloc.add(const NavigateToScreen(AppScreen.library));
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.library);
|
|
});
|
|
|
|
test('navigates to categories screen', () async {
|
|
homeBloc.add(const NavigateToScreen(AppScreen.categories));
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.categories);
|
|
});
|
|
|
|
test('navigates to wishlist screen', () async {
|
|
homeBloc.add(const NavigateToScreen(AppScreen.wishlist));
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.wishlist);
|
|
});
|
|
|
|
test('navigates to settings screen', () async {
|
|
homeBloc.add(const NavigateToScreen(AppScreen.settings));
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.settings);
|
|
});
|
|
|
|
test('navigates to details screen', () async {
|
|
homeBloc.add(const NavigateToScreen(AppScreen.details));
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.details);
|
|
});
|
|
|
|
test('navigates to add book screen', () async {
|
|
homeBloc.add(const NavigateToScreen(AppScreen.addBook));
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.addBook);
|
|
});
|
|
|
|
test('navigates to scanner screen', () async {
|
|
homeBloc.add(const NavigateToScreen(AppScreen.scanner));
|
|
await Future.delayed(Duration.zero);
|
|
|
|
expect(homeBloc.state.currentScreen, AppScreen.scanner);
|
|
});
|
|
});
|
|
});
|
|
} |