Files
bookshelf/bookshelf_flutter/test/bloc/home/home_bloc_test.dart
Yuriy Panov 2f97873095 Fix import paths and test issues
- Fixed test file import paths to point to correct Bloc file locations
- Fixed Bloc file import paths for models (../../../models/models.dart)
- Added explicit type annotations to resolve null safety warnings
- Fixed null safety issues in wishlist_bloc_test.dart
- All 70 tests now passing
2026-02-04 15:28:59 +06:00

85 lines
2.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:bookshelf_flutter/features/home/bloc/home_bloc.dart';
import 'package:bookshelf_flutter/features/home/bloc/home_event.dart';
import 'package:bookshelf_flutter/features/home/bloc/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);
});
});
});
}