This repository was 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
test: add tests for TransactionDetailsPage
#316
Merged
ethanwlee
merged 6 commits into
TBD54566975:main
from
mohitrajsinha:test/TransactionDetailsPage
Oct 18, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
793ceb5
Transaction detail page test added
mohitrajsinha f6d989b
transaction_tile_test.dart removed
mohitrajsinha c55fb93
Duplicate code moved to mocks.dart
mohitrajsinha f9930e7
update transaction_tile_test.dart
mohitrajsinha 5678043
Merge remote-tracking branch 'upstream/main' into test/TransactionDet…
mohitrajsinha 6031d2d
minor fixes
mohitrajsinha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
test/features/transaction/transaction_details_page_test.dart
This file contains hidden or 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,131 @@ | ||
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, | ||
); // Adjust to your currency setup. | ||
}); | ||
|
||
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, | ||
); // Adjust based on status | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add missing newline here! |
This file contains hidden or 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 | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,3 +79,21 @@ class MockAccountBalanceNotifier | |||||||||||||||||||||||||||||||||||
@override | ||||||||||||||||||||||||||||||||||||
FutureOr<AccountBalance?> build() async => accountBalance; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
sealed class MockTransactionNotifierType { | ||||||||||||||||||||||||||||||||||||
const MockTransactionNotifierType(); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
class MockTransactionNotifierWithData extends MockTransactionNotifierType { | ||||||||||||||||||||||||||||||||||||
const MockTransactionNotifierWithData({required this.transactionType}); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
final TransactionType transactionType; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
class MockTransactionNotifierWithNullData extends MockTransactionNotifierType { | ||||||||||||||||||||||||||||||||||||
const MockTransactionNotifierWithNullData(); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
class MockTransactionNotifierWithError extends MockTransactionNotifierType { | ||||||||||||||||||||||||||||||||||||
const MockTransactionNotifierWithError(); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
Comment on lines
+83
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines are still duplicated in didpay/test/features/transaction/transaction_tile_test.dart Lines 186 to 202 in 0bc1feb
They can be removed from the |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments in test file not required