From e443343c9ff6bb26af3f8acf22ff8d0ed73089db Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 6 Mar 2023 22:10:09 +0100 Subject: [PATCH 1/2] test open scanner --- test/widget_tests/scanner_test.dart | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/widget_tests/scanner_test.dart diff --git a/test/widget_tests/scanner_test.dart b/test/widget_tests/scanner_test.dart new file mode 100644 index 0000000..7a9a5f0 --- /dev/null +++ b/test/widget_tests/scanner_test.dart @@ -0,0 +1,42 @@ +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:shared_preferences/shared_preferences.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); + }); + }); +} From 6b6d2c1fcd9e98d5029093103a489d876d8281e2 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 6 Mar 2023 22:12:13 +0100 Subject: [PATCH 2/2] remove unused import --- test/widget_tests/scanner_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/test/widget_tests/scanner_test.dart b/test/widget_tests/scanner_test.dart index 7a9a5f0..3260472 100644 --- a/test/widget_tests/scanner_test.dart +++ b/test/widget_tests/scanner_test.dart @@ -2,7 +2,6 @@ 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:shared_preferences/shared_preferences.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';