Files
bookshelf/bookshelf_flutter/test/bloc/home/home_bloc_test.dart
Yuriy Panov 310463e89a refactor: create separate BLoCs for each screen with comprehensive tests
- 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
2026-02-04 14:40:00 +06:00

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);
});
});
});
}