-
Notifications
You must be signed in to change notification settings - Fork 6
Add UI Tests for CurrencyDropdown Widget #312
Changes from 2 commits
149c5b2
6a2e10f
4821eb9
ebad7de
e75d4f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:didpay/features/currency/currency_dropdown.dart'; | ||
import 'package:didpay/features/payment/payment_amount_state.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../../helpers/test_data.dart'; | ||
import '../../helpers/widget_helpers.dart'; | ||
|
||
void main() async { | ||
await TestData.initializeDids(); | ||
|
||
late ValueNotifier<PaymentAmountState?> mockState; | ||
const testCurrency = 'USD'; | ||
|
||
setUp(() { | ||
// Initialize mockState with a non-null offeringsMap | ||
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. comments in test file are not required! |
||
mockState = ValueNotifier<PaymentAmountState?>( | ||
PaymentAmountState( | ||
offeringsMap: TestData.getOfferingsMap(), | ||
), // Use TestData as suggested | ||
); | ||
}); | ||
|
||
Widget createWidgetUnderTest() { | ||
return WidgetHelpers.testableWidget( | ||
// Use WidgetHelpers for consistent test setup | ||
child: CurrencyDropdown( | ||
paymentCurrency: testCurrency, | ||
state: mockState, | ||
), | ||
); | ||
} | ||
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. try to follow the existing test suite in terms of naming/initializing this widget (e.g. see payout_test.dart) |
||
|
||
testWidgets('CurrencyDropdown shows the correct initial currency', | ||
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. try updating the test descriptions to be consistent with the existing test suite |
||
(tester) async { | ||
await tester.pumpWidget(createWidgetUnderTest()); | ||
|
||
// Check if the currency label displays the initial currency | ||
expect(find.text(testCurrency), findsOneWidget); | ||
}); | ||
|
||
testWidgets('CurrencyDropdown opens the Select Currency modal when tapped', | ||
(tester) async { | ||
await tester.pumpWidget(createWidgetUnderTest()); | ||
|
||
// Tap on the currency dropdown button | ||
await tester.tap(find.text(testCurrency)); | ||
await tester.pumpAndSettle(); // Wait for the modal to open | ||
|
||
// Verify if the modal is displayed | ||
expect( | ||
find.text('Select currency'), | ||
findsOneWidget, | ||
); // Look for modal text or widget | ||
}); | ||
|
||
testWidgets('CurrencyDropdown updates state when a currency is selected', | ||
(tester) async { | ||
await tester.pumpWidget(createWidgetUnderTest()); | ||
|
||
// Open the modal by tapping on the currency dropdown button | ||
await tester.tap( | ||
find.text(testCurrency), | ||
); // Using the 'USD' label text to find the button | ||
await tester.pumpAndSettle(); | ||
|
||
// Simulate selecting a currency by updating the mockState directly | ||
const selectedCurrency = 'EUR'; | ||
mockState.value = PaymentAmountState( | ||
filterCurrency: | ||
selectedCurrency, // Assuming 'filterCurrency' is the correct field for currency selection | ||
); | ||
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. instead of updating |
||
|
||
await tester.pumpAndSettle(); | ||
|
||
// Verify the state reflects the selected currency | ||
expect(mockState.value?.filterCurrency, selectedCurrency); | ||
}); | ||
} |
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.
please remove this line as keys aren't being used in tests