Skip to content

Commit

Permalink
[Murat] Add country picker height extension tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Murat Gun committed Nov 21, 2023
1 parent a476f05 commit c9029b4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
66 changes: 65 additions & 1 deletion test/component/country_picker_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'mocks/country_picker_button.dart';

void main() {
const CountryPickerButtonMock mockWidget = CountryPickerButtonMock(menuType: PickerMenuType.bottomSheet);
CountryPickerButtonMock mockWidget =
CountryPickerButtonMock(menuType: PickerMenuType.bottomSheet, pickerHeight: CountryPickerHeigth.h25);
testWidgets('should CountryPickerButton widget renders successfully', (widgetTester) async {
await widgetTester.pumpWidget(mockWidget);
expect(find.byType(CountryPickerButton), findsOneWidget);
Expand Down Expand Up @@ -37,4 +38,67 @@ void main() {

expect(find.byType(CountryPickerMenu), findsOneWidget);
});

testWidgets('should country picker size as expected if pickerHeight CountryPickerHeigth.h25', (widgetTester) async {
await widgetTester.pumpWidget(mockWidget);

await widgetTester.tap(find.byType(CountryPickerButton));
await widgetTester.pumpAndSettle();

expect(find.byType(CountryPickerMenu), findsOneWidget);

final CountryPickerMenu menu = widgetTester.firstWidget(find.byType(CountryPickerMenu));
expect(
menu.height,
MediaQuery.of(mockWidget.ctx!).size.height * .25,
);
});

testWidgets('should country picker size as expected if pickerHeight CountryPickerHeigth.h50', (widgetTester) async {
mockWidget = CountryPickerButtonMock(menuType: PickerMenuType.bottomSheet, pickerHeight: CountryPickerHeigth.h50);
await widgetTester.pumpWidget(mockWidget);

await widgetTester.tap(find.byType(CountryPickerButton));
await widgetTester.pumpAndSettle();

expect(find.byType(CountryPickerMenu), findsOneWidget);

final CountryPickerMenu menu = widgetTester.firstWidget(find.byType(CountryPickerMenu));
expect(
menu.height,
MediaQuery.of(mockWidget.ctx!).size.height * .50,
);
});

testWidgets('should country picker size as expected if pickerHeight CountryPickerHeigth.h75', (widgetTester) async {
mockWidget = CountryPickerButtonMock(menuType: PickerMenuType.bottomSheet, pickerHeight: CountryPickerHeigth.h75);
await widgetTester.pumpWidget(mockWidget);

await widgetTester.tap(find.byType(CountryPickerButton));
await widgetTester.pumpAndSettle();

expect(find.byType(CountryPickerMenu), findsOneWidget);

final CountryPickerMenu menu = widgetTester.firstWidget(find.byType(CountryPickerMenu));
expect(
menu.height,
MediaQuery.of(mockWidget.ctx!).size.height * .75,
);
});

testWidgets('should country picker size as expected if pickerHeight CountryPickerHeigth.h100', (widgetTester) async {
mockWidget = CountryPickerButtonMock(menuType: PickerMenuType.bottomSheet, pickerHeight: CountryPickerHeigth.h100);
await widgetTester.pumpWidget(mockWidget);

await widgetTester.tap(find.byType(CountryPickerButton));
await widgetTester.pumpAndSettle();

expect(find.byType(CountryPickerMenu), findsOneWidget);

final CountryPickerMenu menu = widgetTester.firstWidget(find.byType(CountryPickerMenu));
expect(
menu.height,
MediaQuery.of(mockWidget.ctx!).size.height,
);
});
}
11 changes: 5 additions & 6 deletions test/component/mocks/country_picker_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import 'package:ephone_field/src/enums/ephone_textfield_type.dart';
import 'package:flutter/material.dart';

class CountryPickerButtonMock extends StatelessWidget {
const CountryPickerButtonMock({
Key? key,
required this.menuType,
}) : super(key: key);
CountryPickerButtonMock({Key? key, required this.menuType, required this.pickerHeight, this.ctx}) : super(key: key);
final List<Country> countries = Country.values;
final String title = "Select Country";
final bool isSearchable = true;
Expand All @@ -22,10 +19,12 @@ class CountryPickerButtonMock extends StatelessWidget {
final Country initialValue = Country.afghanistan;
final EphoneFieldType initialType = EphoneFieldType.phone;
final PickerMenuType menuType;
final CountryPickerHeigth pickerHeight = CountryPickerHeigth.h75;
final CountryPickerHeigth pickerHeight;
BuildContext? ctx;

@override
Widget build(BuildContext context) {
ctx = context;
return MaterialApp(
home: Scaffold(
body: SizedBox(
Expand All @@ -40,7 +39,7 @@ class CountryPickerButtonMock extends StatelessWidget {
onValuePicked: (Country c) {},
initialValue: initialValue,
menuType: menuType,
pickerHeight: menuType == PickerMenuType.page ? CountryPickerHeigth.h100 : CountryPickerHeigth.h50,
pickerHeight: menuType == PickerMenuType.page ? CountryPickerHeigth.h100 : pickerHeight,
),
),
),
Expand Down
3 changes: 1 addition & 2 deletions test/component/mocks/country_picker_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class CountryPickerMenuMock extends StatelessWidget {
hintText: 'hintText',
);
// ignore: prefer_function_declarations_over_variables
final Widget Function(Country) itemBuilder =
(Country c) => CountryCard(country: c);
final Widget Function(Country) itemBuilder = (Country c) => CountryCard(country: c);
// ignore: prefer_function_declarations_over_variables
final void Function(Country) onValuePicked = (Country c) {
if (kDebugMode) {
Expand Down

0 comments on commit c9029b4

Please sign in to comment.