- 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
82 lines
2.4 KiB
Dart
82 lines
2.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:bookshelf_flutter/features/scanner/bloc/scanner_bloc.dart';
|
|
import 'package:bookshelf_flutter/features/scanner/bloc/scanner_event.dart';
|
|
import 'package:bookshelf_flutter/features/scanner/bloc/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);
|
|
});
|
|
});
|
|
});
|
|
} |