Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into test/currency-dropd…
Browse files Browse the repository at this point in the history
…own-widget
  • Loading branch information
mohitrajsinha committed Oct 11, 2024
2 parents 6a2e10f + 89bbc71 commit 4821eb9
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/features/payment/payment_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PaymentDetailsPage extends HookConsumerWidget {

return PopScope(
canPop: !isAwaiting,
onPopInvoked: (_) {
onPopInvokedWithResult: (_, __) {
if (isAwaiting) {
ref.read(quoteProvider.notifier).stopPolling();
quote.value = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/features/payment/payment_review_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PaymentReviewPage extends HookConsumerWidget {

return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
onPopInvokedWithResult: (didPop, _) async {
if (didPop) {
return;
}
Expand Down
102 changes: 102 additions & 0 deletions test/features/account/account_balance_card_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import 'package:didpay/features/account/account_balance_card.dart';
import 'package:didpay/features/account/account_balance_notifier.dart';
import 'package:didpay/features/did/did_provider.dart';
import 'package:didpay/features/pfis/pfis_notifier.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

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

void main() async {
await TestData.initializeDids();

final accountBalance = TestData.getAccountBalance();
final did = TestData.aliceDid;
final pfis = TestData.getPfis();

late MockPfisNotifier mockPfisNotifier;
late MockAccountBalanceNotifier mockAccountBalanceNotifier;

group('AccountBalanceCard', () {
setUpAll(() {
registerFallbackValue(did);
registerFallbackValue(pfis);
});

setUp(() {
mockPfisNotifier = MockPfisNotifier(pfis);
mockAccountBalanceNotifier = MockAccountBalanceNotifier(accountBalance);

when(
() => mockAccountBalanceNotifier.startPolling(any(), any()),
).thenAnswer((_) async => accountBalance);
});

Widget accountBalanceCardTestWidget({
bool pfisIsEmpty = false,
}) =>
WidgetHelpers.testableWidget(
child: const AccountBalanceCard(),
overrides: [
pfisProvider.overrideWith(
(ref) => pfisIsEmpty ? MockPfisNotifier([]) : mockPfisNotifier,
),
accountBalanceProvider
.overrideWith(() => mockAccountBalanceNotifier),
didProvider.overrideWith((ref) => did),
],
);

testWidgets('should show account balance title', (tester) async {
await tester.pumpWidget(accountBalanceCardTestWidget());
await tester.pumpAndSettle();

expect(find.text('Account balance'), findsOneWidget);
});

testWidgets('should show account balance amount', (tester) async {
await tester.pumpWidget(accountBalanceCardTestWidget());
await tester.pumpAndSettle();

expect(find.text('101'), findsOneWidget);
expect(find.text('USD'), findsOneWidget);
});

group('if pfis is empty', () {
testWidgets('should not show deposit button', (tester) async {
await tester
.pumpWidget(accountBalanceCardTestWidget(pfisIsEmpty: true));
await tester.pumpAndSettle();

expect(find.widgetWithText(FilledButton, 'Deposit'), findsNothing);
});

testWidgets('should not show withdraw button', (tester) async {
await tester
.pumpWidget(accountBalanceCardTestWidget(pfisIsEmpty: true));
await tester.pumpAndSettle();

expect(find.widgetWithText(FilledButton, 'Withdraw'), findsNothing);
});
});

group('if pfis is not empty', () {
testWidgets('should show deposit button', (tester) async {
await tester.pumpWidget(accountBalanceCardTestWidget());
await tester.pumpAndSettle();

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

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

expect(find.widgetWithText(FilledButton, 'Withdraw'), findsOneWidget);
});
});
});
}
15 changes: 12 additions & 3 deletions test/helpers/test_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ class TestData {
static FeatureFlag getFeatureFlag(String name, String description) =>
FeatureFlag(name: name, description: description);

static Map<Pfi, List<Offering>> getOfferingsMap() => {
Pfi(did: pfiDid.uri): [getOffering()],
static Map<Pfi, List<Offering>> getOfferingsMap({
List<String>? payoutCurrencies,
}) =>
{
Pfi(did: pfiDid.uri):
(payoutCurrencies != null && payoutCurrencies.isNotEmpty)
? payoutCurrencies
.map((currency) => getOffering(payoutCurrency: currency))
.toList()
: [getOffering()],
};

static List<Pfi> getPfis() => [Pfi(did: pfiDid.uri)];
Expand All @@ -37,6 +45,7 @@ class TestData {
AccountBalance(total: '101', currencyCode: 'USD', balancesMap: {});

static Offering getOffering({
String? payoutCurrency,
PresentationDefinition? requiredClaims,
List<PayinMethod>? payinMethods,
List<PayoutMethod>? payoutMethods,
Expand All @@ -59,7 +68,7 @@ class TestData {
],
),
payout: PayoutDetails(
currencyCode: 'USD',
currencyCode: payoutCurrency ?? 'USD',
methods: payoutMethods ??
[
PayoutMethod(
Expand Down

0 comments on commit 4821eb9

Please sign in to comment.