This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for
TransactionDetailsPage
(#316)
- Loading branch information
1 parent
fdf2352
commit 568d379
Showing
3 changed files
with
150 additions
and
17 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
test/features/transaction/transaction_details_page_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import 'package:didpay/features/transaction/transaction.dart'; | ||
import 'package:didpay/features/transaction/transaction_details_page.dart'; | ||
import 'package:didpay/features/transaction/transaction_notifier.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:intl/intl.dart'; | ||
|
||
import '../../helpers/mocks.dart'; | ||
import '../../helpers/test_data.dart'; | ||
import '../../helpers/widget_helpers.dart'; | ||
|
||
void main() { | ||
group('TransactionDetailsPage', () { | ||
final sendTransaction = TestData.getTransaction(); | ||
final depositTransaction = | ||
TestData.getTransaction(type: TransactionType.deposit); | ||
final withdrawTransaction = | ||
TestData.getTransaction(type: TransactionType.withdraw); | ||
|
||
const mockTransactionNotifierWithSendTransaction = | ||
MockTransactionNotifierWithData( | ||
transactionType: TransactionType.send, | ||
); | ||
const mockTransactionNotifierWithError = MockTransactionNotifierWithError(); | ||
|
||
late MockTransactionNotifier mockSendTransactionNotifier; | ||
late MockTransactionNotifier mockDepositTransactionNotifier; | ||
late MockTransactionNotifier mockWithdrawTransactionNotifier; | ||
late MockTransactionNotifier nullMockTransactionNotifier; | ||
late MockTransactionNotifier erroringMockTransactionNotifier; | ||
|
||
setUp(() { | ||
mockSendTransactionNotifier = | ||
MockTransactionNotifier(() => sendTransaction); | ||
mockDepositTransactionNotifier = | ||
MockTransactionNotifier(() => depositTransaction); | ||
mockWithdrawTransactionNotifier = | ||
MockTransactionNotifier(() => withdrawTransaction); | ||
nullMockTransactionNotifier = MockTransactionNotifier(); | ||
erroringMockTransactionNotifier = MockTransactionNotifier( | ||
() => throw StateError('Error loading transaction'), | ||
); | ||
}); | ||
|
||
Widget transactionDetailsTestWidget({ | ||
required MockTransactionNotifierType mockTransactionNotifierType, | ||
}) => | ||
WidgetHelpers.testableWidget( | ||
child: TransactionDetailsPage( | ||
pfi: TestData.getPfi('did:dht:pfiDid'), | ||
exchangeId: 'rfq_01ha835rhefwmagsknrrhvaa0k', | ||
), | ||
overrides: [ | ||
transactionProvider.overrideWith( | ||
() => switch (mockTransactionNotifierType) { | ||
MockTransactionNotifierWithData() => switch ( | ||
mockTransactionNotifierType.transactionType) { | ||
TransactionType.send => mockSendTransactionNotifier, | ||
TransactionType.deposit => mockDepositTransactionNotifier, | ||
TransactionType.withdraw => mockWithdrawTransactionNotifier, | ||
}, | ||
MockTransactionNotifierWithNullData() => | ||
nullMockTransactionNotifier, | ||
MockTransactionNotifierWithError() => | ||
erroringMockTransactionNotifier, | ||
}, | ||
), | ||
], | ||
); | ||
|
||
testWidgets('should show correct payout and payin amounts', (tester) async { | ||
await tester.pumpWidget( | ||
transactionDetailsTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithSendTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find.text('100.01'), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets('should show transaction date', (tester) async { | ||
await tester.pumpWidget( | ||
transactionDetailsTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithSendTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find.text( | ||
DateFormat("MMM dd 'at' hh:mm a") | ||
.format(sendTransaction.createdAt.toLocal()), | ||
), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets('should show transaction status chip', (tester) async { | ||
await tester.pumpWidget( | ||
transactionDetailsTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithSendTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find.text('Order submitted'), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets('should display error when transaction fetch fails', | ||
(tester) async { | ||
await tester.pumpWidget( | ||
transactionDetailsTestWidget( | ||
mockTransactionNotifierType: mockTransactionNotifierWithError, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Bad state: Error loading transaction'), findsOneWidget); | ||
}); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters