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
7d02880c
Commit
7d02880c
authored
Sep 25, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port some more tests to fn3
parent
06ffa759
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
172 additions
and
124 deletions
+172
-124
scrollable.dart
packages/flutter/lib/src/fn3/scrollable.dart
+13
-10
widget_tester.dart
packages/unit/test/fn3/widget_tester.dart
+27
-0
progress_indicator_test.dart
packages/unit/test/widget/progress_indicator_test.dart
+6
-9
set_state_3_test.dart
packages/unit/test/widget/set_state_3_test.dart
+31
-16
set_state_test.dart
packages/unit/test/widget/set_state_test.dart
+19
-23
stack_test.dart
packages/unit/test/widget/stack_test.dart
+31
-28
stateful_components_test.dart
packages/unit/test/widget/stateful_components_test.dart
+45
-38
No files found.
packages/flutter/lib/src/fn3/scrollable.dart
View file @
7d02880c
...
...
@@ -312,10 +312,9 @@ abstract class ScrollableWidgetList extends Scrollable {
assert
(
itemExtent
!=
null
);
}
EdgeDims
padding
;
bool
itemsWrap
;
double
itemExtent
;
Size
containerSize
=
Size
.
zero
;
final
bool
itemsWrap
;
final
double
itemExtent
;
final
EdgeDims
padding
;
}
abstract
class
ScrollableWidgetListState
<
T
extends
ScrollableWidgetList
>
extends
ScrollableState
<
T
>
{
...
...
@@ -324,6 +323,8 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends
int
get
itemCount
;
int
_previousItemCount
;
Size
_containerSize
=
Size
.
zero
;
void
didUpdateConfig
(
T
oldConfig
)
{
super
.
didUpdateConfig
(
oldConfig
);
...
...
@@ -351,13 +352,13 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends
double
get
_containerExtent
{
return
config
.
scrollDirection
==
ScrollDirection
.
vertical
?
config
.
containerSize
.
height
:
config
.
containerSize
.
width
;
?
_
containerSize
.
height
:
_
containerSize
.
width
;
}
void
_handleSizeChanged
(
Size
newSize
)
{
setState
(()
{
config
.
containerSize
=
newSize
;
_
containerSize
=
newSize
;
_updateScrollBehavior
();
});
}
...
...
@@ -501,9 +502,11 @@ class PageableList<T> extends ScrollableList<T> {
padding:
padding
);
Duration
duration
;
Curve
curve
;
PageChangedCallback
pageChanged
;
final
Duration
duration
;
final
Curve
curve
;
final
PageChangedCallback
pageChanged
;
PageableListState
<
T
>
createState
()
=>
new
PageableListState
();
}
class
PageableListState
<
T
>
extends
ScrollableListState
<
T
,
PageableList
<
T
>>
{
...
...
packages/unit/test/fn3/widget_tester.dart
View file @
7d02880c
...
...
@@ -34,6 +34,21 @@ class WidgetTester {
}
List
<
Layer
>
_layers
(
Layer
layer
)
{
List
<
Layer
>
result
=
[
layer
];
if
(
layer
is
ContainerLayer
)
{
ContainerLayer
root
=
layer
;
Layer
child
=
root
.
firstChild
;
while
(
child
!=
null
)
{
result
.
addAll
(
_layers
(
child
));
child
=
child
.
nextSibling
;
}
}
return
result
;
}
List
<
Layer
>
get
layers
=>
_layers
(
SkyBinding
.
instance
.
renderView
.
layer
);
void
walkElements
(
ElementVisitor
visitor
)
{
void
walk
(
Element
element
)
{
visitor
(
element
);
...
...
@@ -110,6 +125,18 @@ class WidgetTester {
_dispatchEvent
(
p
.
up
(),
result
);
}
void
scroll
(
Element
element
,
Offset
offset
,
{
int
pointer:
1
})
{
Point
startLocation
=
getCenter
(
element
);
Point
endLocation
=
startLocation
+
offset
;
TestPointer
p
=
new
TestPointer
(
pointer
);
// Events for the entire press-drag-release gesture are dispatched
// to the widgets "hit" by the pointer down event.
HitTestResult
result
=
_hitTest
(
startLocation
);
_dispatchEvent
(
p
.
down
(
startLocation
),
result
);
_dispatchEvent
(
p
.
move
(
endLocation
),
result
);
_dispatchEvent
(
p
.
up
(),
result
);
}
void
dispatchEvent
(
sky
.
Event
event
,
Point
location
)
{
_dispatchEvent
(
event
,
_hitTest
(
location
));
}
...
...
packages/unit/test/widget/progress_indicator_test.dart
View file @
7d02880c
import
'package:sky/rendering.dart'
;
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
test
(
'LinearProgressIndicator changes when its value changes'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Block
([
new
LinearProgressIndicator
(
value:
0.0
)]);
});
tester
.
pumpFrame
(
new
Block
([
new
LinearProgressIndicator
(
value:
0.0
)]));
List
<
Layer
>
layers1
=
tester
.
layers
;
tester
.
pumpFrame
(()
{
return
new
Block
([
new
LinearProgressIndicator
(
value:
0.5
)]);
});
List
<
Layer
>
layers2
=
tester
.
layers
;
tester
.
pumpFrame
(
new
Block
([
new
LinearProgressIndicator
(
value:
0.5
)]));
List
<
Layer
>
layers2
=
tester
.
layers
;
expect
(
layers1
,
isNot
(
equals
(
layers2
)));
});
}
packages/unit/test/widget/set_state_3_test.dart
View file @
7d02880c
...
...
@@ -2,40 +2,55 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:sky/src/widgets/basic.dart'
;
import
'package:sky/src/widgets/framework.dart'
;
import
'package:sky/src/fn3.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
Changer
changer
;
import
'../fn3/widget_tester.dart'
;
ChangerState
changer
;
class
Changer
extends
StatefulComponent
{
Changer
(
this
.
child
);
Widget
child
;
void
syncConstructorArguments
(
Changer
source
)
{
child
=
source
.
child
;
}
final
Widget
child
;
ChangerState
createState
()
=>
new
ChangerState
();
}
class
ChangerState
extends
State
<
Changer
>
{
bool
_state
=
false
;
void
initState
()
{
changer
=
this
;
}
void
initState
(
BuildContext
context
)
{
super
.
initState
(
context
);
changer
=
this
;
}
void
test
()
{
setState
(()
{
_state
=
true
;
});
}
Widget
build
()
=>
_state
?
new
Wrapper
(
child
)
:
child
;
Widget
build
(
BuildContext
)
=>
_state
?
new
Wrapper
(
config
.
child
)
:
config
.
child
;
}
class
Wrapper
extends
Component
{
class
Wrapper
extends
Stateless
Component
{
Wrapper
(
this
.
child
);
final
Widget
child
;
Widget
build
()
=>
child
;
Widget
build
(
BuildContext
context
)
=>
child
;
}
class
Leaf
extends
StatefulComponent
{
void
syncConstructorArguments
(
Leaf
source
)
{
}
Widget
build
()
=>
new
Text
(
"leaf"
);
LeafState
createState
()
=>
new
LeafState
();
}
class
LeafState
extends
State
<
Leaf
>
{
Widget
build
(
BuildContext
context
)
=>
new
Text
(
"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
())));
tester
.
pumpFrame
(
new
Changer
(
new
Wrapper
(
new
Leaf
())));
tester
.
pumpFrame
(
new
Changer
(
new
Wrapper
(
new
Leaf
())));
changer
.
test
();
tester
.
pumpFrameWithoutChange
();
});
...
...
packages/unit/test/widget/set_state_test.dart
View file @
7d02880c
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'../engine/mock_events.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
class
Inside
extends
StatefulComponent
{
void
syncConstructorArguments
(
Inside
source
)
{
}
InsideState
createState
()
=>
new
InsideState
();
}
Widget
build
()
{
class
InsideState
extends
State
<
Inside
>
{
Widget
build
(
BuildContext
context
)
{
return
new
Listener
(
onPointerDown:
_handlePointerDown
,
child:
new
Text
(
'INSIDE'
)
...
...
@@ -21,29 +22,32 @@ class Inside extends StatefulComponent {
}
class
Middle
extends
StatefulComponent
{
Inside
child
;
Middle
({
this
.
child
});
void
syncConstructorArguments
(
Middle
source
)
{
child
=
source
.
child
;
}
final
Inside
child
;
Widget
build
()
{
MiddleState
createState
()
=>
new
MiddleState
();
}
class
MiddleState
extends
State
<
Middle
>
{
Widget
build
(
BuildContext
context
)
{
return
new
Listener
(
onPointerDown:
_handlePointerDown
,
child:
child
child:
c
onfig
.
c
hild
);
}
void
_handlePointerDown
(
_
)
{
setState
(()
{
});
}
}
class
Outside
extends
StatefulComponent
{
OutsideState
createState
()
=>
new
OutsideState
();
}
class
Outside
extends
App
{
Widget
build
()
{
class
Outside
State
extends
State
<
Outside
>
{
Widget
build
(
BuildContext
context
)
{
return
new
Middle
(
child:
new
Inside
());
}
}
...
...
@@ -51,20 +55,12 @@ class Outside extends App {
void
main
(
)
{
test
(
'setState() smoke test'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Outside
();
});
tester
.
pumpFrame
(
new
Outside
());
TestPointer
pointer
=
new
TestPointer
(
1
);
Point
location
=
tester
.
getCenter
(
tester
.
findText
(
'INSIDE'
));
tester
.
dispatchEvent
(
pointer
.
down
(
location
),
location
);
tester
.
pumpFrameWithoutChange
();
tester
.
dispatchEvent
(
pointer
.
up
(),
location
);
tester
.
pumpFrameWithoutChange
();
});
}
packages/unit/test/widget/stack_test.dart
View file @
7d02880c
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
test
(
'Can change position data'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Stack
([
Key
key
=
new
Key
(
'container'
);
tester
.
pumpFrame
(
new
Stack
([
new
Positioned
(
left:
10.0
,
child:
new
Container
(
key:
key
,
width:
10.0
,
height:
10.0
)
)
])
;
}
);
])
);
Container
container
=
tester
.
findWidget
((
Widget
widget
)
=>
widget
is
Container
);
Element
container
=
tester
.
findElementByKey
(
key
);
expect
(
container
.
renderObject
.
parentData
.
top
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
right
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
left
,
equals
(
10.0
));
tester
.
pumpFrame
(
()
{
return
new
Stack
([
tester
.
pumpFrame
(
new
Stack
([
new
Positioned
(
right:
10.0
,
child:
new
Container
(
key:
key
,
width:
10.0
,
height:
10.0
)
)
])
;
}
);
])
);
container
=
tester
.
find
Widget
((
Widget
widget
)
=>
widget
is
Container
);
container
=
tester
.
find
ElementByKey
(
key
);
expect
(
container
.
renderObject
.
parentData
.
top
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
right
,
equals
(
10.0
));
expect
(
container
.
renderObject
.
parentData
.
bottom
,
isNull
);
...
...
@@ -46,26 +50,25 @@ void main() {
test
(
'Can remove parent data'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
Container
container
;
tester
.
pumpFrame
(()
{
container
=
new
Container
(
width:
10.0
,
height:
10.0
);
return
new
Stack
([
new
Positioned
(
left:
10.0
,
child:
container
)
]);
});
Key
key
=
new
Key
(
'container'
);
Container
container
=
new
Container
(
key:
key
,
width:
10.0
,
height:
10.0
);
expect
(
container
.
renderObject
.
parentData
.
top
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
right
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
left
,
equals
(
10.0
));
tester
.
pumpFrame
(
new
Stack
([
new
Positioned
(
left:
10.0
,
child:
container
)
]));
Element
containerElement
=
tester
.
findElementByKey
(
key
);
tester
.
pumpFrame
(()
{
return
new
Stack
([
container
]);
});
expect
(
containerElement
.
renderObject
.
parentData
.
top
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
right
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
left
,
equals
(
10.0
));
expect
(
container
.
renderObject
.
parentData
.
top
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
right
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
container
.
renderObject
.
parentData
.
left
,
isNull
);
tester
.
pumpFrame
(
new
Stack
([
container
]));
containerElement
=
tester
.
findElementByKey
(
key
);
expect
(
containerElement
.
renderObject
.
parentData
.
top
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
right
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
bottom
,
isNull
);
expect
(
containerElement
.
renderObject
.
parentData
.
left
,
isNull
);
});
}
packages/unit/test/widget/stateful_components_test.dart
View file @
7d02880c
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
class
InnerComponent
extends
StatefulComponent
{
InnerComponent
();
InnerComponent
({
Key
key
})
:
super
(
key:
key
);
InnerComponentState
createState
()
=>
new
InnerComponentState
();
}
class
InnerComponentState
extends
State
<
InnerComponent
>
{
bool
_didInitState
=
false
;
void
initState
()
{
void
initState
(
BuildContext
context
)
{
super
.
initState
(
context
);
_didInitState
=
true
;
}
void
syncConstructorArguments
(
InnerComponent
source
)
{
}
Widget
build
()
{
Widget
build
(
BuildContext
context
)
{
return
new
Container
();
}
}
class
OuterContainer
extends
StatefulComponent
{
OuterContainer
({
this
.
child
}
);
OuterContainer
({
Key
key
,
this
.
child
})
:
super
(
key:
key
);
InnerComponent
child
;
final
InnerComponent
child
;
void
syncConstructorArguments
(
OuterContainer
source
)
{
child
=
source
.
child
;
}
OuterContainerState
createState
()
=>
new
OuterContainerState
();
}
Widget
build
()
{
return
child
;
class
OuterContainerState
extends
State
<
OuterContainer
>
{
Widget
build
(
BuildContext
context
)
{
return
config
.
child
;
}
}
...
...
@@ -39,36 +40,42 @@ void main() {
WidgetTester
tester
=
new
WidgetTester
();
InnerComponent
inner1
;
Key
innerKey
=
new
Key
(
'inner'
);
Key
outerKey
=
new
Key
(
'outer'
);
InnerComponent
inner1
=
new
InnerComponent
(
key:
innerKey
);
InnerComponent
inner2
;
OuterContainer
outer
;
OuterContainer
outer1
=
new
OuterContainer
(
key:
outerKey
,
child:
inner1
);
OuterContainer
outer2
;
tester
.
pumpFrame
(()
{
inner1
=
new
InnerComponent
();
outer
=
new
OuterContainer
(
child:
inner1
);
return
outer
;
});
tester
.
pumpFrame
(
outer1
);
expect
(
inner1
.
_didInitState
,
isTrue
);
expect
(
inner1
.
parent
,
isNotNull
);
StatefulComponentElement
innerElement
=
tester
.
findElementByKey
(
innerKey
);
InnerComponentState
innerElementState
=
innerElement
.
state
;
expect
(
innerElementState
.
config
,
equals
(
inner1
));
expect
(
innerElementState
.
_didInitState
,
isTrue
);
expect
(
innerElement
.
renderObject
.
attached
,
isTrue
);
tester
.
pumpFrame
(()
{
inner2
=
new
InnerComponent
();
return
new
OuterContainer
(
child:
inner2
);
});
inner2
=
new
InnerComponent
(
key:
innerKey
);
outer2
=
new
OuterContainer
(
key:
outerKey
,
child:
inner2
);
expect
(
inner1
.
_didInitState
,
isTrue
);
expect
(
inner1
.
parent
,
isNotNull
);
expect
(
inner2
.
_didInitState
,
isFalse
);
expect
(
inner2
.
parent
,
isNull
);
tester
.
pumpFrame
(
outer2
);
outer
.
setState
(()
{}
);
tester
.
pumpFrameWithoutChange
(
0.0
);
expect
(
tester
.
findElementByKey
(
innerKey
),
equals
(
innerElement
)
);
expect
(
innerElement
.
state
,
equals
(
innerElementState
)
);
expect
(
inner1
.
_didInitState
,
isTrue
);
expect
(
inner1
.
parent
,
isNotNull
);
expect
(
inner2
.
_didInitState
,
isFalse
);
expect
(
inner2
.
parent
,
isNull
);
expect
(
innerElementState
.
config
,
equals
(
inner2
));
expect
(
innerElementState
.
_didInitState
,
isTrue
);
expect
(
innerElement
.
renderObject
.
attached
,
isTrue
);
StatefulComponentElement
outerElement
=
tester
.
findElementByKey
(
outerKey
);
expect
(
outerElement
.
state
.
config
,
equals
(
outer2
));
outerElement
.
state
.
setState
(()
{});
tester
.
pumpFrameWithoutChange
(
0.0
);
expect
(
tester
.
findElementByKey
(
innerKey
),
equals
(
innerElement
));
expect
(
innerElement
.
state
,
equals
(
innerElementState
));
expect
(
innerElementState
.
config
,
equals
(
inner2
));
expect
(
innerElement
.
renderObject
.
attached
,
isTrue
);
});
}
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