Merge pull request #866 from abarth/test_date_picker
Add a basic test for DatePicker
This commit is contained in:
commit
c476f8b3d5
@ -136,8 +136,6 @@ class DatePickerHeader extends Component {
|
|||||||
TextStyle dayStyle = headerTheme.display3.copyWith(color: dayColor, height: 1.0, fontSize: 100.0);
|
TextStyle dayStyle = headerTheme.display3.copyWith(color: dayColor, height: 1.0, fontSize: 100.0);
|
||||||
TextStyle monthStyle = headerTheme.headline.copyWith(color: dayColor, height: 1.0);
|
TextStyle monthStyle = headerTheme.headline.copyWith(color: dayColor, height: 1.0);
|
||||||
TextStyle yearStyle = headerTheme.headline.copyWith(color: yearColor, height: 1.0);
|
TextStyle yearStyle = headerTheme.headline.copyWith(color: yearColor, height: 1.0);
|
||||||
DateTime firstDate = new DateTime(1900);
|
|
||||||
DateTime lastDate = new DateTime(2101);
|
|
||||||
|
|
||||||
return new Container(
|
return new Container(
|
||||||
child: new BlockBody([
|
child: new BlockBody([
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import 'dart:sky' as sky;
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:sky/rendering.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:sky/widgets.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
const Size _kTestViewSize = const Size(800.0, 600.0);
|
const Size _kTestViewSize = const Size(800.0, 600.0);
|
||||||
|
|
||||||
@ -30,6 +32,28 @@ class TestApp extends App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestGestureEvent extends sky.GestureEvent {
|
||||||
|
TestGestureEvent({
|
||||||
|
this.type,
|
||||||
|
this.primaryPointer,
|
||||||
|
this.x,
|
||||||
|
this.y,
|
||||||
|
this.dx,
|
||||||
|
this.dy,
|
||||||
|
this.velocityX,
|
||||||
|
this.velocityY
|
||||||
|
});
|
||||||
|
|
||||||
|
String type;
|
||||||
|
int primaryPointer;
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
double dx;
|
||||||
|
double dy;
|
||||||
|
double velocityX;
|
||||||
|
double velocityY;
|
||||||
|
}
|
||||||
|
|
||||||
class WidgetTester {
|
class WidgetTester {
|
||||||
WidgetTester() {
|
WidgetTester() {
|
||||||
_app = new TestApp();
|
_app = new TestApp();
|
||||||
@ -49,6 +73,42 @@ class WidgetTester {
|
|||||||
_app.walkChildren(walk);
|
_app.walkChildren(walk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget findWidget(bool predicate(Widget widget)) {
|
||||||
|
try {
|
||||||
|
walkWidgets((Widget widget) {
|
||||||
|
if (predicate(widget))
|
||||||
|
throw widget;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e is Widget)
|
||||||
|
return e;
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Text findText(String text) {
|
||||||
|
return findWidget((Widget widget) {
|
||||||
|
return widget is Text && widget.data == text;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Point getCenter(Widget widget) {
|
||||||
|
assert(widget != null);
|
||||||
|
RenderBox box = widget.renderObject as RenderBox;
|
||||||
|
assert(box != null);
|
||||||
|
return box.localToGlobal(box.size.center(Point.origin));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tap(Widget widget) {
|
||||||
|
dispatchEvent(new TestGestureEvent(type: 'gesturetap'), getCenter(widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispatchEvent(sky.Event event, Point position) {
|
||||||
|
HitTestResult result = SkyBinding.instance.hitTest(position);
|
||||||
|
SkyBinding.instance.dispatchEvent(event, result);
|
||||||
|
}
|
||||||
|
|
||||||
void pumpFrame(WidgetBuilder builder) {
|
void pumpFrame(WidgetBuilder builder) {
|
||||||
_app.builder = builder;
|
_app.builder = builder;
|
||||||
Component.flushBuild();
|
Component.flushBuild();
|
||||||
|
34
packages/unit/test/widget/date_picker_test.dart
Normal file
34
packages/unit/test/widget/date_picker_test.dart
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:sky/widgets.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import 'build_utils.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('Can select a day', () {
|
||||||
|
WidgetTester tester = new WidgetTester();
|
||||||
|
|
||||||
|
DateTime currentValue;
|
||||||
|
|
||||||
|
Widget builder() {
|
||||||
|
return new Block([
|
||||||
|
new DatePicker(
|
||||||
|
selectedDate: new DateTime.utc(2015, 6, 9, 7, 12),
|
||||||
|
firstDate: new DateTime.utc(2013),
|
||||||
|
lastDate: new DateTime.utc(2018),
|
||||||
|
onChanged: (DateTime dateTime) {
|
||||||
|
currentValue = dateTime;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tester.pumpFrame(builder);
|
||||||
|
// TODO(abarth): We shouldn't need to pump a second frame here.
|
||||||
|
tester.pumpFrame(builder);
|
||||||
|
|
||||||
|
expect(currentValue, isNull);
|
||||||
|
tester.tap(tester.findText('30'));
|
||||||
|
expect(currentValue, equals(new DateTime(2013, 1, 30)));
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user