Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
f621e01c
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f621e01c
编写于
9月 04, 2015
作者:
H
Hans Muller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Dismissable unit tests
上级
4840f802
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
210 addition
and
73 deletion
+210
-73
examples/widgets/card_collection.dart
examples/widgets/card_collection.dart
+3
-3
sky/unit/test/widget/dismissable_test.dart
sky/unit/test/widget/dismissable_test.dart
+191
-60
sky/unit/test/widget/widget_tester.dart
sky/unit/test/widget/widget_tester.dart
+16
-10
未找到文件。
examples/widgets/card_collection.dart
浏览文件 @
f621e01c
...
...
@@ -64,7 +64,7 @@ class CardCollectionApp extends App {
});
}
String
dismissDirectionText
(
DismissDirection
direction
)
{
String
_
dismissDirectionText
(
DismissDirection
direction
)
{
String
s
=
direction
.
toString
();
return
"dismiss
${s.substring(s.indexOf('.') + 1)}
"
;
}
...
...
@@ -85,7 +85,7 @@ class CardCollectionApp extends App {
icon:
icon
,
onPressed:
()
{
changeDismissDirection
(
direction
);
},
child:
new
Row
([
new
Flexible
(
child:
new
Text
(
dismissDirectionText
(
direction
))),
new
Flexible
(
child:
new
Text
(
_
dismissDirectionText
(
direction
))),
new
Radio
(
value:
direction
,
onChanged:
changeDismissDirection
,
...
...
@@ -116,7 +116,7 @@ class CardCollectionApp extends App {
left:
new
IconButton
(
icon:
"navigation/menu"
,
onPressed:
_handleOpenDrawer
),
center:
new
Text
(
'Swipe Away'
),
right:
[
new
Text
(
dismissDirectionText
(
_dismissDirection
))
new
Text
(
_
dismissDirectionText
(
_dismissDirection
))
]
);
}
...
...
sky/unit/test/widget/dismissable_test.dart
浏览文件 @
f621e01c
...
...
@@ -5,70 +5,201 @@ import 'package:test/test.dart';
import
'../engine/mock_events.dart'
;
import
'widget_tester.dart'
;
const
double
itemExtent
=
100.0
;
ScrollDirection
scrollDirection
=
ScrollDirection
.
vertical
;
DismissDirection
dismissDirection
=
DismissDirection
.
horizontal
;
List
<
int
>
dismissedItems
=
[];
void
handleOnResized
(
item
)
{
expect
(
dismissedItems
.
contains
(
item
),
isFalse
);
}
void
handleOnDismissed
(
item
)
{
expect
(
dismissedItems
.
contains
(
item
),
isFalse
);
dismissedItems
.
add
(
item
);
}
Widget
buildDismissableItem
(
int
item
)
{
return
new
Dismissable
(
key:
new
ValueKey
<
int
>(
item
),
direction:
dismissDirection
,
onDismissed:
()
{
handleOnDismissed
(
item
);
},
onResized:
()
{
handleOnResized
(
item
);
},
child:
new
Container
(
width:
itemExtent
,
height:
itemExtent
,
child:
new
Text
(
item
.
toString
())
)
);
}
Widget
widgetBuilder
(
)
{
return
new
Container
(
padding:
const
EdgeDims
.
all
(
10.0
),
child:
new
ScrollableList
<
int
>(
items:
[
0
,
1
,
2
,
3
,
4
],
itemBuilder:
buildDismissableItem
,
scrollDirection:
scrollDirection
,
itemExtent:
itemExtent
)
);
}
void
dismissItem
(
WidgetTester
tester
,
int
item
,
{
DismissDirection
gestureDirection
})
{
assert
(
gestureDirection
!=
DismissDirection
.
horizontal
);
assert
(
gestureDirection
!=
DismissDirection
.
vertical
);
Widget
itemWidget
=
tester
.
findText
(
item
.
toString
());
expect
(
itemWidget
,
isNotNull
);
Point
downLocation
;
Point
upLocation
;
switch
(
gestureDirection
)
{
case
DismissDirection
.
left
:
// Note: getTopRight() returns a point that's just beyond
// itemWidget's right edge and outside the Dismissable event
// listener's bounds.
downLocation
=
tester
.
getTopRight
(
itemWidget
)
+
const
Offset
(-
0.1
,
0.0
);
upLocation
=
tester
.
getTopLeft
(
itemWidget
);
break
;
case
DismissDirection
.
right
:
downLocation
=
tester
.
getTopLeft
(
itemWidget
);
upLocation
=
tester
.
getTopRight
(
itemWidget
);
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
(
itemWidget
)
+
const
Offset
(
0.0
,
-
0.1
);
upLocation
=
tester
.
getTopLeft
(
itemWidget
);
break
;
case
DismissDirection
.
down
:
downLocation
=
tester
.
getTopLeft
(
itemWidget
);
upLocation
=
tester
.
getBottomLeft
(
itemWidget
);
break
;
}
TestPointer
pointer
=
new
TestPointer
(
5
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
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
));
});
}
void
main
(
)
{
test
(
'Horizontal drag triggers dismiss'
,
()
{
test
(
'Horizontal drag triggers dismiss scrollDirection=vertical'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
scrollDirection
=
ScrollDirection
.
vertical
;
dismissDirection
=
DismissDirection
.
horizontal
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
left
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
});
test
(
'Vertical drag triggers dismiss scrollDirection=horizontal'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
vertical
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
down
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
});
test
(
'drag-left with DismissDirection.left triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
scrollDirection
=
ScrollDirection
.
vertical
;
dismissDirection
=
DismissDirection
.
left
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
left
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
test
(
'drag-right with DismissDirection.right triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
scrollDirection
=
ScrollDirection
.
vertical
;
dismissDirection
=
DismissDirection
.
right
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
left
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
right
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
test
(
'drag-up with DismissDirection.up triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
up
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
down
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
test
(
'drag-down with DismissDirection.down triggers dismiss'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
TestPointer
pointer
=
new
TestPointer
(
5
);
const
double
itemHeight
=
50.0
;
List
<
int
>
dismissedItems
=
[];
void
handleOnResized
(
item
)
{
expect
(
dismissedItems
.
contains
(
item
),
isFalse
);
}
void
handleOnDismissed
(
item
)
{
expect
(
dismissedItems
.
contains
(
item
),
isFalse
);
dismissedItems
.
add
(
item
);
}
Widget
buildDismissableItem
(
int
item
)
{
return
new
Dismissable
(
key:
new
ValueKey
<
int
>(
item
),
onDismissed:
()
{
handleOnDismissed
(
item
);
},
onResized:
()
{
handleOnResized
(
item
);
},
child:
new
Container
(
height:
itemHeight
,
child:
new
Text
(
item
.
toString
())
)
);
}
Widget
builder
()
{
return
new
Container
(
padding:
const
EdgeDims
.
all
(
10.0
),
child:
new
ScrollableList
<
int
>(
items:
[
0
,
1
,
2
,
3
,
4
,
5
],
itemBuilder:
buildDismissableItem
,
scrollDirection:
ScrollDirection
.
vertical
,
itemExtent:
itemHeight
)
);
}
tester
.
pumpFrame
(
builder
);
Widget
item3
=
tester
.
findText
(
"3"
);
expect
(
item3
,
isNotNull
);
scrollDirection
=
ScrollDirection
.
horizontal
;
dismissDirection
=
DismissDirection
.
down
;
dismissedItems
=
[];
tester
.
pumpFrame
(
widgetBuilder
);
expect
(
dismissedItems
,
isEmpty
);
// Gesture: press-drag-release from the Dismissable's top-left corner
// to its top-right corner. Triggers the resize animation which concludes
// by calling onDismissed().
Point
downLocation
=
tester
.
getTopLeft
(
item3
);
Point
upLocation
=
tester
.
getTopRight
(
item3
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
upLocation
);
tester
.
dispatchEvent
(
pointer
.
up
(),
upLocation
);
new
FakeAsync
().
run
((
async
)
{
tester
.
pumpFrame
(
builder
);
// start the resize animation
tester
.
pumpFrame
(
builder
,
1000.0
);
// finish the resize animation
async
.
elapse
(
new
Duration
(
seconds:
1
));
tester
.
pumpFrame
(
builder
,
2000.0
);
// dismiss
async
.
elapse
(
new
Duration
(
seconds:
1
));
expect
(
dismissedItems
,
equals
([
3
]));
expect
(
tester
.
findText
(
"3"
),
isNull
);
});
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
down
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
dismissedItems
,
equals
([
0
]));
});
}
sky/unit/test/widget/widget_tester.dart
浏览文件 @
f621e01c
...
...
@@ -76,25 +76,31 @@ class WidgetTester {
});
}
Point
getCenter
(
Widget
widge
t
)
{
Point
_getWidgetPoint
(
Widget
widget
,
Function
sizeToPoin
t
)
{
assert
(
widget
!=
null
);
RenderBox
box
=
widget
.
renderObject
as
RenderBox
;
assert
(
box
!=
null
);
return
box
.
localToGlobal
(
box
.
size
.
center
(
Point
.
origin
));
return
box
.
localToGlobal
(
sizeToPoint
(
box
.
size
));
}
Point
getCenter
(
Widget
widget
)
{
return
_getWidgetPoint
(
widget
,
(
Size
size
)
=>
size
.
center
(
Point
.
origin
));
}
Point
getTopLeft
(
Widget
widget
)
{
assert
(
widget
!=
null
);
RenderBox
box
=
widget
.
renderObject
as
RenderBox
;
assert
(
box
!=
null
);
return
box
.
localToGlobal
(
Point
.
origin
);
return
_getWidgetPoint
(
widget
,
(
_
)
=>
Point
.
origin
);
}
Point
getTopRight
(
Widget
widget
)
{
assert
(
widget
!=
null
);
RenderBox
box
=
widget
.
renderObject
as
RenderBox
;
assert
(
box
!=
null
);
return
box
.
localToGlobal
(
box
.
size
.
topRight
(
Point
.
origin
));
return
_getWidgetPoint
(
widget
,
(
Size
size
)
=>
size
.
topRight
(
Point
.
origin
));
}
Point
getBottomLeft
(
Widget
widget
)
{
return
_getWidgetPoint
(
widget
,
(
Size
size
)
=>
size
.
bottomLeft
(
Point
.
origin
));
}
Point
getBottomRight
(
Widget
widget
)
{
return
_getWidgetPoint
(
widget
,
(
Size
size
)
=>
size
.
bottomRight
(
Point
.
origin
));
}
HitTestResult
_hitTest
(
Point
location
)
=>
SkyBinding
.
instance
.
hitTest
(
location
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录