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
fbd5460b
Commit
fbd5460b
authored
Oct 01, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate WidgetTester with FakeAsync
Fixes #1084
parent
67feb40c
Changes
34
Show whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
2022 additions
and
2060 deletions
+2022
-2060
align_test.dart
packages/unit/test/widget/align_test.dart
+16
-17
block_test.dart
packages/unit/test/widget/block_test.dart
+48
-48
box_decoration_test.dart
packages/unit/test/widget/box_decoration_test.dart
+11
-12
build_scope_test.dart
packages/unit/test/widget/build_scope_test.dart
+36
-36
center_test.dart
packages/unit/test/widget/center_test.dart
+3
-4
coordinates_test.dart
packages/unit/test/widget/coordinates_test.dart
+32
-32
date_picker_test.dart
packages/unit/test/widget/date_picker_test.dart
+22
-22
dismissable_test.dart
packages/unit/test/widget/dismissable_test.dart
+120
-119
draggable_test.dart
packages/unit/test/widget/draggable_test.dart
+52
-52
duplicate_key_test.dart
packages/unit/test/widget/duplicate_key_test.dart
+10
-9
flex_test.dart
packages/unit/test/widget/flex_test.dart
+33
-33
gesture_detector_test.dart
packages/unit/test/widget/gesture_detector_test.dart
+71
-69
homogeneous_viewport_test.dart
packages/unit/test/widget/homogeneous_viewport_test.dart
+132
-132
input_test.dart
packages/unit/test/widget/input_test.dart
+40
-43
listener_test.dart
packages/unit/test/widget/listener_test.dart
+25
-25
mixed_viewport_test.dart
packages/unit/test/widget/mixed_viewport_test.dart
+111
-114
multichild_test.dart
packages/unit/test/widget/multichild_test.dart
+252
-250
navigator_test.dart
packages/unit/test/widget/navigator_test.dart
+23
-25
pageable_list_test.dart
packages/unit/test/widget/pageable_list_test.dart
+47
-45
parent_data_test.dart
packages/unit/test/widget/parent_data_test.dart
+212
-212
progress_indicator_test.dart
packages/unit/test/widget/progress_indicator_test.dart
+7
-7
render_object_widget_test.dart
packages/unit/test/widget/render_object_widget_test.dart
+115
-113
scrollable_list_hit_testing_test.dart
...es/unit/test/widget/scrollable_list_hit_testing_test.dart
+78
-76
scrollable_list_horizontal_test.dart
...ges/unit/test/widget/scrollable_list_horizontal_test.dart
+113
-124
scrollable_list_vertical_test.dart
packages/unit/test/widget/scrollable_list_vertical_test.dart
+40
-44
set_state_3_test.dart
packages/unit/test/widget/set_state_3_test.dart
+6
-5
set_state_test.dart
packages/unit/test/widget/set_state_test.dart
+9
-8
snap_scrolling_test.dart
packages/unit/test/widget/snap_scrolling_test.dart
+31
-63
stack_test.dart
packages/unit/test/widget/stack_test.dart
+51
-52
stateful_component_test.dart
packages/unit/test/widget/stateful_component_test.dart
+57
-56
stateful_components_test.dart
packages/unit/test/widget/stateful_components_test.dart
+30
-31
syncing_test.dart
packages/unit/test/widget/syncing_test.dart
+131
-135
transform_test.dart
packages/unit/test/widget/transform_test.dart
+37
-37
widget_tester.dart
packages/unit/test/widget/widget_tester.dart
+21
-10
No files found.
packages/unit/test/widget/align_test.dart
View file @
fbd5460b
...
...
@@ -5,9 +5,8 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Align smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Align
(
child:
new
Container
(),
horizontal:
0.75
,
...
...
@@ -15,13 +14,13 @@ void main() {
)
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Align
(
child:
new
Container
(),
horizontal:
0.5
,
vertical:
0.5
)
);
});
});
}
packages/unit/test/widget/block_test.dart
View file @
fbd5460b
...
...
@@ -8,9 +8,8 @@ final Key blockKey = new Key('test');
void
main
(
)
{
test
(
'Cannot scroll a non-overflowing block'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Block
([
new
Container
(
height:
200.0
,
// less than 600, the height of the test area
...
...
@@ -19,7 +18,7 @@ void main() {
],
key:
blockKey
)
);
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
tester
.
pump
();
// for SizeObservers
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementByKey
(
blockKey
));
...
...
@@ -27,17 +26,17 @@ void main() {
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
pumpFrameWithoutChange
(
1.0
);
tester
.
pump
(
const
Duration
(
milliseconds:
1
)
);
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isTrue
);
tester
.
dispatchEvent
(
pointer
.
up
(),
target
);
});
});
test
(
'Can scroll an overflowing block'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Block
([
new
Container
(
height:
2000.0
,
// more than 600, the height of the test area
...
...
@@ -46,7 +45,7 @@ void main() {
],
key:
blockKey
)
);
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
tester
.
pump
();
// for SizeObservers
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementByKey
(
blockKey
));
...
...
@@ -54,10 +53,11 @@ void main() {
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
pumpFrameWithoutChange
(
1.0
);
tester
.
pump
(
const
Duration
(
milliseconds:
1
)
);
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isFalse
);
tester
.
dispatchEvent
(
pointer
.
up
(),
target
);
});
});
}
packages/unit/test/widget/box_decoration_test.dart
View file @
fbd5460b
...
...
@@ -6,9 +6,8 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Circles can have uniform borders'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Container
(
padding:
new
EdgeDims
.
all
(
50.0
),
decoration:
new
BoxDecoration
(
...
...
@@ -18,6 +17,6 @@ void main() {
)
)
);
});
});
}
packages/unit/test/widget/build_scope_test.dart
View file @
fbd5460b
...
...
@@ -80,47 +80,47 @@ void main() {
});
test
(
'Legal times for setState'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
GlobalKey
flipKey
=
new
GlobalKey
();
expect
(
ProbeWidgetState
.
buildCount
,
equals
(
0
));
tester
.
pumpFrame
(
new
ProbeWidget
());
tester
.
pumpWidget
(
new
ProbeWidget
());
expect
(
ProbeWidgetState
.
buildCount
,
equals
(
1
));
tester
.
pumpFrame
(
new
ProbeWidget
());
tester
.
pumpWidget
(
new
ProbeWidget
());
expect
(
ProbeWidgetState
.
buildCount
,
equals
(
2
));
tester
.
pumpFrame
(
new
FlipComponent
(
tester
.
pumpWidget
(
new
FlipComponent
(
key:
flipKey
,
left:
new
Container
(),
right:
new
ProbeWidget
()
));
expect
(
ProbeWidgetState
.
buildCount
,
equals
(
2
));
(
flipKey
.
currentState
as
FlipComponentState
).
flip
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
ProbeWidgetState
.
buildCount
,
equals
(
3
));
(
flipKey
.
currentState
as
FlipComponentState
).
flip
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
ProbeWidgetState
.
buildCount
,
equals
(
3
));
tester
.
pumpFrame
(
new
Container
());
tester
.
pumpWidget
(
new
Container
());
expect
(
ProbeWidgetState
.
buildCount
,
equals
(
3
));
});
});
test
(
'Setting parent state during build is forbidden'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
expect
(
cachedException
,
isNull
);
tester
.
pumpFrame
(
new
BadWidgetParent
());
tester
.
pumpWidget
(
new
BadWidgetParent
());
expect
(
cachedException
,
isNotNull
);
cachedException
=
null
;
tester
.
pumpFrame
(
new
Container
());
tester
.
pumpWidget
(
new
Container
());
expect
(
cachedException
,
isNull
);
});
});
test
(
'Setting state during dispose is forbidden'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
BadDisposeWidget
());
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
BadDisposeWidget
());
expect
(()
{
tester
.
pumpFrame
(
new
Container
());
tester
.
pumpWidget
(
new
Container
());
},
throws
);
});
});
}
packages/unit/test/widget/center_test.dart
View file @
fbd5460b
...
...
@@ -5,9 +5,8 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Can be placed in an infinte box'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
Block
([
new
Center
()])
);
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Block
([
new
Center
()]));
}
);
});
}
packages/unit/test/widget/coordinates_test.dart
View file @
fbd5460b
...
...
@@ -6,12 +6,11 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Comparing coordinates'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
Key
keyA
=
new
GlobalKey
();
Key
keyB
=
new
GlobalKey
();
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
top:
100.0
,
...
...
@@ -43,4 +42,5 @@ void main() {
expect
((
tester
.
findElementByKey
(
keyB
).
renderObject
as
RenderBox
).
globalToLocal
(
const
Point
(
110.0
,
205.0
)),
equals
(
const
Point
(
10.0
,
5.0
)));
});
});
}
packages/unit/test/widget/date_picker_test.dart
View file @
fbd5460b
...
...
@@ -5,8 +5,7 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Can select a day'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
DateTime
currentValue
;
Widget
widget
=
new
Block
([
...
...
@@ -20,15 +19,16 @@ void main() {
)
]);
tester
.
pumpFrame
(
widget
);
tester
.
pumpWidget
(
widget
);
expect
(
currentValue
,
isNull
);
tester
.
tap
(
tester
.
findText
(
'2015'
));
tester
.
pumpFrame
(
widget
);
tester
.
pumpWidget
(
widget
);
tester
.
tap
(
tester
.
findText
(
'2014'
));
tester
.
pumpFrame
(
widget
);
tester
.
pumpWidget
(
widget
);
expect
(
currentValue
,
equals
(
new
DateTime
(
2014
,
6
,
9
)));
tester
.
tap
(
tester
.
findText
(
'30'
));
expect
(
currentValue
,
equals
(
new
DateTime
(
2013
,
1
,
30
)));
});
});
}
packages/unit/test/widget/dismissable_test.dart
View file @
fbd5460b
import
'package:quiver/testing/async.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
...
...
@@ -86,24 +85,19 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
downLocation
);
tester
.
dispatchEvent
(
pointer
.
up
(),
downLocation
);
double
t0
=
0.0
;
new
FakeAsync
().
run
((
async
)
{
tester
.
pumpFrame
(
widgetBuilder
(),
t0
);
// start the resize animation
tester
.
pumpFrame
(
widgetBuilder
(),
t0
+
1000.0
);
// finish the resize animation
async
.
elapse
(
new
Duration
(
seconds:
1
));
tester
.
pumpFrame
(
widgetBuilder
(),
t0
+
2000.0
);
// dismiss
async
.
elapse
(
new
Duration
(
seconds:
1
));
});
tester
.
pumpWidget
(
widgetBuilder
());
// start the resize animation
tester
.
pumpWidget
(
widgetBuilder
(),
const
Duration
(
seconds:
1
));
// finish the resize animation
tester
.
pumpWidget
(
widgetBuilder
(),
const
Duration
(
seconds:
1
));
// dismiss
}
void
main
(
)
{
test
(
'Horizontal drag triggers dismiss scrollDirection=vertical'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
scrollDirection
=
ScrollDirection
.
vertical
;
dismissDirection
=
DismissDirection
.
horizontal
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
...
...
@@ -114,14 +108,15 @@ void main() {
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
});
});
test
(
'Vertical drag triggers dismiss scrollDirection=horizontal'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
vertical
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
...
...
@@ -132,14 +127,15 @@ void main() {
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
});
});
test
(
'drag-left with DismissDirection.left triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
scrollDirection
=
ScrollDirection
.
vertical
;
dismissDirection
=
DismissDirection
.
left
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
...
...
@@ -150,14 +146,15 @@ void main() {
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
});
test
(
'drag-right with DismissDirection.right triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
scrollDirection
=
ScrollDirection
.
vertical
;
dismissDirection
=
DismissDirection
.
right
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
left
);
...
...
@@ -168,14 +165,15 @@ void main() {
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
});
test
(
'drag-up with DismissDirection.up triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
up
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
down
);
...
...
@@ -186,14 +184,15 @@ void main() {
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
});
test
(
'drag-down with DismissDirection.down triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
down
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
...
...
@@ -204,16 +203,17 @@ void main() {
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
});
// This is a regression test for
// https://github.com/domokit/sky_engine/issues/1068
test
(
'Verify that drag-move events do not assert'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
down
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
Element
itemElement
=
tester
.
findText
(
'0'
);
TestPointer
pointer
=
new
TestPointer
(
5
);
...
...
@@ -221,12 +221,13 @@ void main() {
Offset
offset
=
new
Offset
(
0.0
,
5.0
);
tester
.
dispatchEvent
(
pointer
.
down
(
location
),
location
);
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
offset
),
location
);
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
2.0
)),
location
);
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
3.0
)),
location
);
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
4.0
)),
location
);
tester
.
pumpFrame
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
});
});
}
packages/unit/test/widget/draggable_test.dart
View file @
fbd5460b
...
...
@@ -6,12 +6,12 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Drag and drop - control test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
TestPointer
pointer
=
new
TestPointer
(
7
);
List
accepted
=
[];
tester
.
pumpFrame
(
new
Navigator
(
tester
.
pumpWidget
(
new
Navigator
(
routes:
{
'/'
:
(
NavigatorState
navigator
,
Route
route
)
{
return
new
Column
([
new
Draggable
(
...
...
@@ -43,7 +43,7 @@ void main() {
Point
firstLocation
=
tester
.
getCenter
(
tester
.
findText
(
'Source'
));
tester
.
dispatchEvent
(
pointer
.
down
(
firstLocation
),
firstLocation
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
...
...
@@ -52,7 +52,7 @@ void main() {
Point
secondLocation
=
tester
.
getCenter
(
tester
.
findText
(
'Target'
));
tester
.
dispatchEvent
(
pointer
.
move
(
secondLocation
),
firstLocation
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
...
...
@@ -60,12 +60,12 @@ void main() {
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
tester
.
dispatchEvent
(
pointer
.
up
(),
firstLocation
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
accepted
,
equals
([
1
]));
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
});
});
}
packages/unit/test/widget/duplicate_key_test.dart
View file @
fbd5460b
...
...
@@ -42,14 +42,15 @@ Widget builder() {
void
main
(
)
{
test
(
'duplicate key smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
builder
());
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
builder
());
StatefulLeafState
leaf
=
tester
.
findStateOfType
(
StatefulLeafState
);
leaf
.
test
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
Item
lastItem
=
items
[
1
];
items
.
remove
(
lastItem
);
items
.
insert
(
0
,
lastItem
);
tester
.
pumpFrame
(
builder
());
// this marks the app dirty and rebuilds it
tester
.
pumpWidget
(
builder
());
// this marks the app dirty and rebuilds it
});
});
}
packages/unit/test/widget/flex_test.dart
View file @
fbd5460b
...
...
@@ -5,10 +5,9 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Can hit test flex children of stacks'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
bool
didReceiveTap
=
false
;
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Container
(
decoration:
const
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
)
...
...
@@ -42,4 +41,5 @@ void main() {
tester
.
tap
(
tester
.
findText
(
'X'
));
expect
(
didReceiveTap
,
isTrue
);
});
});
}
packages/unit/test/widget/gesture_detector_test.dart
View file @
fbd5460b
...
...
@@ -6,7 +6,7 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Uncontested scrolls start immediately'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
TestPointer
pointer
=
new
TestPointer
(
7
);
bool
didStartDrag
=
false
;
...
...
@@ -26,7 +26,7 @@ void main() {
child:
new
Container
()
);
tester
.
pumpFrame
(
widget
);
tester
.
pumpWidget
(
widget
);
expect
(
didStartDrag
,
isFalse
);
expect
(
updatedDragDelta
,
isNull
);
expect
(
didEndDrag
,
isFalse
);
...
...
@@ -51,11 +51,12 @@ void main() {
expect
(
didEndDrag
,
isTrue
);
didEndDrag
=
false
;
tester
.
pumpFrame
(
new
Container
());
tester
.
pumpWidget
(
new
Container
());
});
});
test
(
'Match two scroll gestures in succession'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
TestPointer
pointer
=
new
TestPointer
(
7
);
int
gestureCount
=
0
;
...
...
@@ -71,7 +72,7 @@ void main() {
onHorizontalDragEnd:
(
Offset
velocity
)
{
fail
(
"gesture should not match"
);
},
child:
new
Container
()
);
tester
.
pumpFrame
(
widget
);
tester
.
pumpWidget
(
widget
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
downLocation
);
...
...
@@ -84,6 +85,7 @@ void main() {
expect
(
gestureCount
,
2
);
expect
(
dragDistance
,
20.0
);
tester
.
pumpFrame
(
new
Container
());
tester
.
pumpWidget
(
new
Container
());
});
});
}
packages/unit/test/widget/homogeneous_viewport_test.dart
View file @
fbd5460b
...
...
@@ -6,8 +6,7 @@ import 'test_widgets.dart';
void
main
(
)
{
test
(
'HomogeneousViewport mount/dismount smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
...
...
@@ -35,7 +34,7 @@ void main() {
);
}
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
StatefulComponentElement
element
=
tester
.
findElement
((
element
)
=>
element
.
widget
is
FlipComponent
);
FlipComponentState
testComponent
=
element
.
state
;
...
...
@@ -44,20 +43,20 @@ void main() {
callbackTracker
.
clear
();
testComponent
.
flip
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
callbackTracker
,
equals
([]));
callbackTracker
.
clear
();
testComponent
.
flip
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
});
});
test
(
'HomogeneousViewport vertical'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
...
...
@@ -93,7 +92,7 @@ void main() {
return
testComponent
;
}
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
expect
(
callbackTracker
,
equals
([
1
,
2
,
3
,
4
]));
...
...
@@ -101,16 +100,16 @@ void main() {
offset
=
400.0
;
// now only 3 should fit, numbered 2-4.
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
expect
(
callbackTracker
,
equals
([
2
,
3
,
4
]));
callbackTracker
.
clear
();
});
});
test
(
'HomogeneousViewport horizontal'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
...
...
@@ -147,7 +146,7 @@ void main() {
return
testComponent
;
}
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
expect
(
callbackTracker
,
equals
([
1
,
2
,
3
,
4
,
5
]));
...
...
@@ -155,10 +154,11 @@ void main() {
offset
=
400.0
;
// now only 4 should fit, numbered 2-5.
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
expect
(
callbackTracker
,
equals
([
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
});
});
}
packages/unit/test/widget/input_test.dart
View file @
fbd5460b
import
'package:mojo_services/keyboard/keyboard.mojom.dart'
;
import
'package:quiver/testing/async.dart'
;
import
'package:sky/rendering.dart'
;
import
'package:sky/services.dart'
;
import
'package:sky/widgets.dart'
;
...
...
@@ -25,8 +24,7 @@ void main() {
serviceMocker
.
registerMockService
(
KeyboardServiceName
,
mockKeyboard
);
test
(
'Editable text has consistent width'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
GlobalKey
inputKey
=
new
GlobalKey
();
String
inputValue
;
...
...
@@ -40,7 +38,7 @@ void main() {
);
}
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
Element
input
=
tester
.
findElementByKey
(
inputKey
);
Size
emptyInputSize
=
(
input
.
renderObject
as
RenderBox
).
size
;
...
...
@@ -53,15 +51,15 @@ void main() {
// Check that the onChanged event handler fired.
expect
(
inputValue
,
equals
(
testValue
));
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
// Check that the Input with text has the same size as the empty Input.
expect
((
input
.
renderObject
as
RenderBox
).
size
,
equals
(
emptyInputSize
));
});
});
test
(
'Cursor blinks'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
GlobalKey
inputKey
=
new
GlobalKey
();
Widget
builder
()
{
...
...
@@ -73,17 +71,16 @@ void main() {
);
}
new
FakeAsync
().
run
((
async
)
{
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
EditableTextState
editableText
=
tester
.
findStateOfType
(
EditableTextState
);
// Check that the cursor visibility toggles after each blink interval.
void
checkCursorToggle
()
{
bool
initialShowCursor
=
editableText
.
test_showCursor
;
async
.
elapse
(
editableText
.
test_cursorBlinkPeriod
);
tester
.
async
.
elapse
(
editableText
.
test_cursorBlinkPeriod
);
expect
(
editableText
.
test_showCursor
,
equals
(!
initialShowCursor
));
async
.
elapse
(
editableText
.
test_cursorBlinkPeriod
);
tester
.
async
.
elapse
(
editableText
.
test_cursorBlinkPeriod
);
expect
(
editableText
.
test_showCursor
,
equals
(
initialShowCursor
));
}
...
...
packages/unit/test/widget/listener_test.dart
View file @
fbd5460b
...
...
@@ -5,11 +5,10 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Events bubble up the tree'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
List
<
String
>
log
=
new
List
<
String
>();
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Listener
(
onPointerDown:
(
_
)
{
log
.
add
(
'top'
);
...
...
@@ -39,4 +38,5 @@ void main() {
'top'
,
]));
});
});
}
packages/unit/test/widget/mixed_viewport_test.dart
View file @
fbd5460b
...
...
@@ -6,8 +6,7 @@ import 'test_widgets.dart';
void
main
(
)
{
test
(
'MixedViewport mount/dismount smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
...
...
@@ -30,7 +29,7 @@ void main() {
);
}
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
StatefulComponentElement
element
=
tester
.
findElement
((
element
)
=>
element
.
widget
is
FlipComponent
);
FlipComponentState
testComponent
=
element
.
state
;
...
...
@@ -39,21 +38,20 @@ void main() {
callbackTracker
.
clear
();
testComponent
.
flip
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
callbackTracker
,
equals
([]));
callbackTracker
.
clear
();
testComponent
.
flip
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
});
});
test
(
'MixedViewport vertical'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
...
...
@@ -82,7 +80,7 @@ void main() {
);
}
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
// 0 is built to find its width
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
]));
...
...
@@ -91,18 +89,17 @@ void main() {
offset
=
400.0
;
// now only 3 should fit, numbered 2-4.
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
// 0 and 1 aren't built, we know their size and nothing else changed
expect
(
callbackTracker
,
equals
([
2
,
3
,
4
]));
callbackTracker
.
clear
();
});
});
test
(
'MixedViewport horizontal'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
...
...
@@ -132,7 +129,7 @@ void main() {
);
}
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
// 0 is built to find its width
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
...
...
@@ -141,12 +138,12 @@ void main() {
offset
=
400.0
;
// now only 4 should fit, numbered 2-5.
tester
.
pumpFrame
(
builder
());
tester
.
pumpWidget
(
builder
());
// 0 and 1 aren't built, we know their size and nothing else changed
expect
(
callbackTracker
,
equals
([
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
});
});
}
packages/unit/test/widget/multichild_test.dart
View file @
fbd5460b
...
...
@@ -28,9 +28,9 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) {
void
main
(
)
{
test
(
'MultiChildRenderObjectElement control test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
DecoratedBox
(
decoration:
kBoxDecorationB
),
...
...
@@ -40,7 +40,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationB
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
DecoratedBox
(
decoration:
kBoxDecorationC
),
...
...
@@ -49,7 +49,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
DecoratedBox
(
key:
new
Key
(
'b'
),
decoration:
kBoxDecorationB
),
...
...
@@ -59,7 +59,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationB
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
key:
new
Key
(
'b'
),
decoration:
kBoxDecorationB
),
new
DecoratedBox
(
decoration:
kBoxDecorationC
),
...
...
@@ -69,7 +69,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationB
,
kBoxDecorationC
,
kBoxDecorationA
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
key:
new
Key
(
'a'
),
decoration:
kBoxDecorationA
),
new
DecoratedBox
(
decoration:
kBoxDecorationC
),
...
...
@@ -79,7 +79,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationC
,
kBoxDecorationB
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationC
),
])
...
...
@@ -87,17 +87,19 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([])
);
checkTree
(
tester
,
[]);
});
});
test
(
'MultiChildRenderObjectElement with stateless components'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
DecoratedBox
(
decoration:
kBoxDecorationB
),
...
...
@@ -107,7 +109,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationB
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
Container
(
...
...
@@ -119,7 +121,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationB
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
Container
(
...
...
@@ -133,7 +135,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationB
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Container
(
child:
new
Container
(
...
...
@@ -149,7 +151,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationB
,
kBoxDecorationA
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Container
(
child:
new
DecoratedBox
(
decoration:
kBoxDecorationB
)
...
...
@@ -163,7 +165,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationB
,
kBoxDecorationA
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Container
(
key:
new
Key
(
'b'
),
...
...
@@ -178,7 +180,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationB
,
kBoxDecorationA
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Container
(
key:
new
Key
(
'a'
),
...
...
@@ -193,17 +195,17 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationB
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
])
);
checkTree
(
tester
,
[]);
});
});
test
(
'MultiChildRenderObjectElement with stateful components'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
DecoratedBox
(
decoration:
kBoxDecorationB
),
...
...
@@ -212,7 +214,7 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationB
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
FlipComponent
(
left:
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
...
...
@@ -225,11 +227,11 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationA
,
kBoxDecorationC
]);
flipStatefulComponent
(
tester
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
checkTree
(
tester
,
[
kBoxDecorationB
,
kBoxDecorationC
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
FlipComponent
(
left:
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
...
...
@@ -241,11 +243,11 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationB
]);
flipStatefulComponent
(
tester
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
checkTree
(
tester
,
[
kBoxDecorationA
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
FlipComponent
(
key:
new
Key
(
'flip'
),
...
...
@@ -255,7 +257,7 @@ void main() {
])
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
key:
new
Key
(
'c'
),
decoration:
kBoxDecorationC
),
new
FlipComponent
(
...
...
@@ -269,11 +271,11 @@ void main() {
checkTree
(
tester
,
[
kBoxDecorationC
,
kBoxDecorationA
]);
flipStatefulComponent
(
tester
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
checkTree
(
tester
,
[
kBoxDecorationC
,
kBoxDecorationB
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
FlipComponent
(
key:
new
Key
(
'flip'
),
...
...
@@ -285,6 +287,6 @@ void main() {
);
checkTree
(
tester
,
[
kBoxDecorationB
,
kBoxDecorationC
]);
});
});
}
packages/unit/test/widget/navigator_test.dart
View file @
fbd5460b
import
'package:sky/animation.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
...
...
@@ -48,36 +47,35 @@ class SecondComponentState extends State<SecondComponent> {
void
main
(
)
{
test
(
'Can navigator navigate to and from a stateful component'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
final
Map
<
String
,
RouteBuilder
>
routes
=
<
String
,
RouteBuilder
>{
'/'
:
(
navigator
,
route
)
=>
new
FirstComponent
(
navigator
),
'/second'
:
(
navigator
,
route
)
=>
new
SecondComponent
(
navigator
),
};
tester
.
pumpFrame
(
new
Navigator
(
routes:
routes
));
tester
.
pumpWidget
(
new
Navigator
(
routes:
routes
));
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'Y'
),
isNull
);
tester
.
tap
(
tester
.
findText
(
'X'
));
scheduler
.
beginFrame
(
10.0
);
tester
.
pump
(
const
Duration
(
milliseconds:
10
)
);
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'Y'
),
isNotNull
);
scheduler
.
beginFrame
(
20.0
);
scheduler
.
beginFrame
(
30.0
);
scheduler
.
beginFrame
(
1000.0
);
tester
.
pump
(
const
Duration
(
milliseconds:
10
)
);
tester
.
pump
(
const
Duration
(
milliseconds:
10
)
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
tester
.
tap
(
tester
.
findText
(
'Y'
));
scheduler
.
beginFrame
(
1010.0
);
scheduler
.
beginFrame
(
1020.0
);
scheduler
.
beginFrame
(
1030.0
);
scheduler
.
beginFrame
(
2000.0
);
tester
.
pump
(
const
Duration
(
milliseconds:
10
)
);
tester
.
pump
(
const
Duration
(
milliseconds:
10
)
);
tester
.
pump
(
const
Duration
(
milliseconds:
10
)
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'Y'
),
isNull
);
});
});
}
packages/unit/test/widget/pageable_list_test.dart
View file @
fbd5460b
import
'package:quiver/testing/async.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
...
...
@@ -33,13 +32,10 @@ Widget buildFrame() {
void
page
(
WidgetTester
tester
,
Offset
offset
)
{
String
itemText
=
currentPage
!=
null
?
currentPage
.
toString
()
:
'0'
;
new
FakeAsync
().
run
((
async
)
{
tester
.
scroll
(
tester
.
findText
(
itemText
),
offset
);
// One frame to start the animation, a second to complete it.
tester
.
pumpFrameWithoutChange
();
tester
.
pumpFrameWithoutChange
(
1000.0
);
async
.
elapse
(
new
Duration
(
seconds:
1
));
});
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
}
void
pageLeft
(
WidgetTester
tester
)
{
...
...
@@ -54,59 +50,65 @@ void main() {
// PageableList with itemsWrap: false
test
(
'Scroll left from page 0 to page 1'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
currentPage
=
null
;
itemsWrap
=
false
;
tester
.
pumpFrame
(
buildFrame
());
tester
.
pumpWidget
(
buildFrame
());
expect
(
currentPage
,
isNull
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
1
));
});
});
test
(
'Scroll right from page 1 to page 0'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
itemsWrap
=
false
;
tester
.
pumpFrame
(
buildFrame
());
tester
.
pumpWidget
(
buildFrame
());
expect
(
currentPage
,
equals
(
1
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
});
});
test
(
'Scroll right from page 0 does nothing (underscroll)'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
itemsWrap
=
false
;
tester
.
pumpFrame
(
buildFrame
());
tester
.
pumpWidget
(
buildFrame
());
expect
(
currentPage
,
equals
(
0
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
});
});
// PageableList with itemsWrap: true
test
(
'Scroll left page 0 to page 1, itemsWrap: true'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
reset
(
);
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Container
()
);
currentPage
=
null
;
itemsWrap
=
true
;
tester
.
pumpFrame
(
buildFrame
());
tester
.
pumpWidget
(
buildFrame
());
expect
(
currentPage
,
isNull
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
1
));
});
});
test
(
'Scroll right from page 1 to page 0, itemsWrap: true'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
buildFrame
());
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
buildFrame
());
expect
(
currentPage
,
equals
(
1
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
});
});
test
(
'Scroll right from page 0 to page 5, itemsWrap: true (underscroll)'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
buildFrame
());
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
buildFrame
());
expect
(
currentPage
,
equals
(
0
));
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
5
));
});
});
}
packages/unit/test/widget/parent_data_test.dart
View file @
fbd5460b
...
...
@@ -58,9 +58,9 @@ void main() {
});
test
(
'ParentDataWidget control test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
new
Positioned
(
...
...
@@ -78,7 +78,7 @@ void main() {
kNonPositioned
,
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
bottom:
5.0
,
...
...
@@ -104,7 +104,7 @@ void main() {
DecoratedBox
kDecoratedBoxB
=
new
DecoratedBox
(
decoration:
kBoxDecorationB
);
DecoratedBox
kDecoratedBoxC
=
new
DecoratedBox
(
decoration:
kBoxDecorationC
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
bottom:
5.0
,
...
...
@@ -126,7 +126,7 @@ void main() {
kNonPositioned
,
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
bottom:
6.0
,
...
...
@@ -148,7 +148,7 @@ void main() {
kNonPositioned
,
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
kDecoratedBoxA
,
new
Positioned
(
...
...
@@ -166,7 +166,7 @@ void main() {
kNonPositioned
,
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
kDecoratedBoxA
,
new
Positioned
(
...
...
@@ -188,7 +188,7 @@ void main() {
new
TestParentData
(
top:
8.0
),
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
right:
10.0
,
...
...
@@ -202,13 +202,13 @@ void main() {
]);
flipStatefulComponent
(
tester
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
checkTree
(
tester
,
[
new
TestParentData
(
right:
10.0
),
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
top:
7.0
,
...
...
@@ -222,25 +222,25 @@ void main() {
]);
flipStatefulComponent
(
tester
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
checkTree
(
tester
,
[
new
TestParentData
(
top:
7.0
),
]);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([])
);
checkTree
(
tester
,
[]);
});
});
test
(
'ParentDataWidget conflicting data'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
expect
(
cachedException
,
isNull
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
top:
5.0
,
...
...
@@ -257,12 +257,12 @@ void main() {
expect
(
cachedException
,
isNotNull
);
cachedException
=
null
;
tester
.
pumpFrame
(
new
Stack
([]));
tester
.
pumpWidget
(
new
Stack
([]));
checkTree
(
tester
,
[]);
expect
(
cachedException
,
isNull
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Container
(
child:
new
Flex
([
new
Positioned
(
...
...
@@ -277,11 +277,11 @@ void main() {
expect
(
cachedException
,
isNotNull
);
cachedException
=
null
;
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([])
);
checkTree
(
tester
,
[]);
});
});
}
packages/unit/test/widget/progress_indicator_test.dart
View file @
fbd5460b
...
...
@@ -7,15 +7,15 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'LinearProgressIndicator changes when its value changes'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
Block
([
new
LinearProgressIndicator
(
value:
0.0
)]));
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Block
([
new
LinearProgressIndicator
(
value:
0.0
)]));
List
<
Layer
>
layers1
=
tester
.
layers
;
tester
.
pumpFrame
(
new
Block
([
new
LinearProgressIndicator
(
value:
0.5
)]));
tester
.
pumpWidget
(
new
Block
([
new
LinearProgressIndicator
(
value:
0.5
)]));
List
<
Layer
>
layers2
=
tester
.
layers
;
expect
(
layers1
,
isNot
(
equals
(
layers2
)));
});
});
}
packages/unit/test/widget/render_object_widget_test.dart
View file @
fbd5460b
...
...
@@ -16,9 +16,8 @@ class TestComponent extends StatelessComponent {
void
main
(
)
{
test
(
'RenderObjectWidget smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
));
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
));
OneChildRenderObjectElement
element
=
tester
.
findElement
((
element
)
=>
element
is
OneChildRenderObjectElement
);
expect
(
element
,
isNotNull
);
...
...
@@ -27,7 +26,7 @@ void main() {
expect
(
renderObject
.
decoration
,
equals
(
kBoxDecorationA
));
expect
(
renderObject
.
position
,
equals
(
BoxDecorationPosition
.
background
));
tester
.
pumpFrame
(
new
DecoratedBox
(
decoration:
kBoxDecorationB
));
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationB
));
element
=
tester
.
findElement
((
element
)
=>
element
is
OneChildRenderObjectElement
);
expect
(
element
,
isNotNull
);
expect
(
element
.
renderObject
is
RenderDecoratedBox
,
isTrue
);
...
...
@@ -35,9 +34,10 @@ void main() {
expect
(
renderObject
.
decoration
,
equals
(
kBoxDecorationB
));
expect
(
renderObject
.
position
,
equals
(
BoxDecorationPosition
.
background
));
});
});
test
(
'RenderObjectWidget can add and remove children'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
void
checkFullTree
()
{
OneChildRenderObjectElement
element
=
...
...
@@ -66,7 +66,7 @@ void main() {
expect
(
renderObject
.
child
,
isNull
);
}
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
,
child:
new
DecoratedBox
(
decoration:
kBoxDecorationB
...
...
@@ -75,7 +75,7 @@ void main() {
checkFullTree
();
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
,
child:
new
TestComponent
(
child:
new
DecoratedBox
(
...
...
@@ -86,7 +86,7 @@ void main() {
checkFullTree
();
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
,
child:
new
DecoratedBox
(
decoration:
kBoxDecorationB
...
...
@@ -95,13 +95,13 @@ void main() {
checkFullTree
();
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
));
childBareTree
();
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
,
child:
new
TestComponent
(
child:
new
TestComponent
(
...
...
@@ -114,17 +114,18 @@ void main() {
checkFullTree
();
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
));
childBareTree
();
});
});
test
(
'Detached render tree is intact'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
,
child:
new
DecoratedBox
(
decoration:
kBoxDecorationB
,
...
...
@@ -146,7 +147,7 @@ void main() {
expect
(
grandChild
.
decoration
,
equals
(
kBoxDecorationC
));
expect
(
grandChild
.
child
,
isNull
);
tester
.
pumpFrame
(
new
DecoratedBox
(
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
));
...
...
@@ -163,4 +164,5 @@ void main() {
expect
(
grandChild
.
decoration
,
equals
(
kBoxDecorationC
));
expect
(
grandChild
.
child
,
isNull
);
});
});
}
packages/unit/test/widget/scrollable_list_hit_testing_test.dart
View file @
fbd5460b
...
...
@@ -8,11 +8,10 @@ const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
List
<
int
>
tapped
=
<
int
>[];
void
main
(
)
{
double
t
=
0.0
;
WidgetTester
tester
=
new
WidgetTester
();
test
(
'Tap item after scroll - horizontal'
,
()
{
tester
.
pumpFrame
(
new
Center
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Container
());
tester
.
pumpWidget
(
new
Center
(
child:
new
Container
(
height:
50.0
,
child:
new
ScrollableList
<
int
>(
...
...
@@ -31,9 +30,9 @@ void main() {
scrollDirection:
ScrollDirection
.
horizontal
)
)
),
t
);
)
);
tester
.
scroll
(
tester
.
findText
(
'2'
),
const
Offset
(-
280.0
,
0.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// screen is 800px wide, and has the following items:
// -280..10 = 0
// 10..300 = 1
...
...
@@ -49,9 +48,12 @@ void main() {
tester
.
tap
(
tester
.
findText
(
'2'
));
expect
(
tapped
,
equals
([
2
]));
});
});
test
(
'Tap item after scroll - vertical'
,
()
{
tester
.
pumpFrame
(
new
Center
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Container
());
tester
.
pumpWidget
(
new
Center
(
child:
new
Container
(
width:
50.0
,
child:
new
ScrollableList
<
int
>(
...
...
@@ -70,9 +72,9 @@ void main() {
scrollDirection:
ScrollDirection
.
vertical
)
)
),
t
);
)
);
tester
.
scroll
(
tester
.
findText
(
'1'
),
const
Offset
(
0.0
,
-
280.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// screen is 600px tall, and has the following items:
// -280..10 = 0
// 10..300 = 1
...
...
@@ -90,5 +92,5 @@ void main() {
tester
.
tap
(
tester
.
findText
(
'3'
));
expect
(
tapped
,
equals
([
2
,
1
]));
// the center of the third item is off-screen so it shouldn't get hit
});
});
}
packages/unit/test/widget/scrollable_list_horizontal_test.dart
View file @
fbd5460b
...
...
@@ -26,14 +26,13 @@ Widget buildFrame() {
}
void
main
(
)
{
double
t
=
0.0
;
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
buildFrame
());
test
(
'Drag horizontally'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
buildFrame
());
test
(
'Drag to the left using item 1'
,
()
{
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findText
(
'1'
),
const
Offset
(-
300.0
,
0.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// screen is 800px wide, and has the following items:
// -10..280 = 1
// 280..570 = 2
...
...
@@ -44,15 +43,13 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
});
test
(
'Drag to the left using item 3'
,
()
{
// the center of item 3 is visible, so this works;
// if item 3 was a bit wider, such that it's center was past the 800px mark, this would fail,
// because it wouldn't be hit tested when scrolling from its center, as scroll() does.
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
tester
.
scroll
(
tester
.
findText
(
'3'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// screen is 800px wide, and has the following items:
// -10..280 = 2
// 280..570 = 3
...
...
@@ -63,12 +60,10 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
});
test
(
'Drag up using item 3'
,
()
{
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findText
(
'3'
),
const
Offset
(
0.0
,
-
290.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// unchanged
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
...
...
@@ -76,12 +71,10 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
});
test
(
'Drag to the left using item 3 again'
,
()
{
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findText
(
'3'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// screen is 800px wide, and has the following items:
// -10..280 = 3
// 280..570 = 4
...
...
@@ -92,17 +85,15 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
});
test
(
'Drag to the left using item 3 again again (past the end of the list)'
,
()
{
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
// at this point we can drag 60 pixels further before we hit the friction zone
// then, every pixel we drag is equivalent to half a pixel of movement
// to move item 3 entirely off screen therefore takes:
// 60 + (290-60)*2 = 520 pixels
// plus a couple more to be sure
tester
.
scroll
(
tester
.
findText
(
'3'
),
const
Offset
(-
522.0
,
0.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
0.0
);
// just after release
tester
.
pump
(
);
// just after release
// screen is 800px wide, and has the following items:
// -11..279 = 4
// 279..569 = 5
...
...
@@ -112,7 +103,7 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
// a second after release
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// a second after release
// screen is 800px wide, and has the following items:
// -70..220 = 3
// 220..510 = 4
...
...
@@ -123,13 +114,11 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
});
test
(
'Drag to the left using item 2 when the scroll offset is big'
,
()
{
tester
.
reset
();
tester
.
pumpFrame
(
buildFrame
(),
t
+=
1000.0
);
tester
.
pumpWidget
(
new
Container
());
tester
.
pumpWidget
(
buildFrame
(),
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findText
(
'2'
),
const
Offset
(-
280.0
,
0.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// screen is 800px wide, and has the following items:
// -280..10 = 0
// 10..300 = 1
...
...
@@ -141,9 +130,9 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
tester
.
scroll
(
tester
.
findText
(
'2'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
pumpFrameWithoutChange
(
t
+=
1000.0
);
tester
.
pump
(
const
Duration
(
seconds:
1
)
);
// screen is 800px wide, and has the following items:
// -280..10 = 1
// 10..300 = 2
...
...
@@ -156,5 +145,5 @@ void main() {
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
});
});
}
packages/unit/test/widget/scrollable_list_vertical_test.dart
View file @
fbd5460b
...
...
@@ -20,13 +20,13 @@ Widget buildFrame() {
}
void
main
(
)
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
buildFrame
());
test
(
'Drag vertically'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
buildFrame
());
test
(
'Drag up using item 1'
,
()
{
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
tester
.
scroll
(
tester
.
findText
(
'1'
),
const
Offset
(
0.0
,
-
300.0
));
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
// screen is 600px high, and has the following items:
// -10..280 = 1
// 280..570 = 2
...
...
@@ -37,12 +37,10 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
});
test
(
'Drag up using item 2'
,
()
{
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
tester
.
scroll
(
tester
.
findText
(
'2'
),
const
Offset
(
0.0
,
-
290.0
));
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
// screen is 600px high, and has the following items:
// -10..280 = 2
// 280..570 = 3
...
...
@@ -53,12 +51,10 @@ void main() {
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
});
test
(
'Drag to the left using item 3'
,
()
{
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
tester
.
scroll
(
tester
.
findText
(
'3'
),
const
Offset
(-
300.0
,
0.0
));
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
// nothing should have changed
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
...
...
@@ -67,5 +63,5 @@ void main() {
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
});
});
}
packages/unit/test/widget/set_state_3_test.dart
View file @
fbd5460b
...
...
@@ -48,10 +48,11 @@ class LeafState extends State<Leaf> {
void
main
(
)
{
test
(
'three-way setState() smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
Changer
(
new
Wrapper
(
new
Leaf
())));
tester
.
pumpFrame
(
new
Changer
(
new
Wrapper
(
new
Leaf
())));
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Changer
(
new
Wrapper
(
new
Leaf
())));
tester
.
pumpWidget
(
new
Changer
(
new
Wrapper
(
new
Leaf
())));
changer
.
test
();
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
});
});
}
packages/unit/test/widget/set_state_test.dart
View file @
fbd5460b
...
...
@@ -54,13 +54,14 @@ class OutsideState extends State<Outside> {
void
main
(
)
{
test
(
'setState() smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
new
Outside
());
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Outside
());
TestPointer
pointer
=
new
TestPointer
(
1
);
Point
location
=
tester
.
getCenter
(
tester
.
findText
(
'INSIDE'
));
tester
.
dispatchEvent
(
pointer
.
down
(
location
),
location
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
tester
.
dispatchEvent
(
pointer
.
up
(),
location
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
});
});
}
packages/unit/test/widget/snap_scrolling_test.dart
View file @
fbd5460b
...
...
@@ -4,7 +4,6 @@
import
'dart:async'
;
import
'package:quiver/testing/async.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
...
...
@@ -59,91 +58,60 @@ Future fling(double velocity) {
}
void
main
(
)
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
buildFrame
());
test
(
'ScrollableList snap scrolling, fling(-800)'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
buildFrame
());
scrollOffset
=
0.0
;
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
scrollOffset
,
0.0
);
double
t0
=
0.0
;
int
dt
=
2000
;
new
FakeAsync
().
run
((
async
)
{
Duration
dt
=
const
Duration
(
seconds:
2
);
fling
(-
800.0
);
tester
.
pumpFrameWithoutChange
(
t0
);
// Start the scheduler at 0.0
tester
.
pumpFrameWithoutChange
(
t0
+
dt
);
async
.
elapse
(
new
Duration
(
milliseconds:
dt
));
tester
.
pump
();
// Start the scheduler at 0.0
tester
.
pump
(
dt
);
expect
(
scrollOffset
,
closeTo
(
200.0
,
1.0
));
});
});
test
(
'ScrollableList snap scrolling, fling(-2000)'
,
()
{
scrollOffset
=
0.0
;
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
scrollOffset
,
0.0
);
double
t0
=
0.0
;
int
dt
=
2000
;
new
FakeAsync
().
run
((
async
)
{
fling
(-
2000.0
);
tester
.
pumpFrameWithoutChange
(
t0
);
tester
.
pumpFrameWithoutChange
(
t0
+
dt
);
async
.
elapse
(
new
Duration
(
milliseconds:
dt
));
tester
.
pump
();
tester
.
pump
(
dt
);
expect
(
scrollOffset
,
closeTo
(
400.0
,
1.0
));
});
});
test
(
'ScrollableList snap scrolling, fling(800)'
,
()
{
scrollOffset
=
400.0
;
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
scrollOffset
,
400.0
);
double
t0
=
0.0
;
int
dt
=
2000
;
new
FakeAsync
().
run
((
async
)
{
fling
(
800.0
);
tester
.
pumpFrameWithoutChange
(
t0
);
tester
.
pumpFrameWithoutChange
(
t0
+
dt
);
async
.
elapse
(
new
Duration
(
milliseconds:
dt
));
tester
.
pump
();
tester
.
pump
(
dt
);
expect
(
scrollOffset
,
closeTo
(
0.0
,
1.0
));
});
});
test
(
'ScrollableList snap scrolling, fling(2000)'
,
()
{
scrollOffset
=
800.0
;
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
scrollOffset
,
800.0
);
double
t0
=
0.0
;
int
dt
=
2000
;
new
FakeAsync
().
run
((
async
)
{
fling
(
2000.0
);
tester
.
pumpFrameWithoutChange
(
t0
);
tester
.
pumpFrameWithoutChange
(
t0
+
dt
);
async
.
elapse
(
new
Duration
(
milliseconds:
dt
));
tester
.
pump
();
tester
.
pump
(
dt
);
expect
(
scrollOffset
,
closeTo
(
200.0
,
1.0
));
});
});
test
(
'ScrollableList snap scrolling, fling(2000).then()'
,
()
{
scrollOffset
=
800.0
;
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
scrollOffset
,
800.0
);
double
t0
=
0.0
;
int
dt
=
2000
;
bool
completed
=
false
;
new
FakeAsync
().
run
((
async
)
{
fling
(
2000.0
).
then
((
_
)
{
completed
=
true
;
expect
(
scrollOffset
,
closeTo
(
200.0
,
1.0
));
});
tester
.
pumpFrameWithoutChange
(
t0
);
tester
.
pumpFrameWithoutChange
(
t0
+
dt
);
async
.
elapse
(
new
Duration
(
milliseconds:
dt
));
tester
.
pump
();
tester
.
pump
(
dt
);
expect
(
completed
,
true
);
});
});
}
packages/unit/test/widget/stack_test.dart
View file @
fbd5460b
...
...
@@ -5,11 +5,10 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Can change position data'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
Key
key
=
new
Key
(
'container'
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
left:
10.0
,
...
...
@@ -28,7 +27,7 @@ void main() {
expect
(
container
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
left
,
equals
(
10.0
));
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
right:
10.0
,
...
...
@@ -47,14 +46,14 @@ void main() {
expect
(
container
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
left
,
isNull
);
});
});
test
(
'Can remove parent data'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
Key
key
=
new
Key
(
'container'
);
Container
container
=
new
Container
(
key:
key
,
width:
10.0
,
height:
10.0
);
tester
.
pumpFrame
(
new
Stack
([
new
Positioned
(
left:
10.0
,
child:
container
)
]));
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
left:
10.0
,
child:
container
)
]));
Element
containerElement
=
tester
.
findElementByKey
(
key
);
expect
(
containerElement
.
renderObject
.
parentData
.
top
,
isNull
);
...
...
@@ -62,7 +61,7 @@ void main() {
expect
(
containerElement
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
left
,
equals
(
10.0
));
tester
.
pumpFrame
(
new
Stack
([
container
]));
tester
.
pumpWidget
(
new
Stack
([
container
]));
containerElement
=
tester
.
findElementByKey
(
key
);
expect
(
containerElement
.
renderObject
.
parentData
.
top
,
isNull
);
...
...
@@ -70,5 +69,5 @@ void main() {
expect
(
containerElement
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
left
,
isNull
);
});
});
}
packages/unit/test/widget/stateful_component_test.dart
View file @
fbd5460b
...
...
@@ -7,7 +7,7 @@ import 'test_widgets.dart';
void
main
(
)
{
test
(
'Stateful component smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
void
checkTree
(
BoxDecoration
expectedDecoration
)
{
OneChildRenderObjectElement
element
=
...
...
@@ -18,7 +18,7 @@ void main() {
expect
(
renderObject
.
decoration
,
equals
(
expectedDecoration
));
}
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
FlipComponent
(
left:
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
right:
new
DecoratedBox
(
decoration:
kBoxDecorationB
)
...
...
@@ -27,7 +27,7 @@ void main() {
checkTree
(
kBoxDecorationA
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
FlipComponent
(
left:
new
DecoratedBox
(
decoration:
kBoxDecorationB
),
right:
new
DecoratedBox
(
decoration:
kBoxDecorationA
)
...
...
@@ -38,11 +38,11 @@ void main() {
flipStatefulComponent
(
tester
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
checkTree
(
kBoxDecorationA
);
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
FlipComponent
(
left:
new
DecoratedBox
(
decoration:
kBoxDecorationA
),
right:
new
DecoratedBox
(
decoration:
kBoxDecorationB
)
...
...
@@ -50,12 +50,12 @@ void main() {
);
checkTree
(
kBoxDecorationB
);
});
});
test
(
'Don
\'
t rebuild subcomponents'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
FlipComponent
(
key:
new
Key
(
'rebuild test'
),
// this is so we don't get the state from the TestComponentConfig in the last test, but instead instantiate a new element with a new state.
left:
new
TestBuildCounter
(),
...
...
@@ -67,8 +67,9 @@ void main() {
flipStatefulComponent
(
tester
);
tester
.
pumpFrameWithoutChange
();
tester
.
pump
();
expect
(
TestBuildCounter
.
buildCount
,
equals
(
1
));
});
});
}
packages/unit/test/widget/stateful_components_test.dart
View file @
fbd5460b
...
...
@@ -37,9 +37,7 @@ class OuterContainerState extends State<OuterContainer> {
void
main
(
)
{
test
(
'resync stateful widget'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
Key
innerKey
=
new
Key
(
'inner'
);
Key
outerKey
=
new
Key
(
'outer'
);
...
...
@@ -48,7 +46,7 @@ void main() {
OuterContainer
outer1
=
new
OuterContainer
(
key:
outerKey
,
child:
inner1
);
OuterContainer
outer2
;
tester
.
pumpFrame
(
outer1
);
tester
.
pumpWidget
(
outer1
);
StatefulComponentElement
innerElement
=
tester
.
findElementByKey
(
innerKey
);
InnerComponentState
innerElementState
=
innerElement
.
state
;
...
...
@@ -59,7 +57,7 @@ void main() {
inner2
=
new
InnerComponent
(
key:
innerKey
);
outer2
=
new
OuterContainer
(
key:
outerKey
,
child:
inner2
);
tester
.
pumpFrame
(
outer2
);
tester
.
pumpWidget
(
outer2
);
expect
(
tester
.
findElementByKey
(
innerKey
),
equals
(
innerElement
));
expect
(
innerElement
.
state
,
equals
(
innerElementState
));
...
...
@@ -71,11 +69,12 @@ void main() {
StatefulComponentElement
outerElement
=
tester
.
findElementByKey
(
outerKey
);
expect
(
outerElement
.
state
.
config
,
equals
(
outer2
));
outerElement
.
state
.
setState
(()
{});
tester
.
pumpFrameWithoutChange
(
0.0
);
tester
.
pump
(
);
expect
(
tester
.
findElementByKey
(
innerKey
),
equals
(
innerElement
));
expect
(
innerElement
.
state
,
equals
(
innerElementState
));
expect
(
innerElementState
.
config
,
equals
(
inner2
));
expect
(
innerElement
.
renderObject
.
attached
,
isTrue
);
});
});
}
packages/unit/test/widget/syncing_test.dart
View file @
fbd5460b
...
...
@@ -37,9 +37,8 @@ class TestWidgetState extends State<TestWidget> {
void
main
(
)
{
test
(
'no change'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Container
(
child:
new
Container
(
child:
new
TestWidget
(
...
...
@@ -55,7 +54,7 @@ void main() {
expect
(
state
.
persistentState
,
equals
(
1
));
expect
(
state
.
updates
,
equals
(
0
));
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Container
(
child:
new
Container
(
child:
new
TestWidget
(
...
...
@@ -69,14 +68,13 @@ void main() {
expect
(
state
.
persistentState
,
equals
(
1
));
expect
(
state
.
updates
,
equals
(
1
));
tester
.
pumpFrame
(
new
Container
());
tester
.
pumpWidget
(
new
Container
());
});
});
test
(
'remove one'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Container
(
child:
new
Container
(
child:
new
TestWidget
(
...
...
@@ -92,7 +90,7 @@ void main() {
expect
(
state
.
persistentState
,
equals
(
10
));
expect
(
state
.
updates
,
equals
(
0
));
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Container
(
child:
new
TestWidget
(
persistentState:
11
,
...
...
@@ -106,21 +104,20 @@ void main() {
expect
(
state
.
persistentState
,
equals
(
11
));
expect
(
state
.
updates
,
equals
(
0
));
tester
.
pumpFrame
(
new
Container
());
tester
.
pumpWidget
(
new
Container
());
});
});
test
(
'swap instances around'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
Widget
a
=
new
TestWidget
(
persistentState:
0x61
,
syncedState:
0x41
,
child:
new
Text
(
'apple'
));
Widget
b
=
new
TestWidget
(
persistentState:
0x62
,
syncedState:
0x42
,
child:
new
Text
(
'banana'
));
tester
.
pumpFrame
(
new
Column
([]));
tester
.
pumpWidget
(
new
Column
([]));
GlobalKey
keyA
=
new
GlobalKey
();
GlobalKey
keyB
=
new
GlobalKey
();
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Column
([
new
Container
(
key:
keyA
,
...
...
@@ -145,7 +142,7 @@ void main() {
expect
(
second
.
persistentState
,
equals
(
0x62
));
expect
(
second
.
syncedState
,
equals
(
0x42
));
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Column
([
new
Container
(
key:
keyA
,
...
...
@@ -172,7 +169,7 @@ void main() {
// now we swap the nodes over
// since they are both "old" nodes, they shouldn't sync with each other even though they look alike
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Column
([
new
Container
(
key:
keyA
,
...
...
@@ -194,7 +191,6 @@ void main() {
expect
(
second
.
config
,
equals
(
a
));
expect
(
second
.
persistentState
,
equals
(
0x62
));
expect
(
second
.
syncedState
,
equals
(
0x41
));
});
});
}
packages/unit/test/widget/transform_test.dart
View file @
fbd5460b
...
...
@@ -5,10 +5,9 @@ import 'widget_tester.dart';
void
main
(
)
{
test
(
'Transform origin'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
testWidgets
((
WidgetTester
tester
)
{
bool
didReceiveTap
=
false
;
tester
.
pumpFrame
(
tester
.
pumpWidget
(
new
Stack
([
new
Positioned
(
top:
100.0
,
...
...
@@ -48,4 +47,5 @@ void main() {
tester
.
tapAt
(
new
Point
(
190.0
,
150.0
));
expect
(
didReceiveTap
,
isTrue
);
});
});
}
packages/unit/test/widget/widget_tester.dart
View file @
fbd5460b
...
...
@@ -3,6 +3,8 @@ import 'dart:sky' as sky;
import
'package:sky/animation.dart'
;
import
'package:sky/rendering.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:quiver/testing/async.dart'
;
import
'package:quiver/time.dart'
;
import
'../engine/mock_events.dart'
;
...
...
@@ -24,21 +26,24 @@ class RootComponentState extends State<RootComponent> {
}
class
WidgetTester
{
WidgetTester
.
_
(
FakeAsync
async
)
:
async
=
async
,
clock
=
async
.
getClock
(
new
DateTime
.
utc
(
2015
,
1
,
1
))
{
}
// See thttps://github.com/flutter/engine/issues/1084 regarding frameTimeMs vs FakeAsync
final
FakeAsync
async
;
final
Clock
clock
;
void
pump
Frame
(
Widget
widget
,
[
double
frameTimeMs
=
0.0
])
{
void
pump
Widget
(
Widget
widget
,
[
Duration
duration
])
{
runApp
(
widget
);
scheduler
.
beginFrame
(
frameTimeMs
);
}
void
pumpFrameWithoutChange
([
double
frameTimeMs
=
0.0
])
{
scheduler
.
beginFrame
(
frameTimeMs
);
pump
(
duration
);
}
void
reset
()
{
runApp
(
new
Container
());
scheduler
.
beginFrame
(
0.0
);
void
pump
([
Duration
duration
])
{
if
(
duration
!=
null
)
async
.
elapse
(
duration
);
scheduler
.
beginFrame
(
clock
.
now
().
millisecondsSinceEpoch
.
toDouble
());
async
.
flushMicrotasks
();
}
List
<
Layer
>
_layers
(
Layer
layer
)
{
...
...
@@ -162,3 +167,9 @@ class WidgetTester {
}
}
void
testWidgets
(
callback
(
WidgetTester
tester
))
{
new
FakeAsync
().
run
((
FakeAsync
async
)
{
callback
(
new
WidgetTester
.
_
(
async
));
});
}
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