Skip to content

Commit

Permalink
test: add ui tests for AccountBalanceCard (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
victoreronmosele authored Oct 11, 2024
1 parent b7fe3ff commit 824cc4c
Showing 1 changed file with 102 additions and 0 deletions.
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);
});
});
});
}

0 comments on commit 824cc4c

Please sign in to comment.