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
This commit is contained in:
82
bookshelf_flutter/test/bloc/scanner/scanner_bloc_test.dart
Normal file
82
bookshelf_flutter/test/bloc/scanner/scanner_bloc_test.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:bookshelf_flutter/bloc/scanner/scanner_bloc.dart';
|
||||
import 'package:bookshelf_flutter/bloc/scanner/scanner_event.dart';
|
||||
import 'package:bookshelf_flutter/bloc/scanner/scanner_state.dart';
|
||||
|
||||
void main() {
|
||||
group('ScannerBloc', () {
|
||||
late ScannerBloc scannerBloc;
|
||||
|
||||
setUp(() {
|
||||
scannerBloc = ScannerBloc();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
scannerBloc.close();
|
||||
});
|
||||
|
||||
test('initial state is ScannerState.initial()', () {
|
||||
expect(scannerBloc.state, isA<ScannerState>());
|
||||
expect(scannerBloc.state.isScanning, false);
|
||||
expect(scannerBloc.state.isProcessing, false);
|
||||
});
|
||||
|
||||
group('StartScanning', () {
|
||||
test('sets isScanning to true and clears errors', () async {
|
||||
scannerBloc.add(const StartScanning());
|
||||
await Future.delayed(Duration.zero);
|
||||
|
||||
expect(scannerBloc.state.isScanning, true);
|
||||
expect(scannerBloc.state.isProcessing, false);
|
||||
expect(scannerBloc.state.errorMessage, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('StopScanning', () {
|
||||
test('sets isScanning to false', () async {
|
||||
scannerBloc.add(const StartScanning());
|
||||
await Future.delayed(Duration.zero);
|
||||
|
||||
scannerBloc.add(const StopScanning());
|
||||
await Future.delayed(Duration.zero);
|
||||
|
||||
expect(scannerBloc.state.isScanning, false);
|
||||
});
|
||||
});
|
||||
|
||||
group('BookDetected', () {
|
||||
test('stores detected book data and sets isProcessing to true', () async {
|
||||
final bookData = {
|
||||
'title': 'Detected Book',
|
||||
'author': 'Detected Author',
|
||||
};
|
||||
|
||||
scannerBloc.add(BookDetected(bookData));
|
||||
await Future.delayed(Duration.zero);
|
||||
|
||||
expect(scannerBloc.state.detectedBookData, bookData);
|
||||
expect(scannerBloc.state.isProcessing, true);
|
||||
});
|
||||
});
|
||||
|
||||
group('ClearDetectedBook', () {
|
||||
test('clears detected book data and resets processing', () async {
|
||||
final bookData = {
|
||||
'title': 'Detected Book',
|
||||
'author': 'Detected Author',
|
||||
};
|
||||
|
||||
scannerBloc.add(BookDetected(bookData));
|
||||
await Future.delayed(Duration.zero);
|
||||
|
||||
expect(scannerBloc.state.detectedBookData, isNotNull);
|
||||
|
||||
scannerBloc.add(const ClearDetectedBook());
|
||||
await Future.delayed(Duration.zero);
|
||||
|
||||
expect(scannerBloc.state.detectedBookData, isNull);
|
||||
expect(scannerBloc.state.isProcessing, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user