Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c476f8b3
Commit
c476f8b3
authored
Aug 26, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #866 from abarth/test_date_picker
Add a basic test for DatePicker
parents
f5fdc1cf
92e5a65d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
2 deletions
+94
-2
date_picker.dart
packages/flutter/lib/widgets/date_picker.dart
+0
-2
build_utils.dart
packages/unit/test/widget/build_utils.dart
+60
-0
date_picker_test.dart
packages/unit/test/widget/date_picker_test.dart
+34
-0
No files found.
packages/flutter/lib/widgets/date_picker.dart
View file @
c476f8b3
...
...
@@ -136,8 +136,6 @@ class DatePickerHeader extends Component {
TextStyle
dayStyle
=
headerTheme
.
display3
.
copyWith
(
color:
dayColor
,
height:
1.0
,
fontSize:
100.0
);
TextStyle
monthStyle
=
headerTheme
.
headline
.
copyWith
(
color:
dayColor
,
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
(
child:
new
BlockBody
([
...
...
packages/unit/test/widget/build_utils.dart
View file @
c476f8b3
import
'dart:sky'
as
sky
;
import
'package:sky/rendering.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
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
{
WidgetTester
()
{
_app
=
new
TestApp
();
...
...
@@ -49,6 +73,42 @@ class WidgetTester {
_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
)
{
_app
.
builder
=
builder
;
Component
.
flushBuild
();
...
...
packages/unit/test/widget/date_picker_test.dart
0 → 100644
View file @
c476f8b3
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
)));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment