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
06ffa759
Commit
06ffa759
authored
Sep 25, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert some tests to fn3
parent
b5893f9e
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
130 additions
and
464 deletions
+130
-464
focus.dart
packages/flutter/lib/src/fn3/focus.dart
+1
-0
framework.dart
packages/flutter/lib/src/fn3/framework.dart
+7
-2
widget_tester.dart
packages/unit/test/fn3/widget_tester.dart
+11
-5
align_test.dart
packages/unit/test/widget/align_test.dart
+10
-10
block_test.dart
packages/unit/test/widget/block_test.dart
+12
-12
box_decoration_test.dart
packages/unit/test/widget/box_decoration_test.dart
+6
-6
center_test.dart
packages/unit/test/widget/center_test.dart
+3
-5
date_picker_test.dart
packages/unit/test/widget/date_picker_test.dart
+15
-17
duplicate_key_test.dart
packages/unit/test/widget/duplicate_key_test.dart
+13
-10
flex_test.dart
packages/unit/test/widget/flex_test.dart
+6
-6
gesture_detector_test.dart
packages/unit/test/widget/gesture_detector_test.dart
+27
-29
homogeneous_viewport_test.dart
packages/unit/test/widget/homogeneous_viewport_test.dart
+0
-170
listener_test.dart
packages/unit/test/widget/listener_test.dart
+6
-6
mixed_viewport_test.dart
packages/unit/test/widget/mixed_viewport_test.dart
+0
-171
navigator_test.dart
packages/unit/test/widget/navigator_test.dart
+13
-15
No files found.
packages/flutter/lib/src/fn3/focus.dart
View file @
06ffa759
...
@@ -153,6 +153,7 @@ class FocusState extends State<Focus> {
...
@@ -153,6 +153,7 @@ class FocusState extends State<Focus> {
}
}
void
initState
(
BuildContext
context
)
{
void
initState
(
BuildContext
context
)
{
super
.
initState
(
context
);
if
(
config
.
autofocus
)
if
(
config
.
autofocus
)
FocusState
.
_moveScopeTo
(
context
,
config
);
FocusState
.
_moveScopeTo
(
context
,
config
);
_updateWidgetRemovalListener
(
_focusedWidget
);
_updateWidgetRemovalListener
(
_focusedWidget
);
...
...
packages/flutter/lib/src/fn3/framework.dart
View file @
06ffa759
...
@@ -631,9 +631,9 @@ abstract class BuildableElement<T extends Widget> extends Element<T> {
...
@@ -631,9 +631,9 @@ abstract class BuildableElement<T extends Widget> extends Element<T> {
/// binding when scheduleBuild() has been called to mark this element dirty,
/// binding when scheduleBuild() has been called to mark this element dirty,
/// and by update() when the Widget has changed.
/// and by update() when the Widget has changed.
void
rebuild
()
{
void
rebuild
()
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
mounted
);
if
(!
_dirty
)
if
(!
_dirty
)
return
;
return
;
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
mounted
);
_dirty
=
false
;
_dirty
=
false
;
Widget
built
;
Widget
built
;
try
{
try
{
...
@@ -731,7 +731,12 @@ class StatefulComponentElement extends BuildableElement<StatefulComponent> {
...
@@ -731,7 +731,12 @@ class StatefulComponentElement extends BuildableElement<StatefulComponent> {
_state
.
_config
=
widget
;
_state
.
_config
=
widget
;
assert
(
_state
.
_debugLifecycleState
==
_StateLifecycle
.
created
);
assert
(
_state
.
_debugLifecycleState
==
_StateLifecycle
.
created
);
_state
.
initState
(
this
);
_state
.
initState
(
this
);
assert
(
_state
.
_debugLifecycleState
==
_StateLifecycle
.
initialized
);
assert
(()
{
if
(
_state
.
_debugLifecycleState
==
_StateLifecycle
.
initialized
)
return
true
;
print
(
'
${_state.runtimeType}
.initState failed to call super.initState'
);
return
false
;
});
assert
(()
{
_state
.
_debugLifecycleState
=
_StateLifecycle
.
ready
;
return
true
;
});
assert
(()
{
_state
.
_debugLifecycleState
=
_StateLifecycle
.
ready
;
return
true
;
});
_builder
=
_state
.
build
;
_builder
=
_state
.
build
;
}
}
...
...
packages/unit/test/fn3/widget_tester.dart
View file @
06ffa759
...
@@ -6,7 +6,7 @@ import 'package:sky/src/fn3.dart';
...
@@ -6,7 +6,7 @@ import 'package:sky/src/fn3.dart';
import
'../engine/mock_events.dart'
;
import
'../engine/mock_events.dart'
;
class
RootComponent
extends
StatefulComponent
{
class
RootComponent
extends
StatefulComponent
{
RootComponentState
createState
()
=>
new
RootComponentState
(
this
);
RootComponentState
createState
()
=>
new
RootComponentState
();
}
}
class
RootComponentState
extends
State
<
RootComponent
>
{
class
RootComponentState
extends
State
<
RootComponent
>
{
...
@@ -24,13 +24,13 @@ class RootComponentState extends State<RootComponent> {
...
@@ -24,13 +24,13 @@ class RootComponentState extends State<RootComponent> {
class
WidgetTester
{
class
WidgetTester
{
void
pumpFrame
(
Widget
widget
)
{
void
pumpFrame
(
Widget
widget
,
[
double
frameTimeMs
=
0.0
]
)
{
runApp
(
widget
);
runApp
(
widget
);
WidgetFlutterBinding
.
instance
.
beginFrame
(
0.0
);
// TODO(ianh): https://github.com/flutter/engine/issues/1084
WidgetFlutterBinding
.
instance
.
beginFrame
(
frameTimeMs
);
// TODO(ianh): https://github.com/flutter/engine/issues/1084
}
}
void
pumpFrameWithoutChange
()
{
void
pumpFrameWithoutChange
(
[
double
frameTimeMs
=
0.0
]
)
{
WidgetFlutterBinding
.
instance
.
beginFrame
(
0.0
);
// TODO(ianh): https://github.com/flutter/engine/issues/1084
WidgetFlutterBinding
.
instance
.
beginFrame
(
frameTimeMs
);
// TODO(ianh): https://github.com/flutter/engine/issues/1084
}
}
...
@@ -64,6 +64,12 @@ class WidgetTester {
...
@@ -64,6 +64,12 @@ class WidgetTester {
});
});
}
}
State
findStateOfType
(
Type
type
)
{
StatefulComponentElement
element
=
findElement
((
Element
element
)
{
return
element
is
StatefulComponentElement
&&
element
.
state
.
runtimeType
==
type
;
});
return
element
?.
state
;
}
Point
getCenter
(
Element
element
)
{
Point
getCenter
(
Element
element
)
{
return
_getElementPoint
(
element
,
(
Size
size
)
=>
size
.
center
(
Point
.
origin
));
return
_getElementPoint
(
element
,
(
Size
size
)
=>
size
.
center
(
Point
.
origin
));
...
...
packages/unit/test/widget/align_test.dart
View file @
06ffa759
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
test
(
'Align smoke test'
,
()
{
test
(
'Align smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
()
{
tester
.
pumpFrame
(
return
new
Align
(
new
Align
(
child:
new
Container
(),
child:
new
Container
(),
horizontal:
0.75
,
horizontal:
0.75
,
vertical:
0.75
vertical:
0.75
)
);
);
});
tester
.
pumpFrame
(
()
{
tester
.
pumpFrame
(
return
new
Align
(
new
Align
(
child:
new
Container
(),
child:
new
Container
(),
horizontal:
0.5
,
horizontal:
0.5
,
vertical:
0.5
vertical:
0.5
)
);
);
});
});
});
}
}
packages/unit/test/widget/block_test.dart
View file @
06ffa759
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'../engine/mock_events.dart'
;
import
'../engine/mock_events.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
final
Key
blockKey
=
new
Key
(
'test'
);
final
Key
blockKey
=
new
Key
(
'test'
);
...
@@ -10,19 +10,19 @@ void main() {
...
@@ -10,19 +10,19 @@ void main() {
test
(
'Cannot scroll a non-overflowing block'
,
()
{
test
(
'Cannot scroll a non-overflowing block'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
()
{
tester
.
pumpFrame
(
return
new
Block
([
new
Block
([
new
Container
(
new
Container
(
height:
200.0
,
// less than 600, the height of the test area
height:
200.0
,
// less than 600, the height of the test area
child:
new
Text
(
'Hello'
)
child:
new
Text
(
'Hello'
)
)
)
],
],
key:
blockKey
)
;
key:
blockKey
)
}
);
);
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
find
Widget
((
widget
)
=>
widget
.
key
==
blockKey
));
Point
target
=
tester
.
getCenter
(
tester
.
find
ElementByKey
(
blockKey
));
TestPointer
pointer
=
new
TestPointer
();
TestPointer
pointer
=
new
TestPointer
();
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
...
@@ -37,19 +37,19 @@ void main() {
...
@@ -37,19 +37,19 @@ void main() {
test
(
'Can scroll an overflowing block'
,
()
{
test
(
'Can scroll an overflowing block'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
()
{
tester
.
pumpFrame
(
return
new
Block
([
new
Block
([
new
Container
(
new
Container
(
height:
2000.0
,
// more than 600, the height of the test area
height:
2000.0
,
// more than 600, the height of the test area
child:
new
Text
(
'Hello'
)
child:
new
Text
(
'Hello'
)
)
)
],
],
key:
blockKey
)
;
key:
blockKey
)
}
);
);
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
find
Widget
((
widget
)
=>
widget
.
key
==
blockKey
));
Point
target
=
tester
.
getCenter
(
tester
.
find
ElementByKey
(
blockKey
));
TestPointer
pointer
=
new
TestPointer
();
TestPointer
pointer
=
new
TestPointer
();
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
...
...
packages/unit/test/widget/box_decoration_test.dart
View file @
06ffa759
import
'package:sky/material.dart'
;
import
'package:sky/material.dart'
;
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
test
(
'Circles can have uniform borders'
,
()
{
test
(
'Circles can have uniform borders'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
()
{
tester
.
pumpFrame
(
return
new
Container
(
new
Container
(
padding:
new
EdgeDims
.
all
(
50.0
),
padding:
new
EdgeDims
.
all
(
50.0
),
decoration:
new
BoxDecoration
(
decoration:
new
BoxDecoration
(
shape:
Shape
.
circle
,
shape:
Shape
.
circle
,
border:
new
Border
.
all
(
width:
10.0
,
color:
const
Color
(
0x80FF00FF
)),
border:
new
Border
.
all
(
width:
10.0
,
color:
const
Color
(
0x80FF00FF
)),
backgroundColor:
Colors
.
teal
[
600
]
backgroundColor:
Colors
.
teal
[
600
]
)
)
)
);
);
});
});
});
}
}
packages/unit/test/widget/center_test.dart
View file @
06ffa759
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
test
(
'Can be placed in an infinte box'
,
()
{
test
(
'Can be placed in an infinte box'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
tester
.
pumpFrame
(
new
Block
([
new
Center
()]));
return
new
Block
([
new
Center
()]);
});
});
});
}
}
packages/unit/test/widget/date_picker_test.dart
View file @
06ffa759
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
test
(
'Can select a day'
,
()
{
test
(
'Can select a day'
,
()
{
...
@@ -9,8 +9,7 @@ void main() {
...
@@ -9,8 +9,7 @@ void main() {
DateTime
currentValue
;
DateTime
currentValue
;
Widget
builder
()
{
Widget
widget
=
new
Block
([
return
new
Block
([
new
DatePicker
(
new
DatePicker
(
selectedDate:
new
DateTime
.
utc
(
2015
,
6
,
9
,
7
,
12
),
selectedDate:
new
DateTime
.
utc
(
2015
,
6
,
9
,
7
,
12
),
firstDate:
new
DateTime
.
utc
(
2013
),
firstDate:
new
DateTime
.
utc
(
2013
),
...
@@ -20,15 +19,14 @@ void main() {
...
@@ -20,15 +19,14 @@ void main() {
}
}
)
)
]);
]);
}
tester
.
pumpFrame
(
builder
);
tester
.
pumpFrame
(
widget
);
expect
(
currentValue
,
isNull
);
expect
(
currentValue
,
isNull
);
tester
.
tap
(
tester
.
findText
(
'2015'
));
tester
.
tap
(
tester
.
findText
(
'2015'
));
tester
.
pumpFrame
(
builder
);
tester
.
pumpFrame
(
widget
);
tester
.
tap
(
tester
.
findText
(
'2014'
));
tester
.
tap
(
tester
.
findText
(
'2014'
));
tester
.
pumpFrame
(
builder
);
tester
.
pumpFrame
(
widget
);
expect
(
currentValue
,
equals
(
new
DateTime
(
2014
,
6
,
9
)));
expect
(
currentValue
,
equals
(
new
DateTime
(
2014
,
6
,
9
)));
tester
.
tap
(
tester
.
findText
(
'30'
));
tester
.
tap
(
tester
.
findText
(
'30'
));
expect
(
currentValue
,
equals
(
new
DateTime
(
2013
,
1
,
30
)));
expect
(
currentValue
,
equals
(
new
DateTime
(
2013
,
1
,
30
)));
...
...
packages/unit/test/widget/duplicate_key_test.dart
View file @
06ffa759
import
'package:sky/src/widgets/framework.dart'
;
import
'package:sky/src/fn3.dart'
;
import
'package:sky/src/widgets/basic.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'../fn3/widget_tester.dart'
;
class
Item
{
class
Item
{
GlobalKey
key1
=
new
GlobalKey
();
GlobalKey
key1
=
new
GlobalKey
();
...
@@ -12,15 +12,18 @@ List<Item> items = [new Item(), new Item()];
...
@@ -12,15 +12,18 @@ List<Item> items = [new Item(), new Item()];
class
StatefulLeaf
extends
StatefulComponent
{
class
StatefulLeaf
extends
StatefulComponent
{
StatefulLeaf
({
GlobalKey
key
})
:
super
(
key:
key
);
StatefulLeaf
({
GlobalKey
key
})
:
super
(
key:
key
);
void
syncConstructorArguments
(
StatefulLeaf
source
)
{
}
StatefulLeafState
createState
()
=>
new
StatefulLeafState
();
}
class
StatefulLeafState
extends
State
<
StatefulLeaf
>
{
void
test
()
{
setState
(()
{
});
}
void
test
()
{
setState
(()
{
});
}
Widget
build
()
=>
new
Text
(
'leaf'
);
Widget
build
(
BuildContext
context
)
=>
new
Text
(
'leaf'
);
}
}
class
KeyedWrapper
extends
Component
{
class
KeyedWrapper
extends
Stateless
Component
{
KeyedWrapper
(
this
.
key1
,
this
.
key2
);
KeyedWrapper
(
this
.
key1
,
this
.
key2
);
Key
key1
,
key2
;
Key
key1
,
key2
;
Widget
build
()
{
Widget
build
(
BuildContext
context
)
{
return
new
Container
(
return
new
Container
(
key:
key1
,
key:
key1
,
child:
new
StatefulLeaf
(
child:
new
StatefulLeaf
(
...
@@ -40,13 +43,13 @@ Widget builder() {
...
@@ -40,13 +43,13 @@ Widget builder() {
void
main
(
)
{
void
main
(
)
{
test
(
'duplicate key smoke test'
,
()
{
test
(
'duplicate key smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
builder
);
tester
.
pumpFrame
(
builder
()
);
StatefulLeaf
leaf
=
tester
.
findWidget
((
widget
)
=>
widget
is
StatefulLeaf
);
StatefulLeaf
State
leaf
=
tester
.
findStateOfType
(
StatefulLeafState
);
leaf
.
test
();
leaf
.
test
();
tester
.
pumpFrameWithoutChange
();
tester
.
pumpFrameWithoutChange
();
Item
lastItem
=
items
[
1
];
Item
lastItem
=
items
[
1
];
items
.
remove
(
lastItem
);
items
.
remove
(
lastItem
);
items
.
insert
(
0
,
lastItem
);
items
.
insert
(
0
,
lastItem
);
tester
.
pumpFrame
(
builder
);
// this marks the app dirty and rebuilds it
tester
.
pumpFrame
(
builder
()
);
// this marks the app dirty and rebuilds it
});
});
}
}
packages/unit/test/widget/flex_test.dart
View file @
06ffa759
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
test
(
'Can hit test flex children of stacks'
,
()
{
test
(
'Can hit test flex children of stacks'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
bool
didReceiveTap
=
false
;
bool
didReceiveTap
=
false
;
tester
.
pumpFrame
(
()
{
tester
.
pumpFrame
(
return
new
Container
(
new
Container
(
decoration:
const
BoxDecoration
(
decoration:
const
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
)
backgroundColor:
const
Color
(
0xFF00FF00
)
),
),
...
@@ -36,8 +36,8 @@ void main() {
...
@@ -36,8 +36,8 @@ void main() {
])
])
)
)
])
])
)
);
);
});
tester
.
tap
(
tester
.
findText
(
'X'
));
tester
.
tap
(
tester
.
findText
(
'X'
));
expect
(
didReceiveTap
,
isTrue
);
expect
(
didReceiveTap
,
isTrue
);
...
...
packages/unit/test/widget/gesture_detector_test.dart
View file @
06ffa759
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'../engine/mock_events.dart'
;
import
'../engine/mock_events.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
test
(
'Uncontested scrolls start immediately'
,
()
{
test
(
'Uncontested scrolls start immediately'
,
()
{
...
@@ -13,8 +13,7 @@ void main() {
...
@@ -13,8 +13,7 @@ void main() {
double
updatedDragDelta
;
double
updatedDragDelta
;
bool
didEndDrag
=
false
;
bool
didEndDrag
=
false
;
Widget
builder
()
{
Widget
widget
=
new
GestureDetector
(
return
new
GestureDetector
(
onVerticalDragStart:
()
{
onVerticalDragStart:
()
{
didStartDrag
=
true
;
didStartDrag
=
true
;
},
},
...
@@ -26,9 +25,8 @@ void main() {
...
@@ -26,9 +25,8 @@ void main() {
},
},
child:
new
Container
()
child:
new
Container
()
);
);
}
tester
.
pumpFrame
(
builder
);
tester
.
pumpFrame
(
widget
);
expect
(
didStartDrag
,
isFalse
);
expect
(
didStartDrag
,
isFalse
);
expect
(
updatedDragDelta
,
isNull
);
expect
(
updatedDragDelta
,
isNull
);
expect
(
didEndDrag
,
isFalse
);
expect
(
didEndDrag
,
isFalse
);
...
@@ -53,7 +51,7 @@ void main() {
...
@@ -53,7 +51,7 @@ void main() {
expect
(
didEndDrag
,
isTrue
);
expect
(
didEndDrag
,
isTrue
);
didEndDrag
=
false
;
didEndDrag
=
false
;
tester
.
pumpFrame
(
()
=>
new
Container
());
tester
.
pumpFrame
(
new
Container
());
});
});
test
(
'Match two scroll gestures in succession'
,
()
{
test
(
'Match two scroll gestures in succession'
,
()
{
...
@@ -66,16 +64,14 @@ void main() {
...
@@ -66,16 +64,14 @@ void main() {
Point
downLocation
=
new
Point
(
10.0
,
10.0
);
Point
downLocation
=
new
Point
(
10.0
,
10.0
);
Point
upLocation
=
new
Point
(
10.0
,
20.0
);
Point
upLocation
=
new
Point
(
10.0
,
20.0
);
Widget
builder
()
{
Widget
widget
=
new
GestureDetector
(
return
new
GestureDetector
(
onVerticalDragUpdate:
(
double
delta
)
{
dragDistance
+=
delta
;
},
onVerticalDragUpdate:
(
double
delta
)
{
dragDistance
+=
delta
;
},
onVerticalDragEnd:
(
Offset
velocity
)
{
gestureCount
+=
1
;
},
onVerticalDragEnd:
(
Offset
velocity
)
{
gestureCount
+=
1
;
},
onHorizontalDragUpdate:
(
_
)
{
fail
(
"gesture should not match"
);
},
onHorizontalDragUpdate:
(
_
)
{
fail
(
"gesture should not match"
);
},
onHorizontalDragEnd:
(
Offset
velocity
)
{
fail
(
"gesture should not match"
);
},
onHorizontalDragEnd:
(
Offset
velocity
)
{
fail
(
"gesture should not match"
);
},
child:
new
Container
()
child:
new
Container
()
);
);
}
tester
.
pumpFrame
(
widget
);
tester
.
pumpFrame
(
builder
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
downLocation
);
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
downLocation
);
...
@@ -87,5 +83,7 @@ void main() {
...
@@ -87,5 +83,7 @@ void main() {
expect
(
gestureCount
,
2
);
expect
(
gestureCount
,
2
);
expect
(
dragDistance
,
20.0
);
expect
(
dragDistance
,
20.0
);
tester
.
pumpFrame
(
new
Container
());
});
});
}
}
packages/unit/test/widget/homogeneous_viewport_test.dart
deleted
100644 → 0
View file @
b5893f9e
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
class
TestComponent
extends
StatefulComponent
{
TestComponent
(
this
.
viewport
);
HomogeneousViewport
viewport
;
void
syncConstructorArguments
(
TestComponent
source
)
{
viewport
=
source
.
viewport
;
}
bool
_flag
=
true
;
void
go
(
bool
flag
)
{
setState
(()
{
_flag
=
flag
;
});
}
Widget
build
()
{
return
_flag
?
viewport
:
new
Text
(
'Not Today'
);
}
}
void
main
(
)
{
test
(
'HomogeneousViewport mount/dismount smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 100 pixels tall, it should fit exactly 6 times.
TestComponent
testComponent
;
Widget
builder
()
{
testComponent
=
new
TestComponent
(
new
HomogeneousViewport
(
builder:
(
int
start
,
int
count
)
{
List
<
Widget
>
result
=
<
Widget
>[];
for
(
int
index
=
start
;
index
<
start
+
count
;
index
+=
1
)
{
callbackTracker
.
add
(
index
);
result
.
add
(
new
Container
(
key:
new
ValueKey
<
int
>(
index
),
height:
100.0
,
child:
new
Text
(
"
$index
"
)
));
}
return
result
;
},
startOffset:
0.0
,
itemExtent:
100.0
));
return
testComponent
;
}
tester
.
pumpFrame
(
builder
);
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
testComponent
.
go
(
false
);
tester
.
pumpFrameWithoutChange
();
expect
(
callbackTracker
,
equals
([]));
callbackTracker
.
clear
();
testComponent
.
go
(
true
);
tester
.
pumpFrameWithoutChange
();
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
});
test
(
'HomogeneousViewport vertical'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 200 pixels tall, it should fit exactly 3 times.
// but if we are offset by 300 pixels, there will be 4, numbered 1-4.
double
offset
=
300.0
;
ListBuilder
itemBuilder
=
(
int
start
,
int
count
)
{
List
<
Widget
>
result
=
<
Widget
>[];
for
(
int
index
=
start
;
index
<
start
+
count
;
index
+=
1
)
{
callbackTracker
.
add
(
index
);
result
.
add
(
new
Container
(
key:
new
ValueKey
<
int
>(
index
),
width:
500.0
,
// this should be ignored
height:
400.0
,
// should be overridden by itemExtent
child:
new
Text
(
"
$index
"
)
));
}
return
result
;
};
TestComponent
testComponent
;
Widget
builder
()
{
testComponent
=
new
TestComponent
(
new
HomogeneousViewport
(
builder:
itemBuilder
,
startOffset:
offset
,
itemExtent:
200.0
));
return
testComponent
;
}
tester
.
pumpFrame
(
builder
);
expect
(
callbackTracker
,
equals
([
1
,
2
,
3
,
4
]));
callbackTracker
.
clear
();
offset
=
400.0
;
// now only 3 should fit, numbered 2-4.
tester
.
pumpFrame
(
builder
);
expect
(
callbackTracker
,
equals
([
2
,
3
,
4
]));
callbackTracker
.
clear
();
});
test
(
'HomogeneousViewport horizontal'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 200 pixels wide, it should fit exactly 4 times.
// but if we are offset by 300 pixels, there will be 5, numbered 1-5.
double
offset
=
300.0
;
ListBuilder
itemBuilder
=
(
int
start
,
int
count
)
{
List
<
Widget
>
result
=
<
Widget
>[];
for
(
int
index
=
start
;
index
<
start
+
count
;
index
+=
1
)
{
callbackTracker
.
add
(
index
);
result
.
add
(
new
Container
(
key:
new
ValueKey
<
int
>(
index
),
width:
400.0
,
// this should be overridden by itemExtent
height:
500.0
,
// this should be ignored
child:
new
Text
(
"
$index
"
)
));
}
return
result
;
};
TestComponent
testComponent
;
Widget
builder
()
{
testComponent
=
new
TestComponent
(
new
HomogeneousViewport
(
builder:
itemBuilder
,
startOffset:
offset
,
itemExtent:
200.0
,
direction:
ScrollDirection
.
horizontal
));
return
testComponent
;
}
tester
.
pumpFrame
(
builder
);
expect
(
callbackTracker
,
equals
([
1
,
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
offset
=
400.0
;
// now only 4 should fit, numbered 2-5.
tester
.
pumpFrame
(
builder
);
expect
(
callbackTracker
,
equals
([
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
});
}
packages/unit/test/widget/listener_test.dart
View file @
06ffa759
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
void
main
(
)
{
test
(
'Events bubble up the tree'
,
()
{
test
(
'Events bubble up the tree'
,
()
{
...
@@ -9,8 +9,8 @@ void main() {
...
@@ -9,8 +9,8 @@ void main() {
List
<
String
>
log
=
new
List
<
String
>();
List
<
String
>
log
=
new
List
<
String
>();
tester
.
pumpFrame
(
()
{
tester
.
pumpFrame
(
return
new
Listener
(
new
Listener
(
onPointerDown:
(
_
)
{
onPointerDown:
(
_
)
{
log
.
add
(
'top'
);
log
.
add
(
'top'
);
},
},
...
@@ -28,8 +28,8 @@ void main() {
...
@@ -28,8 +28,8 @@ void main() {
)
)
)
)
)
)
)
);
);
});
tester
.
tap
(
tester
.
findText
(
'X'
));
tester
.
tap
(
tester
.
findText
(
'X'
));
...
...
packages/unit/test/widget/mixed_viewport_test.dart
deleted
100644 → 0
View file @
b5893f9e
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
class
TestComponent
extends
StatefulComponent
{
TestComponent
(
this
.
viewport
);
MixedViewport
viewport
;
void
syncConstructorArguments
(
TestComponent
source
)
{
viewport
=
source
.
viewport
;
}
bool
_flag
=
true
;
void
go
(
bool
flag
)
{
setState
(()
{
_flag
=
flag
;
});
}
Widget
build
()
{
return
_flag
?
viewport
:
new
Text
(
'Not Today'
);
}
}
void
main
(
)
{
test
(
'MixedViewport mount/dismount smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
MixedViewportLayoutState
layoutState
=
new
MixedViewportLayoutState
();
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 100 pixels tall, it should fit exactly 6 times.
TestComponent
testComponent
;
Widget
builder
()
{
testComponent
=
new
TestComponent
(
new
MixedViewport
(
builder:
(
int
i
)
{
callbackTracker
.
add
(
i
);
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
height:
100.0
,
child:
new
Text
(
"
$i
"
)
);
},
startOffset:
0.0
,
layoutState:
layoutState
));
return
testComponent
;
}
tester
.
pumpFrame
(
builder
);
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
testComponent
.
go
(
false
);
tester
.
pumpFrameWithoutChange
();
expect
(
callbackTracker
,
equals
([]));
callbackTracker
.
clear
();
testComponent
.
go
(
true
);
tester
.
pumpFrameWithoutChange
();
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
});
test
(
'MixedViewport vertical'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
MixedViewportLayoutState
layoutState
=
new
MixedViewportLayoutState
();
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 200 pixels tall, it should fit exactly 3 times.
// but if we are offset by 300 pixels, there will be 4, numbered 1-4.
double
offset
=
300.0
;
IndexedBuilder
itemBuilder
=
(
int
i
)
{
callbackTracker
.
add
(
i
);
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
width:
500.0
,
// this should be ignored
height:
200.0
,
child:
new
Text
(
"
$i
"
)
);
};
TestComponent
testComponent
;
Widget
builder
()
{
testComponent
=
new
TestComponent
(
new
MixedViewport
(
builder:
itemBuilder
,
startOffset:
offset
,
layoutState:
layoutState
));
return
testComponent
;
}
tester
.
pumpFrame
(
builder
);
// 0 is built to find its width
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
]));
callbackTracker
.
clear
();
offset
=
400.0
;
// now only 3 should fit, numbered 2-4.
tester
.
pumpFrame
(
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
();
MixedViewportLayoutState
layoutState
=
new
MixedViewportLayoutState
();
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 200 pixels wide, it should fit exactly 4 times.
// but if we are offset by 300 pixels, there will be 5, numbered 1-5.
double
offset
=
300.0
;
IndexedBuilder
itemBuilder
=
(
int
i
)
{
callbackTracker
.
add
(
i
);
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
height:
500.0
,
// this should be ignored
width:
200.0
,
child:
new
Text
(
"
$i
"
)
);
};
TestComponent
testComponent
;
Widget
builder
()
{
testComponent
=
new
TestComponent
(
new
MixedViewport
(
builder:
itemBuilder
,
startOffset:
offset
,
layoutState:
layoutState
,
direction:
ScrollDirection
.
horizontal
));
return
testComponent
;
}
tester
.
pumpFrame
(
builder
);
// 0 is built to find its width
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
offset
=
400.0
;
// now only 4 should fit, numbered 2-5.
tester
.
pumpFrame
(
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/navigator_test.dart
View file @
06ffa759
import
'package:sky/animation.dart'
;
import
'package:sky/animation.dart'
;
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
class
FirstComponent
extends
Component
{
class
FirstComponent
extends
Stateless
Component
{
FirstComponent
(
this
.
navigator
);
FirstComponent
(
this
.
navigator
);
final
Navigator
navigator
;
final
Navigator
State
navigator
;
Widget
build
()
{
Widget
build
(
BuildContext
context
)
{
return
new
GestureDetector
(
return
new
GestureDetector
(
onTap:
()
{
onTap:
()
{
navigator
.
pushNamed
(
'/second'
);
navigator
.
pushNamed
(
'/second'
);
...
@@ -27,15 +27,15 @@ class FirstComponent extends Component {
...
@@ -27,15 +27,15 @@ class FirstComponent extends Component {
class
SecondComponent
extends
StatefulComponent
{
class
SecondComponent
extends
StatefulComponent
{
SecondComponent
(
this
.
navigator
);
SecondComponent
(
this
.
navigator
);
Navigator
navigator
;
final
NavigatorState
navigator
;
void
syncConstructorArguments
(
SecondComponent
source
)
{
SecondComponentState
createState
()
=>
new
SecondComponentState
();
navigator
=
source
.
navigator
;
}
}
Widget
build
()
{
class
SecondComponentState
extends
State
<
SecondComponent
>
{
Widget
build
(
BuildContext
context
)
{
return
new
GestureDetector
(
return
new
GestureDetector
(
onTap:
navigator
.
pop
,
onTap:
config
.
navigator
.
pop
,
child:
new
Container
(
child:
new
Container
(
decoration:
new
BoxDecoration
(
decoration:
new
BoxDecoration
(
backgroundColor:
new
Color
(
0xFFFF00FF
)
backgroundColor:
new
Color
(
0xFFFF00FF
)
...
@@ -50,7 +50,7 @@ void main() {
...
@@ -50,7 +50,7 @@ void main() {
test
(
'Can navigator navigate to and from a stateful component'
,
()
{
test
(
'Can navigator navigate to and from a stateful component'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
WidgetTester
tester
=
new
WidgetTester
();
final
Navigat
ionState
routes
=
new
NavigationState
([
final
Navigat
orHistory
routes
=
new
NavigatorHistory
([
new
Route
(
new
Route
(
name:
'/'
,
name:
'/'
,
builder:
(
navigator
,
route
)
=>
new
FirstComponent
(
navigator
)
builder:
(
navigator
,
route
)
=>
new
FirstComponent
(
navigator
)
...
@@ -61,9 +61,7 @@ void main() {
...
@@ -61,9 +61,7 @@ void main() {
)
)
]);
]);
tester
.
pumpFrame
(()
{
tester
.
pumpFrame
(
new
Navigator
(
routes
));
return
new
Navigator
(
routes
);
});
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'Y'
),
isNull
);
expect
(
tester
.
findText
(
'Y'
),
isNull
);
...
...
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