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
b5562c1b
Unverified
Commit
b5562c1b
authored
Oct 06, 2020
by
Kate Lovett
Committed by
GitHub
Oct 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NNBD] More test migration for Cupertino & Painting (#67323)
parent
ef6c720d
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
147 additions
and
269 deletions
+147
-269
refresh_test.dart
packages/flutter/test/cupertino/refresh_test.dart
+9
-11
route_test.dart
packages/flutter/test/cupertino/route_test.dart
+48
-66
scaffold_test.dart
packages/flutter/test/cupertino/scaffold_test.dart
+13
-15
scrollbar_paint_test.dart
packages/flutter/test/cupertino/scrollbar_paint_test.dart
+0
-2
scrollbar_test.dart
packages/flutter/test/cupertino/scrollbar_test.dart
+1
-3
segmented_control_test.dart
packages/flutter/test/cupertino/segmented_control_test.dart
+17
-53
slider_test.dart
packages/flutter/test/cupertino/slider_test.dart
+10
-12
sliding_segmented_control_test.dart
...lutter/test/cupertino/sliding_segmented_control_test.dart
+19
-69
switch_test.dart
packages/flutter/test/cupertino/switch_test.dart
+0
-2
tab_scaffold_test.dart
packages/flutter/test/cupertino/tab_scaffold_test.dart
+20
-24
tab_test.dart
packages/flutter/test/cupertino/tab_test.dart
+10
-12
No files found.
packages/flutter/test/cupertino/refresh_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'package:flutter/cupertino.dart'
;
...
...
@@ -13,7 +11,7 @@ import 'package:flutter/services.dart';
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
FakeBuilder
mockHelper
;
late
FakeBuilder
mockHelper
;
setUp
(()
{
mockHelper
=
FakeBuilder
();
...
...
@@ -1407,10 +1405,10 @@ class RefreshTaskInvocation extends MockHelperInvocation {
@immutable
class
BuilderInvocation
extends
MockHelperInvocation
{
const
BuilderInvocation
({
@
required
this
.
refreshState
,
@
required
this
.
pulledExtent
,
@
required
this
.
refreshIndicatorExtent
,
@
required
this
.
refreshTriggerPullDistance
,
required
this
.
refreshState
,
required
this
.
pulledExtent
,
required
this
.
refreshIndicatorExtent
,
required
this
.
refreshTriggerPullDistance
,
});
final
RefreshIndicatorMode
refreshState
;
...
...
@@ -1423,10 +1421,10 @@ class BuilderInvocation extends MockHelperInvocation {
}
Matcher
matchesBuilder
(
{
@
required
RefreshIndicatorMode
refreshState
,
@
required
dynamic
pulledExtent
,
@
required
dynamic
refreshTriggerPullDistance
,
@
required
dynamic
refreshIndicatorExtent
,
required
RefreshIndicatorMode
refreshState
,
required
dynamic
pulledExtent
,
required
dynamic
refreshTriggerPullDistance
,
required
dynamic
refreshIndicatorExtent
,
})
{
return
isA
<
BuilderInvocation
>()
.
having
((
BuilderInvocation
invocation
)
=>
invocation
.
refreshState
,
'refreshState'
,
refreshState
)
...
...
packages/flutter/test/cupertino/route_test.dart
View file @
b5562c1b
This diff is collapsed.
Click to expand it.
packages/flutter/test/cupertino/scaffold_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:typed_data'
;
import
'package:flutter/cupertino.dart'
;
...
...
@@ -31,7 +29,7 @@ void main() {
});
testWidgets
(
'Opaque bar pushes contents down'
,
(
WidgetTester
tester
)
async
{
BuildContext
childContext
;
late
BuildContext
childContext
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MediaQuery
(
...
...
@@ -51,7 +49,7 @@ void main() {
),
));
expect
(
MediaQuery
.
of
(
childContext
).
padding
.
top
,
0
);
expect
(
MediaQuery
.
of
(
childContext
)
!
.
padding
.
top
,
0
);
// The top of the [Container] is 44 px from the top of the screen because
// it's pushed down by the opaque navigation bar whose height is 44 px,
// and the 20 px [MediaQuery] top padding is fully absorbed by the navigation bar.
...
...
@@ -69,7 +67,7 @@ void main() {
darkColor:
Color
(
0xFF000000
),
);
BuildContext
childContext
;
late
BuildContext
childContext
;
Widget
scaffoldWithBrightness
(
Brightness
brightness
)
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
...
...
@@ -96,12 +94,12 @@ void main() {
}
await
tester
.
pumpWidget
(
scaffoldWithBrightness
(
Brightness
.
light
));
expect
(
MediaQuery
.
of
(
childContext
).
padding
.
top
,
0
);
expect
(
MediaQuery
.
of
(
childContext
)
!
.
padding
.
top
,
0
);
expect
(
find
.
byType
(
CupertinoPageScaffold
),
paints
..
rect
(
color:
backgroundColor
.
color
));
await
tester
.
pumpWidget
(
scaffoldWithBrightness
(
Brightness
.
dark
));
expect
(
MediaQuery
.
of
(
childContext
).
padding
.
top
,
greaterThan
(
0
));
expect
(
MediaQuery
.
of
(
childContext
)
!
.
padding
.
top
,
greaterThan
(
0
));
expect
(
find
.
byType
(
CupertinoPageScaffold
),
paints
..
rect
(
color:
backgroundColor
.
darkColor
));
});
...
...
@@ -122,7 +120,7 @@ void main() {
expect
(
tester
.
getSize
(
find
.
byType
(
Container
)).
height
,
600.0
-
44.0
-
100.0
);
BuildContext
childContext
;
late
BuildContext
childContext
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
MediaQuery
(
...
...
@@ -144,7 +142,7 @@ void main() {
expect
(
tester
.
getSize
(
find
.
byType
(
Container
)).
height
,
600.0
-
100.0
);
// The shouldn't see a media query view inset because it was consumed by
// the scaffold.
expect
(
MediaQuery
.
of
(
childContext
).
viewInsets
.
bottom
,
0
);
expect
(
MediaQuery
.
of
(
childContext
)
!
.
viewInsets
.
bottom
,
0
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
...
...
@@ -324,7 +322,7 @@ void main() {
child:
CupertinoButton
(
child:
const
Text
(
'Next'
),
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
Navigator
.
of
(
context
)
!
.
push
(
CupertinoPageRoute
<
void
>(
builder:
(
BuildContext
context
)
{
return
CupertinoPageScaffold
(
...
...
@@ -335,7 +333,7 @@ void main() {
child:
CupertinoButton
(
child:
const
Text
(
'Back'
),
onPressed:
()
{
Navigator
.
of
(
context
).
pop
();
Navigator
.
of
(
context
)
!
.
pop
();
},
),
),
...
...
@@ -438,11 +436,11 @@ void main() {
testWidgets
(
'Lists in CupertinoPageScaffold scroll to the top when status bar tapped'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
builder:
(
BuildContext
context
,
Widget
child
)
{
builder:
(
BuildContext
context
,
Widget
?
child
)
{
// Acts as a 20px status bar at the root of the app.
return
MediaQuery
(
data:
MediaQuery
.
of
(
context
).
copyWith
(
padding:
const
EdgeInsets
.
only
(
top:
20
)),
child:
child
,
data:
MediaQuery
.
of
(
context
)
!
.
copyWith
(
padding:
const
EdgeInsets
.
only
(
top:
20
)),
child:
child
!
,
);
},
home:
CupertinoPageScaffold
(
...
...
@@ -539,7 +537,7 @@ void main() {
CupertinoApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
return
MediaQuery
(
data:
MediaQuery
.
of
(
context
).
copyWith
(
textScaleFactor:
99
),
data:
MediaQuery
.
of
(
context
)
!
.
copyWith
(
textScaleFactor:
99
),
child:
const
CupertinoPageScaffold
(
navigationBar:
CupertinoNavigationBar
(
middle:
Text
(
'middle'
),
...
...
packages/flutter/test/cupertino/scrollbar_paint_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
packages/flutter/test/cupertino/scrollbar_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/services.dart'
;
...
...
@@ -62,7 +60,7 @@ void main() {
testWidgets
(
'Scrollbar dark mode'
,
(
WidgetTester
tester
)
async
{
Brightness
brightness
=
Brightness
.
light
;
StateSetter
setState
;
late
StateSetter
setState
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
...
...
packages/flutter/test/cupertino/segmented_control_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/widgets.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -41,7 +39,7 @@ StatefulBuilder setupSimpleSegmentedControl() {
);
}
Widget
boilerplate
(
{
Widget
child
})
{
Widget
boilerplate
(
{
required
Widget
child
})
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
child
),
...
...
@@ -132,18 +130,18 @@ void main() {
child:
Text
(
'Child 2'
),
)
;
Future
<
void
>
verifyPadding
({
EdgeInsets
padding
})
async
{
Future
<
void
>
verifyPadding
({
EdgeInsets
?
padding
})
async
{
final
EdgeInsets
effectivePadding
=
padding
??
const
EdgeInsets
.
symmetric
(
horizontal:
16
);
final
Rect
segmentedControlRect
=
tester
.
getRect
(
find
.
byKey
(
key
));
expect
(
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
])),
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
]
!
)),
segmentedControlRect
.
topLeft
.
translate
(
effectivePadding
.
topLeft
.
dx
,
effectivePadding
.
topLeft
.
dy
,
),
);
expect
(
tester
.
getBottomLeft
(
find
.
byWidget
(
children
[
0
])),
tester
.
getBottomLeft
(
find
.
byWidget
(
children
[
0
]
!
)),
segmentedControlRect
.
bottomLeft
.
translate
(
effectivePadding
.
bottomLeft
.
dx
,
effectivePadding
.
bottomLeft
.
dy
,
...
...
@@ -151,14 +149,14 @@ void main() {
);
expect
(
tester
.
getTopRight
(
find
.
byWidget
(
children
[
1
])),
tester
.
getTopRight
(
find
.
byWidget
(
children
[
1
]
!
)),
segmentedControlRect
.
topRight
.
translate
(
effectivePadding
.
topRight
.
dx
,
effectivePadding
.
topRight
.
dy
,
),
);
expect
(
tester
.
getBottomRight
(
find
.
byWidget
(
children
[
1
])),
tester
.
getBottomRight
(
find
.
byWidget
(
children
[
1
]
!
)),
segmentedControlRect
.
bottomRight
.
translate
(
effectivePadding
.
bottomRight
.
dx
,
effectivePadding
.
bottomRight
.
dy
,
...
...
@@ -228,40 +226,6 @@ void main() {
}
});
testWidgets
(
'Children and onValueChanged arguments can not be null'
,
(
WidgetTester
tester
)
async
{
try
{
await
tester
.
pumpWidget
(
boilerplate
(
child:
CupertinoSegmentedControl
<
int
>(
children:
null
,
onValueChanged:
(
int
newValue
)
{
},
),
),
);
fail
(
'Should not be possible to create segmented control with null children'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'children'
));
}
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
try
{
await
tester
.
pumpWidget
(
boilerplate
(
child:
CupertinoSegmentedControl
<
int
>(
children:
children
,
onValueChanged:
null
,
),
),
);
fail
(
'Should not be possible to create segmented control with null onValueChanged'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'onValueChanged'
));
}
});
testWidgets
(
'Widgets have correct default text/icon styles, change correctly on selection'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
...
...
@@ -292,7 +256,7 @@ void main() {
DefaultTextStyle
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
IconTheme
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
textStyle
.
style
.
color
,
isSameColorAs
(
CupertinoColors
.
white
));
expect
(
textStyle
.
style
!
.
color
,
isSameColorAs
(
CupertinoColors
.
white
));
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
activeBlue
);
await
tester
.
tap
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
...
...
@@ -301,7 +265,7 @@ void main() {
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
textStyle
.
style
.
color
,
CupertinoColors
.
activeBlue
);
expect
(
textStyle
.
style
!
.
color
,
CupertinoColors
.
activeBlue
);
expect
(
iconTheme
.
data
.
color
,
isSameColorAs
(
CupertinoColors
.
white
));
});
...
...
@@ -336,7 +300,7 @@ void main() {
DefaultTextStyle
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
).
first
);
IconThemeData
iconTheme
=
IconTheme
.
of
(
tester
.
element
(
find
.
byIcon
(
const
IconData
(
1
))));
expect
(
textStyle
.
style
.
color
,
isSameColorAs
(
CupertinoColors
.
black
));
expect
(
textStyle
.
style
!
.
color
,
isSameColorAs
(
CupertinoColors
.
black
));
expect
(
iconTheme
.
color
,
isSameColorAs
(
CupertinoColors
.
systemBlue
.
darkColor
));
await
tester
.
tap
(
find
.
byIcon
(
const
IconData
(
1
)));
...
...
@@ -346,7 +310,7 @@ void main() {
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
).
first
);
iconTheme
=
IconTheme
.
of
(
tester
.
element
(
find
.
byIcon
(
const
IconData
(
1
))));
expect
(
textStyle
.
style
.
color
,
isSameColorAs
(
CupertinoColors
.
systemBlue
.
darkColor
));
expect
(
textStyle
.
style
!
.
color
,
isSameColorAs
(
CupertinoColors
.
systemBlue
.
darkColor
));
expect
(
iconTheme
.
color
,
isSameColorAs
(
CupertinoColors
.
black
));
},
);
...
...
@@ -384,7 +348,7 @@ void main() {
IconTheme
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
getRenderSegmentedControl
(
tester
).
borderColor
,
CupertinoColors
.
black
);
expect
(
textStyle
.
style
.
color
,
CupertinoColors
.
lightBackgroundGray
);
expect
(
textStyle
.
style
!
.
color
,
CupertinoColors
.
lightBackgroundGray
);
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
activeGreen
.
color
);
expect
(
getBackgroundColor
(
tester
,
0
),
CupertinoColors
.
activeGreen
.
color
);
expect
(
getBackgroundColor
(
tester
,
1
),
CupertinoColors
.
lightBackgroundGray
);
...
...
@@ -395,7 +359,7 @@ void main() {
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
textStyle
.
style
.
color
,
CupertinoColors
.
activeGreen
.
color
);
expect
(
textStyle
.
style
!
.
color
,
CupertinoColors
.
activeGreen
.
color
);
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
lightBackgroundGray
);
expect
(
getBackgroundColor
(
tester
,
0
),
CupertinoColors
.
lightBackgroundGray
);
expect
(
getBackgroundColor
(
tester
,
1
),
CupertinoColors
.
activeGreen
.
color
);
...
...
@@ -562,7 +526,7 @@ void main() {
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
int
sharedValue
;
int
?
sharedValue
;
await
tester
.
pumpWidget
(
StatefulBuilder
(
...
...
@@ -930,7 +894,7 @@ void main() {
testWidgets
(
'Hit-tests report accurate local position in segments'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
TapDownDetails
tapDownDetails
;
late
TapDownDetails
tapDownDetails
;
children
[
0
]
=
GestureDetector
(
behavior:
HitTestBehavior
.
opaque
,
onTapDown:
(
TapDownDetails
details
)
{
tapDownDetails
=
details
;
},
...
...
@@ -961,7 +925,7 @@ void main() {
expect
(
sharedValue
,
1
);
final
Offset
segment0GlobalOffset
=
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
]));
final
Offset
segment0GlobalOffset
=
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
]
!
));
await
tester
.
tapAt
(
segment0GlobalOffset
+
const
Offset
(
7
,
11
));
expect
(
tapDownDetails
.
localPosition
,
const
Offset
(
7
,
11
));
...
...
@@ -998,7 +962,7 @@ void main() {
expect
(
sharedValue
,
0
);
final
Offset
centerOfTwo
=
tester
.
getCenter
(
find
.
byWidget
(
children
[
1
]));
final
Offset
centerOfTwo
=
tester
.
getCenter
(
find
.
byWidget
(
children
[
1
]
!
));
// Tap within the bounds of children[1], but not at the center.
// children[1] is a SizedBox thus not hittable by itself.
await
tester
.
tapAt
(
centerOfTwo
+
const
Offset
(
10
,
0
));
...
...
@@ -1418,7 +1382,7 @@ void main() {
children
[
0
]
=
const
Text
(
'A'
);
children
[
1
]
=
const
Text
(
'B'
);
children
[
2
]
=
const
Text
(
'C'
);
int
sharedValue
=
0
;
int
?
sharedValue
=
0
;
await
tester
.
pumpWidget
(
StatefulBuilder
(
...
...
packages/flutter/test/cupertino/slider_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
...
...
@@ -66,7 +64,7 @@ void main() {
await
tester
.
pump
();
// No animation should start.
// Check the transientCallbackCount before tearing down the widget to ensure
// that no animation is running.
expect
(
SchedulerBinding
.
instance
.
transientCallbackCount
,
equals
(
0
));
expect
(
SchedulerBinding
.
instance
!
.
transientCallbackCount
,
equals
(
0
));
});
testWidgets
(
'Slider does not move when tapped (RTL)'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -102,7 +100,7 @@ void main() {
await
tester
.
pump
();
// No animation should start.
// Check the transientCallbackCount before tearing down the widget to ensure
// that no animation is running.
expect
(
SchedulerBinding
.
instance
.
transientCallbackCount
,
equals
(
0
));
expect
(
SchedulerBinding
.
instance
!
.
transientCallbackCount
,
equals
(
0
));
});
testWidgets
(
'Slider calls onChangeStart once when interaction begins'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -143,7 +141,7 @@ void main() {
await
tester
.
pump
();
// No animation should start.
// Check the transientCallbackCount before tearing down the widget to ensure
// that no animation is running.
expect
(
SchedulerBinding
.
instance
.
transientCallbackCount
,
equals
(
0
));
expect
(
SchedulerBinding
.
instance
!
.
transientCallbackCount
,
equals
(
0
));
});
testWidgets
(
'Slider calls onChangeEnd once after interaction has ended'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -184,14 +182,14 @@ void main() {
await
tester
.
pump
();
// No animation should start.
// Check the transientCallbackCount before tearing down the widget to ensure
// that no animation is running.
expect
(
SchedulerBinding
.
instance
.
transientCallbackCount
,
equals
(
0
));
expect
(
SchedulerBinding
.
instance
!
.
transientCallbackCount
,
equals
(
0
));
});
testWidgets
(
'Slider moves when dragged (LTR)'
,
(
WidgetTester
tester
)
async
{
final
Key
sliderKey
=
UniqueKey
();
double
value
=
0.0
;
double
startValue
;
double
endValue
;
late
double
startValue
;
late
double
endValue
;
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -238,14 +236,14 @@ void main() {
await
tester
.
pump
();
// No animation should start.
// Check the transientCallbackCount before tearing down the widget to ensure
// that no animation is running.
expect
(
SchedulerBinding
.
instance
.
transientCallbackCount
,
equals
(
0
));
expect
(
SchedulerBinding
.
instance
!
.
transientCallbackCount
,
equals
(
0
));
});
testWidgets
(
'Slider moves when dragged (RTL)'
,
(
WidgetTester
tester
)
async
{
final
Key
sliderKey
=
UniqueKey
();
double
value
=
0.0
;
double
startValue
;
double
endValue
;
late
double
startValue
;
late
double
endValue
;
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -292,7 +290,7 @@ void main() {
await
tester
.
pump
();
// No animation should start.
// Check the transientCallbackCount before tearing down the widget to ensure
// that no animation is running.
expect
(
SchedulerBinding
.
instance
.
transientCallbackCount
,
equals
(
0
));
expect
(
SchedulerBinding
.
instance
!
.
transientCallbackCount
,
equals
(
0
));
});
testWidgets
(
'Slider Semantics'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/cupertino/sliding_segmented_control_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:collection'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -28,7 +26,7 @@ Rect currentUnscaledThumbRect(WidgetTester tester, { bool useGlobalCoordinate =
return
local
;
final
RenderBox
segmentedControl
=
renderSegmentedControl
as
RenderBox
;
return
local
?
.
shift
(
segmentedControl
.
localToGlobal
(
Offset
.
zero
));
return
local
.
shift
(
segmentedControl
.
localToGlobal
(
Offset
.
zero
));
}
double
currentThumbScale
(
WidgetTester
tester
)
=>
getRenderSegmentedControl
(
tester
).
currentThumbScale
as
double
;
...
...
@@ -50,13 +48,13 @@ Widget setupSimpleSegmentedControl() {
);
}
StateSetter
setState
;
int
groupValue
=
0
;
void
defaultCallback
(
int
newValue
)
{
setState
(()
{
groupValue
=
newValue
;
});
StateSetter
?
setState
;
int
?
groupValue
=
0
;
void
defaultCallback
(
int
?
newValue
)
{
setState
!
(()
{
groupValue
=
newValue
;
});
}
Widget
boilerplate
(
{
WidgetBuilder
builder
})
{
Widget
boilerplate
(
{
required
WidgetBuilder
builder
})
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
...
...
@@ -75,54 +73,6 @@ void main() {
groupValue
=
0
;
});
testWidgets
(
'Children and onValueChanged and padding arguments can not be null'
,
(
WidgetTester
tester
)
async
{
groupValue
=
null
;
try
{
await
tester
.
pumpWidget
(
CupertinoSlidingSegmentedControl
<
int
>(
children:
null
,
groupValue:
groupValue
,
onValueChanged:
defaultCallback
,
),
);
fail
(
'Should not be possible to create segmented control with null children'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'children'
));
}
const
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{
0
:
Text
(
'Child 1'
),
1
:
Text
(
'Child 2'
),
};
try
{
await
tester
.
pumpWidget
(
CupertinoSlidingSegmentedControl
<
int
>(
children:
children
,
groupValue:
groupValue
,
onValueChanged:
null
,
),
);
fail
(
'Should not be possible to create segmented control without an onValueChanged'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'onValueChanged'
));
}
try
{
await
tester
.
pumpWidget
(
CupertinoSlidingSegmentedControl
<
int
>(
children:
children
,
groupValue:
groupValue
,
onValueChanged:
defaultCallback
,
padding:
null
,
),
);
fail
(
'Should not be possible to create segmented control with null padding'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'padding'
));
}
});
testWidgets
(
'Need at least 2 children'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
groupValue
=
null
;
...
...
@@ -178,25 +128,25 @@ void main() {
1
:
Text
(
'Child 2'
),
};
Future
<
void
>
verifyPadding
({
EdgeInsets
padding
})
async
{
Future
<
void
>
verifyPadding
({
EdgeInsets
?
padding
})
async
{
final
EdgeInsets
effectivePadding
=
padding
??
const
EdgeInsets
.
symmetric
(
vertical:
2
,
horizontal:
3
);
final
Rect
segmentedControlRect
=
tester
.
getRect
(
find
.
byKey
(
key
));
expect
(
tester
.
getTopLeft
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
0
]),
matching:
find
.
byType
(
Opacity
))),
tester
.
getTopLeft
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
0
]
!
),
matching:
find
.
byType
(
Opacity
))),
segmentedControlRect
.
topLeft
+
effectivePadding
.
topLeft
,
);
expect
(
tester
.
getBottomLeft
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
0
]),
matching:
find
.
byType
(
Opacity
))),
tester
.
getBottomLeft
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
0
]
!
),
matching:
find
.
byType
(
Opacity
))),
segmentedControlRect
.
bottomLeft
+
effectivePadding
.
bottomLeft
,
);
expect
(
tester
.
getTopRight
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
1
]),
matching:
find
.
byType
(
Opacity
))),
tester
.
getTopRight
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
1
]
!
),
matching:
find
.
byType
(
Opacity
))),
segmentedControlRect
.
topRight
+
effectivePadding
.
topRight
,
);
expect
(
tester
.
getBottomRight
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
1
]),
matching:
find
.
byType
(
Opacity
))),
tester
.
getBottomRight
(
find
.
ancestor
(
of:
find
.
byWidget
(
children
[
1
]
!
),
matching:
find
.
byType
(
Opacity
))),
segmentedControlRect
.
bottomRight
+
effectivePadding
.
bottomRight
,
);
}
...
...
@@ -304,7 +254,7 @@ void main() {
DefaultTextStyle
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
).
first
);
expect
(
textStyle
.
style
.
fontWeight
,
FontWeight
.
w500
);
expect
(
textStyle
.
style
!
.
fontWeight
,
FontWeight
.
w500
);
await
tester
.
tap
(
find
.
byIcon
(
const
IconData
(
1
)));
await
tester
.
pump
();
...
...
@@ -313,7 +263,7 @@ void main() {
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
).
first
);
expect
(
groupValue
,
1
);
expect
(
textStyle
.
style
.
fontWeight
,
FontWeight
.
normal
);
expect
(
textStyle
.
style
!
.
fontWeight
,
FontWeight
.
normal
);
},
);
...
...
@@ -324,7 +274,7 @@ void main() {
};
Brightness
brightness
=
Brightness
.
light
;
StateSetter
setState
;
late
StateSetter
setState
;
await
tester
.
pumpWidget
(
StatefulBuilder
(
...
...
@@ -354,7 +304,7 @@ void main() {
)).
decoration
as
BoxDecoration
;
expect
(
getRenderSegmentedControl
(
tester
).
thumbColor
.
value
,
CupertinoColors
.
systemGreen
.
color
.
value
);
expect
(
decoration
.
color
.
value
,
CupertinoColors
.
systemRed
.
color
.
value
);
expect
(
decoration
.
color
!
.
value
,
CupertinoColors
.
systemRed
.
color
.
value
);
setState
(()
{
brightness
=
Brightness
.
dark
;
});
await
tester
.
pump
();
...
...
@@ -366,7 +316,7 @@ void main() {
expect
(
getRenderSegmentedControl
(
tester
).
thumbColor
.
value
,
CupertinoColors
.
systemGreen
.
darkColor
.
value
);
expect
(
decorationDark
.
color
.
value
,
CupertinoColors
.
systemRed
.
darkColor
.
value
);
expect
(
decorationDark
.
color
!
.
value
,
CupertinoColors
.
systemRed
.
darkColor
.
value
);
});
testWidgets
(
...
...
@@ -777,7 +727,7 @@ void main() {
expect
(
groupValue
,
0
);
final
Offset
centerOfTwo
=
tester
.
getCenter
(
find
.
byWidget
(
children
[
1
]));
final
Offset
centerOfTwo
=
tester
.
getCenter
(
find
.
byWidget
(
children
[
1
]
!
));
// Tap within the bounds of children[1], but not at the center.
// children[1] is a SizedBox thus not hittable by itself.
await
tester
.
tapAt
(
centerOfTwo
+
const
Offset
(
10
,
0
));
...
...
@@ -787,7 +737,7 @@ void main() {
testWidgets
(
'Hit-tests report accurate local position in segments'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
TapDownDetails
tapDownDetails
;
late
TapDownDetails
tapDownDetails
;
children
[
0
]
=
GestureDetector
(
behavior:
HitTestBehavior
.
opaque
,
onTapDown:
(
TapDownDetails
details
)
{
tapDownDetails
=
details
;
},
...
...
@@ -810,7 +760,7 @@ void main() {
expect
(
groupValue
,
0
);
final
Offset
segment0GlobalOffset
=
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
]));
final
Offset
segment0GlobalOffset
=
tester
.
getTopLeft
(
find
.
byWidget
(
children
[
0
]
!
));
await
tester
.
tapAt
(
segment0GlobalOffset
+
const
Offset
(
7
,
11
));
expect
(
tapDownDetails
.
localPosition
,
const
Offset
(
7
,
11
));
...
...
packages/flutter/test/cupertino/switch_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
packages/flutter/test/cupertino/tab_scaffold_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:typed_data'
;
import
'package:flutter/cupertino.dart'
;
...
...
@@ -12,10 +10,10 @@ import 'package:flutter_test/flutter_test.dart';
import
'../image_data.dart'
;
import
'../rendering/rendering_tester.dart'
;
List
<
int
>
selectedTabs
;
late
List
<
int
>
selectedTabs
;
class
MockCupertinoTabController
extends
CupertinoTabController
{
MockCupertinoTabController
({
int
initialIndex
}):
super
(
initialIndex:
initialIndex
);
MockCupertinoTabController
({
required
int
initialIndex
}):
super
(
initialIndex:
initialIndex
);
bool
isDisposed
=
false
;
int
numOfListeners
=
0
;
...
...
@@ -75,12 +73,12 @@ void main() {
of:
find
.
text
(
'Tab 1'
),
matching:
find
.
byType
(
RichText
),
));
expect
(
tab1
.
text
.
style
.
color
,
CupertinoColors
.
activeBlue
);
expect
(
tab1
.
text
.
style
!
.
color
,
CupertinoColors
.
activeBlue
);
RichText
tab2
=
tester
.
widget
(
find
.
descendant
(
of:
find
.
text
(
'Tab 2'
),
matching:
find
.
byType
(
RichText
),
));
expect
(
tab2
.
text
.
style
.
color
.
value
,
0xFF999999
);
expect
(
tab2
.
text
.
style
!.
color
!
.
value
,
0xFF999999
);
await
tester
.
tap
(
find
.
text
(
'Tab 2'
));
await
tester
.
pump
();
...
...
@@ -90,12 +88,12 @@ void main() {
of:
find
.
text
(
'Tab 1'
),
matching:
find
.
byType
(
RichText
),
));
expect
(
tab1
.
text
.
style
.
color
.
value
,
0xFF999999
);
expect
(
tab1
.
text
.
style
!.
color
!
.
value
,
0xFF999999
);
tab2
=
tester
.
widget
(
find
.
descendant
(
of:
find
.
text
(
'Tab 2'
),
matching:
find
.
byType
(
RichText
),
));
expect
(
tab2
.
text
.
style
.
color
,
CupertinoColors
.
activeBlue
);
expect
(
tab2
.
text
.
style
!
.
color
,
CupertinoColors
.
activeBlue
);
await
tester
.
tap
(
find
.
text
(
'Tab 1'
));
await
tester
.
pump
();
...
...
@@ -377,16 +375,16 @@ void main() {
matching:
find
.
byType
(
RichText
),
));
// Tab 2 should still be selected after changing theme.
expect
(
tab1
.
text
.
style
.
color
.
value
,
0xFF757575
);
expect
(
tab1
.
text
.
style
!.
color
!
.
value
,
0xFF757575
);
final
RichText
tab2
=
tester
.
widget
(
find
.
descendant
(
of:
find
.
text
(
'Tab 2'
),
matching:
find
.
byType
(
RichText
),
));
expect
(
tab2
.
text
.
style
.
color
,
isSameColorAs
(
CupertinoColors
.
systemRed
.
darkColor
));
expect
(
tab2
.
text
.
style
!
.
color
,
isSameColorAs
(
CupertinoColors
.
systemRed
.
darkColor
));
});
testWidgets
(
'Tab contents are padded when there are view insets'
,
(
WidgetTester
tester
)
async
{
BuildContext
innerContext
;
late
BuildContext
innerContext
;
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -408,11 +406,11 @@ void main() {
expect
(
tester
.
getRect
(
find
.
byType
(
Placeholder
)),
const
Rect
.
fromLTWH
(
0
,
0
,
800
,
400
));
// Don't generate more media query padding from the translucent bottom
// tab since the tab is behind the keyboard now.
expect
(
MediaQuery
.
of
(
innerContext
).
padding
.
bottom
,
0
);
expect
(
MediaQuery
.
of
(
innerContext
)
!
.
padding
.
bottom
,
0
);
});
testWidgets
(
'Tab contents are not inset when resizeToAvoidBottomInset overridden'
,
(
WidgetTester
tester
)
async
{
BuildContext
innerContext
;
late
BuildContext
innerContext
;
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -435,7 +433,7 @@ void main() {
expect
(
tester
.
getRect
(
find
.
byType
(
Placeholder
)),
const
Rect
.
fromLTWH
(
0
,
0
,
800
,
600
));
// Media query padding shows up in the inner content because it wasn't masked
// by the view inset.
expect
(
MediaQuery
.
of
(
innerContext
).
padding
.
bottom
,
50
);
expect
(
MediaQuery
.
of
(
innerContext
)
!
.
padding
.
bottom
,
50
);
});
testWidgets
(
'Tab contents bottom padding are not consumed by viewInsets when resizeToAvoidBottomInset overridden'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -492,7 +490,7 @@ void main() {
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/43581.
Future
<
EdgeInsets
>
getContentPaddingWithTabBarColor
(
Color
color
)
async
{
EdgeInsets
contentPadding
;
late
EdgeInsets
contentPadding
;
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -504,7 +502,7 @@ void main() {
items:
List
<
BottomNavigationBarItem
>.
generate
(
2
,
tabGenerator
),
),
tabBuilder:
(
BuildContext
context
,
int
index
)
{
contentPadding
=
MediaQuery
.
of
(
context
).
padding
;
contentPadding
=
MediaQuery
.
of
(
context
)
!
.
padding
;
return
const
Placeholder
();
}
),
...
...
@@ -519,7 +517,7 @@ void main() {
});
testWidgets
(
'Tab and page scaffolds do not double stack view insets'
,
(
WidgetTester
tester
)
async
{
BuildContext
innerContext
;
late
BuildContext
innerContext
;
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -545,7 +543,7 @@ void main() {
);
expect
(
tester
.
getRect
(
find
.
byType
(
Placeholder
)),
const
Rect
.
fromLTWH
(
0
,
0
,
800
,
400
));
expect
(
MediaQuery
.
of
(
innerContext
).
padding
.
bottom
,
0
);
expect
(
MediaQuery
.
of
(
innerContext
)
!
.
padding
.
bottom
,
0
);
});
testWidgets
(
'Deleting tabs after selecting them should switch to the last available tab'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -965,7 +963,7 @@ void main() {
testWidgets
(
"Don't replace focus nodes for existing tabs when changing tab count"
,
(
WidgetTester
tester
)
async
{
final
CupertinoTabController
controller
=
CupertinoTabController
(
initialIndex:
2
);
final
List
<
FocusScopeNode
>
scopes
=
List
<
FocusScopeNode
>
(
5
);
final
List
<
FocusScopeNode
>
scopes
=
List
<
FocusScopeNode
>
.
filled
(
5
,
FocusScopeNode
()
);
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoTabScaffold
(
...
...
@@ -987,7 +985,7 @@ void main() {
}
await
tester
.
pump
();
final
List
<
FocusScopeNode
>
newScopes
=
List
<
FocusScopeNode
>(
5
)
;
final
List
<
FocusScopeNode
>
newScopes
=
<
FocusScopeNode
>[]
;
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoTabScaffold
(
...
...
@@ -996,7 +994,7 @@ void main() {
),
controller:
controller
,
tabBuilder:
(
BuildContext
context
,
int
index
)
{
newScopes
[
index
]
=
FocusScope
.
of
(
context
);
newScopes
.
add
(
FocusScope
.
of
(
context
)
);
return
Container
();
},
),
...
...
@@ -1021,12 +1019,10 @@ void main() {
}
expectAssertionError
(()
=>
CupertinoTabController
(
initialIndex:
-
1
),
'>= 0'
);
expectAssertionError
(()
=>
CupertinoTabController
(
initialIndex:
null
),
'!= null'
);
final
CupertinoTabController
controller
=
CupertinoTabController
();
expectAssertionError
(()
=>
controller
.
index
=
-
1
,
'>= 0'
);
expectAssertionError
(()
=>
controller
.
index
=
null
,
'!= null'
);
});
testWidgets
(
'Does not lose state when focusing on text input'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -1078,7 +1074,7 @@ void main() {
CupertinoApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
return
MediaQuery
(
data:
MediaQuery
.
of
(
context
).
copyWith
(
textScaleFactor:
99
),
data:
MediaQuery
.
of
(
context
)
!
.
copyWith
(
textScaleFactor:
99
),
child:
CupertinoTabScaffold
(
tabBar:
CupertinoTabBar
(
items:
List
<
BottomNavigationBarItem
>.
generate
(
...
...
packages/flutter/test/cupertino/tab_test.dart
View file @
b5562c1b
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -42,7 +40,7 @@ void main() {
return
CupertinoButton
(
child:
const
Text
(
'go to second page'
),
onPressed:
()
{
Navigator
.
of
(
context
).
pushNamed
(
'/2'
);
Navigator
.
of
(
context
)
!
.
pushNamed
(
'/2'
);
},
);
},
...
...
@@ -83,12 +81,12 @@ void main() {
});
testWidgets
(
'Use onUnknownRoute'
,
(
WidgetTester
tester
)
async
{
String
unknownForRouteCalled
;
late
String
unknownForRouteCalled
;
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoTabView
(
onUnknownRoute:
(
RouteSettings
settings
)
{
unknownForRouteCalled
=
settings
.
name
;
unknownForRouteCalled
=
settings
.
name
!
;
return
null
;
},
),
...
...
@@ -117,7 +115,7 @@ void main() {
),
);
key
.
currentState
.
pushNamed
(
'/2'
);
key
.
currentState
!
.
pushNamed
(
'/2'
);
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
300
));
...
...
@@ -133,7 +131,7 @@ void main() {
return
CupertinoButton
(
child:
const
Text
(
'go to second page'
),
onPressed:
()
{
Navigator
.
of
(
context
).
pushNamed
(
'/2'
);
Navigator
.
of
(
context
)
!
.
pushNamed
(
'/2'
);
},
);
},
...
...
@@ -158,7 +156,7 @@ void main() {
return
CupertinoButton
(
child:
const
Text
(
'go to second page'
),
onPressed:
()
{
Navigator
.
of
(
context
).
pushNamed
(
'/2'
);
Navigator
.
of
(
context
)
!
.
pushNamed
(
'/2'
);
},
);
},
...
...
@@ -186,9 +184,9 @@ void main() {
),
),
);
FlutterError
error
;
late
FlutterError
error
;
try
{
key
.
currentState
.
pushNamed
(
'/2'
);
key
.
currentState
!
.
pushNamed
(
'/2'
);
}
on
FlutterError
catch
(
e
)
{
error
=
e
;
}
...
...
@@ -222,9 +220,9 @@ void main() {
),
),
);
FlutterError
error
;
late
FlutterError
error
;
try
{
key
.
currentState
.
pushNamed
(
'/2'
);
key
.
currentState
!
.
pushNamed
(
'/2'
);
}
on
FlutterError
catch
(
e
)
{
error
=
e
;
}
...
...
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