From 793ceb581c437e52d24632f955980df44f1adee9 Mon Sep 17 00:00:00 2001 From: mohitrajsinha Date: Wed, 16 Oct 2024 02:20:29 +0530 Subject: [PATCH 1/5] Transaction detail page test added --- .../transaction_details_page_test.dart | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 test/features/transaction/transaction_details_page_test.dart diff --git a/test/features/transaction/transaction_details_page_test.dart b/test/features/transaction/transaction_details_page_test.dart new file mode 100644 index 00000000..867b42c7 --- /dev/null +++ b/test/features/transaction/transaction_details_page_test.dart @@ -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'; +import 'transaction_tile_test.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); + }); + }); +} From f6d989b8c61e55a313b0b13a0a73dc2944c74c35 Mon Sep 17 00:00:00 2001 From: mohitrajsinha Date: Thu, 17 Oct 2024 01:00:39 +0530 Subject: [PATCH 2/5] transaction_tile_test.dart removed --- .../transaction_details_page_test.dart | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/features/transaction/transaction_details_page_test.dart b/test/features/transaction/transaction_details_page_test.dart index 867b42c7..9c6d22ab 100644 --- a/test/features/transaction/transaction_details_page_test.dart +++ b/test/features/transaction/transaction_details_page_test.dart @@ -8,7 +8,6 @@ import 'package:intl/intl.dart'; import '../../helpers/mocks.dart'; import '../../helpers/test_data.dart'; import '../../helpers/widget_helpers.dart'; -import 'transaction_tile_test.dart'; void main() { group('TransactionDetailsPage', () { @@ -130,3 +129,21 @@ void main() { }); }); } + +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(); +} From c55fb934021319b5d69f812a64baf06b8bed909f Mon Sep 17 00:00:00 2001 From: mohitrajsinha Date: Thu, 17 Oct 2024 14:13:47 +0530 Subject: [PATCH 3/5] Duplicate code moved to mocks.dart --- .../transaction_details_page_test.dart | 20 +------------------ test/helpers/mocks.dart | 18 +++++++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/features/transaction/transaction_details_page_test.dart b/test/features/transaction/transaction_details_page_test.dart index 9c6d22ab..9648b1e4 100644 --- a/test/features/transaction/transaction_details_page_test.dart +++ b/test/features/transaction/transaction_details_page_test.dart @@ -128,22 +128,4 @@ void main() { expect(find.text('Bad state: Error loading transaction'), 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(); -} +} \ No newline at end of file diff --git a/test/helpers/mocks.dart b/test/helpers/mocks.dart index 64687fcb..2e87350e 100644 --- a/test/helpers/mocks.dart +++ b/test/helpers/mocks.dart @@ -79,3 +79,21 @@ class MockAccountBalanceNotifier @override FutureOr 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(); +} From f9930e7af29f945b47a5a32a18c3df18c66b09fa Mon Sep 17 00:00:00 2001 From: mohitrajsinha Date: Thu, 17 Oct 2024 19:20:19 +0530 Subject: [PATCH 4/5] update transaction_tile_test.dart Removed duplicate code. --- .../transaction/transaction_tile_test.dart | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/test/features/transaction/transaction_tile_test.dart b/test/features/transaction/transaction_tile_test.dart index 5e5b041f..9414b3f0 100644 --- a/test/features/transaction/transaction_tile_test.dart +++ b/test/features/transaction/transaction_tile_test.dart @@ -183,20 +183,3 @@ void main() { }); } -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(); -} From 6031d2de55450f25e58a8d2f6db56d04a236c013 Mon Sep 17 00:00:00 2001 From: mohitrajsinha Date: Fri, 18 Oct 2024 20:31:35 +0530 Subject: [PATCH 5/5] minor fixes --- .../transaction/transaction_details_page_test.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/features/transaction/transaction_details_page_test.dart b/test/features/transaction/transaction_details_page_test.dart index 9648b1e4..8ca25c74 100644 --- a/test/features/transaction/transaction_details_page_test.dart +++ b/test/features/transaction/transaction_details_page_test.dart @@ -80,7 +80,7 @@ void main() { expect( find.text('100.01'), findsOneWidget, - ); // Adjust to your currency setup. + ); }); testWidgets('should show transaction date', (tester) async { @@ -113,7 +113,7 @@ void main() { expect( find.text('Order submitted'), findsOneWidget, - ); // Adjust based on status + ); }); testWidgets('should display error when transaction fetch fails', @@ -128,4 +128,5 @@ void main() { expect(find.text('Bad state: Error loading transaction'), findsOneWidget); }); }); -} \ No newline at end of file +} +