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
f4afd0d9
Commit
f4afd0d9
authored
Sep 30, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1418 from abarth/dimissable_test
Port dimissable_test.dart to fn3
parents
f26d8d83
d4b1519c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
257 deletions
+31
-257
dismissable_test.dart
packages/unit/test/widget/dismissable_test.dart
+31
-30
global_key_test.dart
packages/unit/test/widget/global_key_test.dart
+0
-153
mimic_test.dart
packages/unit/test/widget/mimic_test.dart
+0
-74
No files found.
packages/unit/test/widget/dismissable_test.dart
View file @
f4afd0d9
import
'package:quiver/testing/async.dart'
;
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'
;
const
double
itemExtent
=
100.0
;
ScrollDirection
scrollDirection
=
ScrollDirection
.
vertical
;
...
...
@@ -19,7 +19,7 @@ void handleOnDismissed(item) {
dismissedItems
.
add
(
item
);
}
Widget
buildDismissableItem
(
int
item
)
{
Widget
buildDismissableItem
(
BuildContext
context
,
int
item
)
{
return
new
Dismissable
(
key:
new
ValueKey
<
int
>(
item
),
direction:
dismissDirection
,
...
...
@@ -37,7 +37,7 @@ Widget widgetBuilder() {
return
new
Container
(
padding:
const
EdgeDims
.
all
(
10.0
),
child:
new
ScrollableList
<
int
>(
items:
[
0
,
1
,
2
,
3
,
4
],
items:
[
0
,
1
,
2
,
3
,
4
]
.
where
((
int
i
)
=>
!
dismissedItems
.
contains
(
i
)).
toList
()
,
itemBuilder:
buildDismissableItem
,
scrollDirection:
scrollDirection
,
itemExtent:
itemExtent
...
...
@@ -49,8 +49,8 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect
assert
(
gestureDirection
!=
DismissDirection
.
horizontal
);
assert
(
gestureDirection
!=
DismissDirection
.
vertical
);
Widget
itemWidge
t
=
tester
.
findText
(
item
.
toString
());
expect
(
item
Widge
t
,
isNotNull
);
Element
itemElemen
t
=
tester
.
findText
(
item
.
toString
());
expect
(
item
Elemen
t
,
isNotNull
);
Point
downLocation
;
Point
upLocation
;
...
...
@@ -59,23 +59,23 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect
// Note: getTopRight() returns a point that's just beyond
// itemWidget's right edge and outside the Dismissable event
// listener's bounds.
downLocation
=
tester
.
getTopRight
(
item
Widge
t
)
+
const
Offset
(-
0.1
,
0.0
);
upLocation
=
tester
.
getTopLeft
(
item
Widge
t
);
downLocation
=
tester
.
getTopRight
(
item
Elemen
t
)
+
const
Offset
(-
0.1
,
0.0
);
upLocation
=
tester
.
getTopLeft
(
item
Elemen
t
);
break
;
case
DismissDirection
.
right
:
downLocation
=
tester
.
getTopLeft
(
item
Widge
t
);
upLocation
=
tester
.
getTopRight
(
item
Widge
t
);
downLocation
=
tester
.
getTopLeft
(
item
Elemen
t
);
upLocation
=
tester
.
getTopRight
(
item
Elemen
t
);
break
;
case
DismissDirection
.
up
:
// Note: getBottomLeft() returns a point that's just below
// itemWidget's bottom edge and outside the Dismissable event
// listener's bounds.
downLocation
=
tester
.
getBottomLeft
(
item
Widge
t
)
+
const
Offset
(
0.0
,
-
0.1
);
upLocation
=
tester
.
getTopLeft
(
item
Widge
t
);
downLocation
=
tester
.
getBottomLeft
(
item
Elemen
t
)
+
const
Offset
(
0.0
,
-
0.1
);
upLocation
=
tester
.
getTopLeft
(
item
Elemen
t
);
break
;
case
DismissDirection
.
down
:
downLocation
=
tester
.
getTopLeft
(
item
Widge
t
);
upLocation
=
tester
.
getBottomLeft
(
item
Widge
t
);
downLocation
=
tester
.
getTopLeft
(
item
Elemen
t
);
upLocation
=
tester
.
getBottomLeft
(
item
Elemen
t
);
break
;
default
:
fail
(
"unsupported gestureDirection"
);
...
...
@@ -88,10 +88,10 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect
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
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
tester
.
pumpFrame
(
widgetBuilder
()
,
t0
+
2000.0
);
// dismiss
async
.
elapse
(
new
Duration
(
seconds:
1
));
});
}
...
...
@@ -103,7 +103,7 @@ void main() {
dismissDirection
=
DismissDirection
.
horizontal
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
...
...
@@ -121,7 +121,7 @@ void main() {
dismissDirection
=
DismissDirection
.
vertical
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
...
...
@@ -139,7 +139,7 @@ void main() {
dismissDirection
=
DismissDirection
.
left
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
...
...
@@ -157,7 +157,7 @@ void main() {
dismissDirection
=
DismissDirection
.
right
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
left
);
...
...
@@ -175,7 +175,7 @@ void main() {
dismissDirection
=
DismissDirection
.
up
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
down
);
...
...
@@ -193,7 +193,7 @@ void main() {
dismissDirection
=
DismissDirection
.
down
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
...
...
@@ -211,21 +211,22 @@ void main() {
WidgetTester
tester
=
new
WidgetTester
();
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
down
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
Widget
itemWidge
t
=
tester
.
findText
(
'0'
);
tester
.
pumpFrame
(
widgetBuilder
()
);
Element
itemElemen
t
=
tester
.
findText
(
'0'
);
TestPointer
pointer
=
new
TestPointer
(
5
);
Point
location
=
tester
.
getTopLeft
(
item
Widge
t
);
Point
location
=
tester
.
getTopLeft
(
item
Elemen
t
);
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
.
pumpFrame
(
widgetBuilder
()
);
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
2.0
)),
location
);
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
3.0
)),
location
);
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
4.0
)),
location
);
tester
.
pumpFrame
(
widgetBuilder
);
tester
.
pumpFrame
(
widgetBuilder
()
);
});
}
packages/unit/test/widget/global_key_test.dart
deleted
100644 → 0
View file @
f26d8d83
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
void
main
(
)
{
test
(
'Global keys notify add and remove'
,
()
{
GlobalKey
globalKey
=
new
GlobalKey
();
Container
container
;
bool
syncListenerCalled
=
false
;
bool
removeListenerCalled
=
false
;
void
syncListener
(
GlobalKey
key
,
Widget
widget
)
{
syncListenerCalled
=
true
;
expect
(
key
,
equals
(
globalKey
));
expect
(
container
,
isNotNull
);
expect
(
widget
,
equals
(
container
));
}
void
removeListener
(
GlobalKey
key
)
{
removeListenerCalled
=
true
;
expect
(
key
,
equals
(
globalKey
));
}
WidgetTester
tester
=
new
WidgetTester
();
GlobalKey
.
registerSyncListener
(
globalKey
,
syncListener
);
GlobalKey
.
registerRemoveListener
(
globalKey
,
removeListener
);
tester
.
pumpFrame
(()
{
container
=
new
Container
(
key:
globalKey
);
return
container
;
});
expect
(
syncListenerCalled
,
isTrue
);
expect
(
removeListenerCalled
,
isFalse
);
syncListenerCalled
=
false
;
removeListenerCalled
=
false
;
tester
.
pumpFrame
(()
=>
new
Container
());
expect
(
syncListenerCalled
,
isFalse
);
expect
(
removeListenerCalled
,
isTrue
);
syncListenerCalled
=
false
;
removeListenerCalled
=
false
;
GlobalKey
.
unregisterSyncListener
(
globalKey
,
syncListener
);
GlobalKey
.
unregisterRemoveListener
(
globalKey
,
removeListener
);
tester
.
pumpFrame
(()
{
container
=
new
Container
(
key:
globalKey
);
return
container
;
});
expect
(
syncListenerCalled
,
isFalse
);
expect
(
removeListenerCalled
,
isFalse
);
tester
.
pumpFrame
(()
=>
new
Container
());
expect
(
syncListenerCalled
,
isFalse
);
expect
(
removeListenerCalled
,
isFalse
);
});
test
(
'Global key reparenting'
,
()
{
GlobalKey
globalKey
=
new
GlobalKey
();
bool
syncListenerCalled
=
false
;
bool
removeListenerCalled
=
false
;
void
syncListener
(
GlobalKey
key
,
Widget
widget
)
{
syncListenerCalled
=
true
;
}
void
removeListener
(
GlobalKey
key
)
{
removeListenerCalled
=
true
;
}
GlobalKey
.
registerSyncListener
(
globalKey
,
syncListener
);
GlobalKey
.
registerRemoveListener
(
globalKey
,
removeListener
);
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Container
(
child:
new
Container
(
key:
globalKey
)
);
});
expect
(
syncListenerCalled
,
isTrue
);
expect
(
removeListenerCalled
,
isFalse
);
tester
.
pumpFrame
(()
{
return
new
Container
(
key:
globalKey
,
child:
new
Container
()
);
});
expect
(
syncListenerCalled
,
isTrue
);
expect
(
removeListenerCalled
,
isFalse
);
tester
.
pumpFrame
(()
{
return
new
Container
(
child:
new
Container
(
key:
globalKey
)
);
});
expect
(
syncListenerCalled
,
isTrue
);
expect
(
removeListenerCalled
,
isFalse
);
GlobalKey
.
unregisterSyncListener
(
globalKey
,
syncListener
);
GlobalKey
.
unregisterRemoveListener
(
globalKey
,
removeListener
);
});
test
(
'Global key mutate during iteration'
,
()
{
GlobalKey
globalKey
=
new
GlobalKey
();
bool
syncListenerCalled
=
false
;
bool
removeListenerCalled
=
false
;
void
syncListener
(
GlobalKey
key
,
Widget
widget
)
{
GlobalKey
.
unregisterSyncListener
(
globalKey
,
syncListener
);
syncListenerCalled
=
true
;
}
void
removeListener
(
GlobalKey
key
)
{
GlobalKey
.
unregisterRemoveListener
(
globalKey
,
removeListener
);
removeListenerCalled
=
true
;
}
GlobalKey
.
registerSyncListener
(
globalKey
,
syncListener
);
GlobalKey
.
registerRemoveListener
(
globalKey
,
removeListener
);
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Container
(
key:
globalKey
);
});
expect
(
syncListenerCalled
,
isTrue
);
expect
(
removeListenerCalled
,
isFalse
);
syncListenerCalled
=
false
;
removeListenerCalled
=
false
;
tester
.
pumpFrame
(()
{
return
new
Container
();
});
expect
(
syncListenerCalled
,
isFalse
);
expect
(
removeListenerCalled
,
isTrue
);
syncListenerCalled
=
false
;
removeListenerCalled
=
false
;
tester
.
pumpFrame
(()
{
return
new
Container
(
key:
globalKey
);
});
expect
(
syncListenerCalled
,
isFalse
);
expect
(
removeListenerCalled
,
isFalse
);
});
}
packages/unit/test/widget/mimic_test.dart
deleted
100644 → 0
View file @
f26d8d83
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
void
main
(
)
{
test
(
'Mimic can track tree movements'
,
()
{
GlobalKey
globalKey
=
new
GlobalKey
();
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Flex
([
new
Mimicable
(
key:
globalKey
,
child:
new
Container
(
key:
new
Key
(
'inner'
),
height:
10.0
,
width:
10.0
)
)
]);
});
bool
mimicReady
=
false
;
tester
.
pumpFrame
(()
{
return
new
Flex
([
new
Mimicable
(
key:
globalKey
,
child:
new
Container
(
height:
10.0
,
width:
10.0
)
),
new
SizedBox
(
height:
10.0
,
width:
10.0
,
child:
new
Mimic
(
original:
globalKey
,
onMimicReady:
()
{
mimicReady
=
true
;
}
)
)
]);
});
expect
(
mimicReady
,
isTrue
);
tester
.
pumpFrame
(()
{
return
new
Flex
([
new
Container
(
key:
new
Key
(
'outer'
),
height:
10.0
,
width:
10.0
,
child:
new
Mimicable
(
key:
globalKey
,
child:
new
Container
(
key:
new
Key
(
'inner'
),
height:
10.0
,
width:
10.0
)
)
),
new
SizedBox
(
height:
10.0
,
width:
10.0
,
child:
new
Mimic
(
original:
globalKey
)
)
]);
});
});
}
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