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
b4c39703
Commit
b4c39703
authored
Nov 11, 2015
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a unit test for persistent bottom sheets
parent
8c98ea37
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
10 deletions
+76
-10
bottom_sheet.dart
packages/flutter/lib/src/material/bottom_sheet.dart
+3
-1
mock_events.dart
packages/unit/test/engine/mock_events.dart
+12
-8
bottom_sheet_test.dart
packages/unit/test/widget/bottom_sheet_test.dart
+40
-1
widget_tester.dart
packages/unit/test/widget/widget_tester.dart
+21
-0
No files found.
packages/flutter/lib/src/material/bottom_sheet.dart
View file @
b4c39703
...
...
@@ -216,5 +216,7 @@ Future showBottomSheet({ BuildContext context, GlobalKey<PlaceholderState> place
_BottomSheetRoute
route
=
new
_BottomSheetRoute
(
child:
child
,
completer:
completer
);
placeholderKey
.
currentState
.
child
=
new
_PersistentBottomSheet
(
route:
route
);
Navigator
.
of
(
context
).
pushEphemeral
(
route
);
return
completer
.
future
;
return
completer
.
future
.
then
((
_
)
{
placeholderKey
.
currentState
.
child
=
null
;
});
}
packages/unit/test/engine/mock_events.dart
View file @
b4c39703
...
...
@@ -11,7 +11,7 @@ class TestPointer {
bool
isDown
=
false
;
ui
.
Point
location
;
PointerInputEvent
down
([
ui
.
Point
newLocation
=
ui
.
Point
.
origin
])
{
PointerInputEvent
down
([
ui
.
Point
newLocation
=
ui
.
Point
.
origin
,
double
timeStamp
=
0.0
])
{
assert
(!
isDown
);
isDown
=
true
;
location
=
newLocation
;
...
...
@@ -19,11 +19,12 @@ class TestPointer {
type:
'pointerdown'
,
pointer:
pointer
,
x:
location
.
x
,
y:
location
.
y
y:
location
.
y
,
timeStamp:
timeStamp
);
}
PointerInputEvent
move
([
ui
.
Point
newLocation
=
ui
.
Point
.
origin
])
{
PointerInputEvent
move
([
ui
.
Point
newLocation
=
ui
.
Point
.
origin
,
double
timeStamp
=
0.0
])
{
assert
(
isDown
);
ui
.
Offset
delta
=
newLocation
-
location
;
location
=
newLocation
;
...
...
@@ -33,29 +34,32 @@ class TestPointer {
x:
newLocation
.
x
,
y:
newLocation
.
y
,
dx:
delta
.
dx
,
dy:
delta
.
dy
dy:
delta
.
dy
,
timeStamp:
timeStamp
);
}
PointerInputEvent
up
()
{
PointerInputEvent
up
(
[
double
timeStamp
=
0.0
]
)
{
assert
(
isDown
);
isDown
=
false
;
return
new
PointerInputEvent
(
type:
'pointerup'
,
pointer:
pointer
,
x:
location
.
x
,
y:
location
.
y
y:
location
.
y
,
timeStamp:
timeStamp
);
}
PointerInputEvent
cancel
()
{
PointerInputEvent
cancel
(
[
double
timeStamp
=
0.0
]
)
{
assert
(
isDown
);
isDown
=
false
;
return
new
PointerInputEvent
(
type:
'pointercancel'
,
pointer:
pointer
,
x:
location
.
x
,
y:
location
.
y
y:
location
.
y
,
timeStamp:
timeStamp
);
}
...
...
packages/unit/test/widget/bottom_sheet_test.dart
View file @
b4c39703
...
...
@@ -5,7 +5,7 @@ import 'package:test/test.dart';
import
'widget_tester.dart'
;
void
main
(
)
{
test
(
'Verify that a tap dismisses
the
BottomSheet'
,
()
{
test
(
'Verify that a tap dismisses
a modal
BottomSheet'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
BuildContext
context
;
tester
.
pumpWidget
(
new
MaterialApp
(
...
...
@@ -46,4 +46,43 @@ void main() {
});
});
test
(
'Verify that a downwards fling dismisses a persistent BottomSheet'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
GlobalKey
<
PlaceholderState
>
_bottomSheetPlaceholderKey
=
new
GlobalKey
<
PlaceholderState
>();
BuildContext
context
;
tester
.
pumpWidget
(
new
MaterialApp
(
routes:
<
String
,
RouteBuilder
>{
'/'
:
(
RouteArguments
args
)
{
context
=
args
.
context
;
return
new
Scaffold
(
bottomSheet:
new
Placeholder
(
key:
_bottomSheetPlaceholderKey
),
body:
new
Center
(
child:
new
Text
(
'body'
))
);
}
}
));
tester
.
pump
();
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
showBottomSheet
(
context:
context
,
child:
new
Container
(
child:
new
Text
(
'BottomSheet'
),
margin:
new
EdgeDims
.
all
(
40.0
)),
placeholderKey:
_bottomSheetPlaceholderKey
);
expect
(
_bottomSheetPlaceholderKey
.
currentState
.
child
,
isNotNull
);
tester
.
pump
();
// bottom sheet show animation starts
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'BottomSheet'
),
isNotNull
);
tester
.
fling
(
tester
.
findText
(
'BottomSheet'
),
const
Offset
(
0.0
,
20.0
),
1000.0
);
tester
.
pump
();
// bottom sheet dismiss animation starts
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
tester
.
pump
(
new
Duration
(
seconds:
2
));
// rebuild frame without the bottom sheet
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
expect
(
_bottomSheetPlaceholderKey
.
currentState
.
child
,
isNull
);
});
});
}
packages/unit/test/widget/widget_tester.dart
View file @
b4c39703
...
...
@@ -144,6 +144,27 @@ class WidgetTester {
_dispatchEvent
(
p
.
up
(),
result
);
}
void
fling
(
Element
element
,
Offset
offset
,
velocity
,
{
int
pointer:
1
})
{
flingFrom
(
getCenter
(
element
),
offset
,
velocity
,
pointer:
pointer
);
}
void
flingFrom
(
Point
startLocation
,
Offset
offset
,
double
velocity
,
{
int
pointer:
1
})
{
assert
(
offset
.
distance
>
0.0
);
assert
(
velocity
!=
0.0
);
// velocity is pixels/second
final
TestPointer
p
=
new
TestPointer
(
pointer
);
final
HitTestResult
result
=
_hitTest
(
startLocation
);
final
kMoveCount
=
50
;
// Needs to be >= kHistorySize, see _LeastSquaresVelocityTrackerStrategy
final
double
timeStampDelta
=
1000.0
*
offset
.
distance
/
(
kMoveCount
*
velocity
);
double
timeStamp
=
0.0
;
_dispatchEvent
(
p
.
down
(
startLocation
,
timeStamp
),
result
);
for
(
int
i
=
0
;
i
<
kMoveCount
;
i
++)
{
final
Point
location
=
startLocation
+
Offset
.
lerp
(
Offset
.
zero
,
offset
,
i
/
kMoveCount
);
_dispatchEvent
(
p
.
move
(
location
,
timeStamp
),
result
);
timeStamp
+=
timeStampDelta
;
}
_dispatchEvent
(
p
.
up
(
timeStamp
),
result
);
}
void
scroll
(
Element
element
,
Offset
offset
,
{
int
pointer:
1
})
{
scrollAt
(
getCenter
(
element
),
offset
,
pointer:
pointer
);
}
...
...
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