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
test: add ui tests for TransactionTile
widget
#314
Merged
ethanwlee
merged 3 commits into
TBD54566975:main
from
victoreronmosele:tests-for-transaction-tile
Oct 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,205 @@ | ||
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:didpay/features/transaction/transaction_tile.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../../helpers/mocks.dart'; | ||
import '../../helpers/test_data.dart'; | ||
import '../../helpers/widget_helpers.dart'; | ||
|
||
void main() { | ||
group('TransactionTile', () { | ||
final pfi = TestData.getPfi('did:dht:pfiDid'); | ||
const exchangeId = 'rfq_01ha835rhefwmagsknrrhvaa0k'; | ||
|
||
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 mockTransactionNotifierWithDepositTransaction = | ||
MockTransactionNotifierWithData( | ||
transactionType: TransactionType.deposit, | ||
); | ||
const mockTransactionNotifierWithWithdrawTransaction = | ||
MockTransactionNotifierWithData( | ||
transactionType: TransactionType.withdraw, | ||
); | ||
const mockTransactionNotifierWithNullData = | ||
MockTransactionNotifierWithNullData(); | ||
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 transactionTileTestWidget({ | ||
required MockTransactionNotifierType mockTransactionNotifierType, | ||
}) => | ||
WidgetHelpers.testableWidget( | ||
child: TransactionTile( | ||
pfi: pfi, | ||
exchangeId: exchangeId, | ||
), | ||
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 paying and payout currencies', (tester) async { | ||
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: should be payin instead of paying 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. Thanks. Updating. |
||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithSendTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('AUD → BTC'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should show transaction status', (tester) async { | ||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithSendTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Order submitted'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should show error if transaction is null', (tester) async { | ||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: mockTransactionNotifierWithNullData, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('No transactions found'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should show error when transaction fetch returns an error', | ||
(tester) async { | ||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: mockTransactionNotifierWithError, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Bad state: Error loading transaction'), findsOneWidget); | ||
}); | ||
|
||
group('should show transaction amount in correct format for ', () { | ||
testWidgets('send transactions', (tester) async { | ||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithSendTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('-100.01 AUD'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('deposit transactions', (tester) async { | ||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithDepositTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('+0.12 BTC'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('withdraw transactions', (tester) async { | ||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithWithdrawTransaction, | ||
), | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('+100.01 AUD'), findsOneWidget); | ||
}); | ||
}); | ||
|
||
testWidgets('should navigate to transaction details page on tap', | ||
(tester) async { | ||
await tester.pumpWidget( | ||
transactionTileTestWidget( | ||
mockTransactionNotifierType: | ||
mockTransactionNotifierWithSendTransaction, | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
await tester.tap(find.widgetWithText(ListTile, 'AUD → BTC')); | ||
|
||
await tester.pumpAndSettle(); | ||
expect(find.byType(TransactionDetailsPage), findsOneWidget); | ||
}); | ||
}); | ||
} | ||
|
||
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(); | ||
} |
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
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.
is
exchangeId
being used for anything other than initializingtransactionTileTestWidget
? if not, this variable probably isn't necessaryThere 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.
It's only used to initialize the
TransactionTile
widget.I'll remove it the extra variable.