Skip to content

Instantly share code, notes, and snippets.

@natintosh
Created April 13, 2020 20:30
Show Gist options
  • Save natintosh/b7b40d75240a65fdb63942a4b36753e5 to your computer and use it in GitHub Desktop.
Save natintosh/b7b40d75240a65fdb63942a4b36753e5 to your computer and use it in GitHub Desktop.
Integration testing example for https://pub.dev/packages/intl_phone_number_input
import 'package:flutter_driver/driver_extension.dart';
import 'package:intlphonenumberinputtest/main.dart' as app;
main() {
enableFlutterDriverExtension();
app.main();
}
import 'package:flutter_driver/flutter_driver.dart';
import 'package:intl_phone_number_input/intl_phone_number_input_test.dart';
import 'package:test/test.dart';
main() {
group('International Phone Number Input', () {
final inputTextFieldFinder = find.byValueKey(TestHelper.TextInputKeyValue);
final dropdownButtonFinder =
find.byValueKey(TestHelper.DropdownButtonKeyValue);
final countrySearchInputFinder =
find.byValueKey(TestHelper.CountrySearchInputKeyValue);
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.connect();
});
tearDownAll(() async {
if (driver != null) {
driver.close();
}
});
test('Tap On TextField and enter text', () async {
await driver.tap(inputTextFieldFinder);
await driver.enterText('7012345678');
await driver.waitFor(find.text('701 234 5678'));
});
/// Test for
/// PhoneInputSelectorType.DROPDOWN
///
/// N.B Some values such as -18500 may vary on devices
///
test('Tap On Dropdown button', () async {
await driver.tap(dropdownButtonFinder);
await driver.waitFor(find.byType('Scrollable'));
});
test('Scroll to view and Select Country', () async {
await driver.scroll(
dropdownButtonFinder, 0, -16000, Duration(milliseconds: 300));
await driver.tap(find.byValueKey(TestHelper.countryItemKeyValue('US')));
});
test('Update Textfield After new Item selected', () async {
await driver.waitFor(inputTextFieldFinder);
await driver.tap(inputTextFieldFinder);
await driver.enterText('');
await driver.enterText('5555555555');
await driver.waitFor(find.text('555-555-5555'));
});
/// Test for
/// PhoneInputSelectorType.BOTTOM_SHEET and
/// PhoneInputSelectorType.DIALOG
///
/// N.B Some values such as -18500 may vary on devices and
/// PhoneInputSelectorType
///
test('Tap On Dropdown button', () async {
await driver.tap(dropdownButtonFinder);
await driver.waitFor(find.byType('Scrollable'));
});
test('Scroll to view and Select Country', () async {
await driver.scroll(find.byType('SingleChildScrollView'), 0, -18500,
Duration(milliseconds: 300));
await driver.tap(find.byValueKey(TestHelper.countryItemKeyValue('US')));
});
test('Update Textfield After new Item selected', () async {
await driver.waitFor(inputTextFieldFinder);
await driver.tap(inputTextFieldFinder);
await driver.enterText('');
await driver.enterText('5555555555');
await driver.waitFor(find.text('555-555-5555'));
});
test('Tap On Dropdown button', () async {
await driver.tap(dropdownButtonFinder);
await driver.waitFor(find.byType('Scrollable'));
});
test('Search for country', () async {
await driver.tap(countrySearchInputFinder);
await driver.enterText('United State');
});
test('Tap on Searched country', () async {
await driver.tap(find.byValueKey(TestHelper.countryItemKeyValue('US')));
});
test('Update Textfield After new Item selected', () async {
await driver.waitFor(inputTextFieldFinder);
await driver.tap(inputTextFieldFinder);
await driver.enterText('');
await driver.enterText('5555555555');
await driver.waitFor(find.text('555-555-5555'));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment