flutter/packages/unit/test/widget/snack_bar_test.dart
Adam Barth 9bc64540c5 Improve hit testing
Now a RenderBox is considered hit if one of its children are hit or it itself
decides that it's hit. In particular, empty space inside a flex won't be hit
because none of the children are located there and a RenderFlex doesn't
consider itself hittable.

Fixes #53
Fixes #1221
2015-11-04 16:51:19 -08:00

46 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:test/test.dart';
import 'widget_tester.dart';
void main() {
test('SnackBar control test', () {
testWidgets((WidgetTester tester) {
String helloSnackBar = 'Hello SnackBar';
GlobalKey<PlaceholderState> placeholderKey = new GlobalKey<PlaceholderState>();
Key tapTarget = new Key('tap-target');
tester.pumpWidget(new MaterialApp(
routes: <String, RouteBuilder>{
'/': (RouteArguments args) {
return new GestureDetector(
onTap: () {
showSnackBar(
context: args.context,
placeholderKey: placeholderKey,
content: new Text(helloSnackBar)
);
},
child: new Container(
decoration: const BoxDecoration(
backgroundColor: const Color(0xFF00FF00)
),
child: new Center(
key: tapTarget,
child: new Placeholder(key: placeholderKey)
)
)
);
}
}
));
tester.tap(tester.findElementByKey(tapTarget));
expect(tester.findText(helloSnackBar), isNull);
tester.pump();
expect(tester.findText(helloSnackBar), isNotNull);
});
});
}