cpd_2022_zi/test/widget_tests/scanner_test.dart

42 lines
1.3 KiB
Dart
Raw Permalink Normal View History

2023-03-06 22:10:09 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/settings_provider.dart';
import 'package:smoke_cess_app/widgets/buttons/text_icon_button.dart';
import 'package:smoke_cess_app/widgets/scanner.dart';
import '../mock/settings_mock.dart';
void main() {
mockSharedPreferences();
group('MyScanner', () {
testWidgets('Scanner should start after Button is pressed',
(widgetTester) async {
SettingsProvider settingsProvider = SettingsProvider();
expect(settingsProvider.scanning, false);
await widgetTester.pumpWidget(MaterialApp(
home: Column(
children: [
ChangeNotifierProvider(
create: (context) => settingsProvider, child: const MyScanner())
],
),
));
final startScannerButton = find.byType(TextIconButton);
final scanner = find.byType(MobileScanner);
expect(startScannerButton, findsOneWidget);
expect(scanner, findsNothing);
await widgetTester.tap(startScannerButton);
await widgetTester.pump();
expect(startScannerButton, findsNothing);
expect(scanner, findsOneWidget);
expect(settingsProvider.scanning, true);
});
});
}