Skip to content

Commit

Permalink
Merge pull request #13 from atn832/tests-77
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
atn832 authored Jul 7, 2024
2 parents 03fe1ad + 87a2c42 commit 739f727
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions test/language_picker_dropdown_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(home: Scaffold(body: LanguagePickerDropdown())));
expect(find.textContaining('Armenian'), findsOneWidget);
expect(find.textContaining('Japanese'), findsOneWidget);
expect(find.textContaining('Turkish'), findsOneWidget);

await tester.tap(find.byType(LanguagePickerDropdown));
await tester.pump(Duration(seconds: 1));
await tester.pump();

// As per https://stackoverflow.com/a/64496868, once the menu is open, there
// there are two widgets. Sometimes there is only one.
expect(
find.textContaining('Armenian', skipOffstage: false), findsNWidgets(2));
expect(
find.textContaining('Japanese', skipOffstage: false), findsNWidgets(1));
expect(
find.textContaining('Turkish', skipOffstage: false), findsNWidgets(1));
});

testWidgets(
Expand All @@ -32,10 +42,9 @@ void main() {

expect(find.textContaining('Japanese'), findsNothing);

// As per https://stackoverflow.com/a/64496868, once the menu is open, there
// there are two widgets, and we should tap the latter one.
expect(find.textContaining('French'), findsNWidgets(2));
await tester.tap(find.textContaining('French', skipOffstage: false).last);
// There used to be 2 widgets, but now there is only one.
expect(find.textContaining('French'), findsOneWidget);
await tester.tap(find.textContaining('French'));
expect(streamController.stream, emits(Languages.french));
streamController.close();
});
Expand All @@ -47,13 +56,12 @@ void main() {
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: picker)));
expect(find.textContaining('French'), findsOneWidget);
// Somehow French is pre-selected but English exists in the tree.
expect(find.textContaining('English'), findsOneWidget);
expect(find.textContaining('English'), findsNothing);
});

testWidgets('item builder', (WidgetTester tester) async {
final picker = LanguagePickerDropdown(
languages: [Languages.english, Languages.french],
languages: [Languages.french, Languages.english],
// Render only the iso code, not the name.
itemBuilder: (language) => Text(language.isoCode),
);
Expand Down

0 comments on commit 739f727

Please sign in to comment.