Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add ui tests for DapForm widget #322

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions test/features/dap/dap_form_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'package:dap/dap.dart';
import 'package:didpay/features/dap/dap_form.dart';
import 'package:didpay/features/dap/dap_qr_tile.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../helpers/widget_helpers.dart';

void main() async {
group('DapForm', () {
Widget dapFormTestWidget({AsyncValue<Dap>? dap, String? dapText}) =>
WidgetHelpers.testableWidget(
child: DapForm(
buttonTitle: 'Next',
dapText: ValueNotifier<String?>(dapText),
dap: ValueNotifier<AsyncValue<Dap>?>(dap),
onSubmit: (_, __) async {},
),
);

testWidgets('should show button title', (tester) async {
await tester.pumpWidget(dapFormTestWidget());
await tester.pumpAndSettle();

expect(find.widgetWithText(FilledButton, 'Next'), findsOneWidget);
});

testWidgets('should show QR Code CTA', (tester) async {
await tester.pumpWidget(dapFormTestWidget());
await tester.pumpAndSettle();

expect(
find.widgetWithText(
DapQrTile,
"Don't know their DAP? Scan their QR code instead",
),
findsOneWidget,
);
});

testWidgets('should show CircularProgressIndicator when DAP is loading',
(tester) async {
await tester.pumpWidget(dapFormTestWidget());
await tester.pump(Duration.zero);

expect(find.byType(CircularProgressIndicator), findsNothing);

await tester.pumpWidget(dapFormTestWidget(dap: const AsyncLoading()));
await tester.pump(Duration.zero);

expect(find.byType(CircularProgressIndicator), findsOneWidget);
});

testWidgets(
'should show error message when the Next button is tapped and the dap text is invalid',
(tester) async {
const invalidDapText = 'invalid_dap_text';
const expectedErrorMessage = 'Invalid DAP';

await tester.pumpWidget(dapFormTestWidget(dapText: invalidDapText));
await tester.pumpAndSettle();

expect(find.text(expectedErrorMessage), findsNothing);

await tester.tap(find.widgetWithText(FilledButton, 'Next'));
await tester.pumpAndSettle();

expect(find.text(expectedErrorMessage), findsOneWidget);
});

testWidgets(
'should resolve DAP without errors when the Next button is tapped and the dap text is valid',
(tester) async {
const validDapText = '@moegrammer/didpay.me';

await tester.pumpWidget(dapFormTestWidget(dapText: validDapText));
await tester.pumpAndSettle();

await tester.tap(find.widgetWithText(FilledButton, 'Next'));
await tester.pumpAndSettle();

expect(find.text('Invalid DAP'), findsNothing);
});
});
}
Loading