Skip to content

Commit

Permalink
Add test for fixes in #1381
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush0Chaudhary committed Jan 6, 2023
1 parent 4c5e4e1 commit 6a73046
Showing 1 changed file with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class TestWidget extends StatelessWidget {

Future<void> main() async {
SizeConfig().test();

const double PORTRAIT_WIDTH = 400.0;
const double PORTRAIT_HEIGHT = 800.0;
const double LANDSCAPE_WIDTH = PORTRAIT_HEIGHT;
const double LANDSCAPE_HEIGHT = PORTRAIT_WIDTH;
Hive.init('test/fixtures/core');
await Hive.openBox('url');

Expand Down Expand Up @@ -92,25 +95,43 @@ Future<void> main() async {
verify(navigationService
.showSnackBar("URL doesn't exist/no connection please check"));
});
group("Check if scanQr() is working", () {
testWidgets('Check if scanQR() is working fine in portrait mode',
(tester) async {
final TestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized();
await binding
.setSurfaceSize(const Size(PORTRAIT_WIDTH, PORTRAIT_HEIGHT));
await tester.pumpWidget(MaterialApp(home: TestWidget(model)));
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();

expect(find.byType(ClipRRect), findsOneWidget);
expect(find.byType(QRView), findsOneWidget);
});
testWidgets("Check if scanQR() is working fine in landscape mode",
(tester) async {
final TestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Check if scanQR() is working fine', (tester) async {
await tester.pumpWidget(MaterialApp(home: TestWidget(model)));
await binding
.setSurfaceSize(const Size(LANDSCAPE_WIDTH, LANDSCAPE_HEIGHT));

await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
await tester.pumpWidget(MaterialApp(home: TestWidget(model)));
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();

expect(find.byType(ClipRRect), findsOneWidget);
expect(find.byType(QRView), findsOneWidget);
expect(find.byType(ClipRRect), findsOneWidget);
expect(find.byType(QRView), findsOneWidget);
});
});

testWidgets('Check if _onQRViewCreated() is working fine', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestWidget(model),
navigatorKey: navigationService.navigatorKey,
),
);

final controller = MockQRViewController();
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode('qr?orgId=1&scan', BarcodeFormat.qrcode, null);
Expand Down

0 comments on commit 6a73046

Please sign in to comment.