Skip to content

Commit

Permalink
OpenContainer test should not depend on impl. details of Switch (flut…
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Mar 1, 2021
1 parent 45f3b99 commit 60e31ec
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions packages/animations/test/open_container_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,7 @@ void main() {
return const Text('Closed');
},
openBuilder: (BuildContext context, VoidCallback action) {
return Switch(
value: true,
onChanged: (bool v) {},
);
return const DummyStatefulWidget();
},
),
),
Expand All @@ -786,20 +783,20 @@ void main() {
await tester.tap(find.text('Closed'));
await tester.pump(const Duration(milliseconds: 200));

final State stateOpening = tester.state(find.byType(Switch));
final State stateOpening = tester.state(find.byType(DummyStatefulWidget));
expect(stateOpening, isNotNull);

await tester.pumpAndSettle();
expect(find.text('Closed'), findsNothing);
final State stateOpen = tester.state(find.byType(Switch));
final State stateOpen = tester.state(find.byType(DummyStatefulWidget));
expect(stateOpen, isNotNull);
expect(stateOpen, same(stateOpening));

final NavigatorState navigator = tester.state(find.byType(Navigator));
navigator.pop();
await tester.pump(const Duration(milliseconds: 200));
expect(find.text('Closed'), findsOneWidget);
final State stateClosing = tester.state(find.byType(Switch));
final State stateClosing = tester.state(find.byType(DummyStatefulWidget));
expect(stateClosing, isNotNull);
expect(stateClosing, same(stateOpen));
});
Expand All @@ -811,10 +808,7 @@ void main() {
child: OpenContainer(
closedBuilder: (BuildContext context, VoidCallback action) {
open = action;
return Switch(
value: true,
onChanged: (bool v) {},
);
return const DummyStatefulWidget();
},
openBuilder: (BuildContext context, VoidCallback action) {
return const Text('Open');
Expand All @@ -823,21 +817,21 @@ void main() {
),
));

final State stateClosed = tester.state(find.byType(Switch));
final State stateClosed = tester.state(find.byType(DummyStatefulWidget));
expect(stateClosed, isNotNull);

open();
await tester.pump(const Duration(milliseconds: 200));
expect(find.text('Open'), findsOneWidget);

final State stateOpening = tester.state(find.byType(Switch));
final State stateOpening = tester.state(find.byType(DummyStatefulWidget));
expect(stateOpening, same(stateClosed));

await tester.pumpAndSettle();
expect(find.byType(Switch), findsNothing);
expect(find.byType(DummyStatefulWidget), findsNothing);
expect(find.text('Open'), findsOneWidget);
final State stateOpen = tester.state(find.byType(
Switch,
DummyStatefulWidget,
skipOffstage: false,
));
expect(stateOpen, same(stateOpening));
Expand All @@ -846,12 +840,13 @@ void main() {
navigator.pop();
await tester.pump(const Duration(milliseconds: 200));
expect(find.text('Open'), findsOneWidget);
final State stateClosing = tester.state(find.byType(Switch));
final State stateClosing = tester.state(find.byType(DummyStatefulWidget));
expect(stateClosing, same(stateOpen));

await tester.pumpAndSettle();
expect(find.text('Open'), findsNothing);
final State stateClosedAgain = tester.state(find.byType(Switch));
final State stateClosedAgain =
tester.state(find.byType(DummyStatefulWidget));
expect(stateClosedAgain, same(stateClosing));
});

Expand Down Expand Up @@ -1966,3 +1961,15 @@ class __RemoveOpenContainerExampleState
);
}
}

class DummyStatefulWidget extends StatefulWidget {
const DummyStatefulWidget({Key? key}) : super(key: key);

@override
State<StatefulWidget> createState() => DummyState();
}

class DummyState extends State<DummyStatefulWidget> {
@override
Widget build(BuildContext context) => const SizedBox.expand();
}

0 comments on commit 60e31ec

Please sign in to comment.