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
5fbec7b8
Commit
5fbec7b8
authored
Jun 25, 2018
by
sandrasandeep
Committed by
Mikkel Nygaard Ravn
Jun 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix segmented control golden tests (#18695)
parent
def7634b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
42 deletions
+87
-42
segmented_control_test.dart
packages/flutter/test/cupertino/segmented_control_test.dart
+87
-42
No files found.
packages/flutter/test/cupertino/segmented_control_test.dart
View file @
5fbec7b8
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:io'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -94,7 +96,8 @@ void main() {
),
),
);
fail
(
'Should not be possible to create a segmented control with no children'
);
fail
(
'Should not be possible to create a segmented control with no children'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'children.length'
));
}
...
...
@@ -109,14 +112,15 @@ void main() {
),
),
);
fail
(
'Should not be possible to create a segmented control with just one child'
);
fail
(
'Should not be possible to create a segmented control with just one child'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'children.length'
));
}
});
testWidgets
(
'Value attribute must be the key of one of the children widgets'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
...
...
@@ -138,7 +142,8 @@ void main() {
}
});
testWidgets
(
'Children and onValueChanged can not be null'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Children and onValueChanged can not be null'
,
(
WidgetTester
tester
)
async
{
try
{
await
tester
.
pumpWidget
(
boilerplate
(
...
...
@@ -148,7 +153,8 @@ void main() {
),
),
);
fail
(
'Should not be possible to create segmented control with null children'
);
fail
(
'Should not be possible to create segmented control with null children'
);
}
on
AssertionError
catch
(
e
)
{
expect
(
e
.
toString
(),
contains
(
'children'
));
}
...
...
@@ -166,14 +172,16 @@ void main() {
),
),
);
fail
(
'Should not be possible to create segmented control with null onValueChanged'
);
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
{
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'
);
children
[
1
]
=
const
Icon
(
IconData
(
1
));
...
...
@@ -198,8 +206,10 @@ void main() {
),
);
DefaultTextStyle
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
IconTheme
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
DefaultTextStyle
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
IconTheme
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
textStyle
.
style
.
color
,
CupertinoColors
.
white
);
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
activeBlue
);
...
...
@@ -208,7 +218,8 @@ void main() {
await
tester
.
pump
();
textStyle
=
tester
.
widget
(
find
.
widgetWithText
(
DefaultTextStyle
,
'Child 1'
));
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
iconTheme
=
tester
.
widget
(
find
.
widgetWithIcon
(
IconTheme
,
const
IconData
(
1
)));
expect
(
textStyle
.
style
.
color
,
CupertinoColors
.
activeBlue
);
expect
(
iconTheme
.
data
.
color
,
CupertinoColors
.
white
);
...
...
@@ -243,8 +254,9 @@ void main() {
expect
(
value
,
isTrue
);
});
testWidgets
(
'State does not change if onValueChanged does not call setState()'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'State does not change if onValueChanged does not call setState()'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
...
...
@@ -265,7 +277,8 @@ void main() {
),
);
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
expect
(
getRenderSegmentedControl
(
tester
),
...
...
@@ -314,7 +327,8 @@ void main() {
'and should not change when tapped again'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
setupSimpleSegmentedControl
());
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
expect
(
getRenderSegmentedControl
(
tester
),
...
...
@@ -389,12 +403,14 @@ void main() {
},
);
testWidgets
(
'Passed in value is child initially selected'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Passed in value is child initially selected'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
setupSimpleSegmentedControl
());
expect
(
getRenderSegmentedControl
(
tester
).
selectedIndex
,
0
);
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
expect
(
getRenderSegmentedControl
(
tester
),
...
...
@@ -417,7 +433,7 @@ void main() {
});
testWidgets
(
'Null input for value results in no child initially selected'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
...
...
@@ -444,7 +460,8 @@ void main() {
expect
(
getRenderSegmentedControl
(
tester
).
selectedIndex
,
null
);
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
expect
(
getRenderSegmentedControl
(
tester
),
...
...
@@ -467,10 +484,11 @@ void main() {
});
testWidgets
(
'Long press changes background color of not-selected child'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
setupSimpleSegmentedControl
());
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
expect
(
getRenderSegmentedControl
(
tester
),
...
...
@@ -515,11 +533,13 @@ void main() {
);
});
testWidgets
(
'Long press does not change background color of currently-selected child'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Long press does not change background color of currently-selected child'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
setupSimpleSegmentedControl
());
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
expect
(
getRenderSegmentedControl
(
tester
),
...
...
@@ -565,7 +585,7 @@ void main() {
});
testWidgets
(
'Height of segmented control is determined by tallest widget'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
new
Container
(
constraints:
const
BoxConstraints
.
tightFor
(
height:
100.0
),
...
...
@@ -591,15 +611,16 @@ void main() {
),
);
final
RenderBox
buttonBox
=
tester
.
renderObject
(
find
.
byKey
(
const
ValueKey
<
String
>(
'Segmented Control'
)));
final
RenderBox
buttonBox
=
tester
.
renderObject
(
find
.
byKey
(
const
ValueKey
<
String
>(
'Segmented Control'
)));
// Default height of Placeholder is 400.0px, which is greater than heights
// of other child widgets.
expect
(
buttonBox
.
size
.
height
,
400.0
);
});
testWidgets
(
'Width of each child widget is the same'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Width of each child widget is the same'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
new
Container
();
children
[
1
]
=
const
Placeholder
();
...
...
@@ -619,21 +640,23 @@ void main() {
),
);
final
RenderBox
segmentedControl
=
tester
.
renderObject
(
find
.
byKey
(
const
ValueKey
<
String
>(
'Segmented Control'
)));
final
RenderBox
segmentedControl
=
tester
.
renderObject
(
find
.
byKey
(
const
ValueKey
<
String
>(
'Segmented Control'
)));
// Subtract the 16.0px from each side. Remaining width should be allocated
// to each child equally.
final
double
childWidth
=
(
segmentedControl
.
size
.
width
-
32.0
)
/
3
;
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
for
(
dynamic
child
in
childList
)
{
expect
(
childWidth
,
child
.
parentData
.
surroundingRect
.
width
);
}
});
testWidgets
(
'Width is finite in unbounded space'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Width is finite in unbounded space'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
...
...
@@ -656,14 +679,14 @@ void main() {
),
);
final
RenderBox
segmentedControl
=
tester
.
renderObject
(
find
.
byKey
(
const
ValueKey
<
String
>(
'Segmented Control'
)));
final
RenderBox
segmentedControl
=
tester
.
renderObject
(
find
.
byKey
(
const
ValueKey
<
String
>(
'Segmented Control'
)));
expect
(
segmentedControl
.
size
.
width
.
isFinite
,
isTrue
);
});
testWidgets
(
'Directionality test - RTL should reverse order of widgets'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
...
...
@@ -680,12 +703,14 @@ void main() {
),
);
expect
(
tester
.
getTopRight
(
find
.
text
(
'Child 1'
)).
dx
>
tester
.
getTopRight
(
find
.
text
(
'Child 2'
)).
dx
,
isTrue
);
expect
(
tester
.
getTopRight
(
find
.
text
(
'Child 1'
)).
dx
>
tester
.
getTopRight
(
find
.
text
(
'Child 2'
)).
dx
,
isTrue
);
});
testWidgets
(
'Correct initial selection and toggling behavior - RTL'
,
(
WidgetTester
tester
)
async
{
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'Child 1'
);
children
[
1
]
=
const
Text
(
'Child 2'
);
...
...
@@ -713,7 +738,8 @@ void main() {
),
);
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
final
dynamic
childList
=
getRenderSegmentedControl
(
tester
).
getChildrenAsList
();
expect
(
getRenderSegmentedControl
(
tester
),
...
...
@@ -869,6 +895,13 @@ void main() {
});
testWidgets
(
'Golden Test Placeholder Widget'
,
(
WidgetTester
tester
)
async
{
// Different machines render this content differently. Since the golden
// files are rendered on MacOS, this test should only be run on MacOS.
// If the golden files are regenerated on another OS, please change this
// test to only run on that OS.
if
(
Platform
.
isMacOS
)
return
;
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
new
Container
();
children
[
1
]
=
const
Placeholder
();
...
...
@@ -893,10 +926,20 @@ void main() {
),
);
await
expectLater
(
find
.
byType
(
RepaintBoundary
),
matchesGoldenFile
(
'segmented_control_test.0.0.png'
));
await
expectLater
(
find
.
byType
(
RepaintBoundary
),
matchesGoldenFile
(
'segmented_control_test.0.0.png'
),
);
});
testWidgets
(
'Golden Test Pressed State'
,
(
WidgetTester
tester
)
async
{
// Different machines render this content differently. Since the golden
// files are rendered on MacOS, this test should only be run on MacOS.
// If the golden files are regenerated on another OS, please change this
// test to only run on that OS.
if
(!
Platform
.
isMacOS
)
return
;
final
Map
<
int
,
Widget
>
children
=
<
int
,
Widget
>{};
children
[
0
]
=
const
Text
(
'A'
);
children
[
1
]
=
const
Text
(
'B'
);
...
...
@@ -924,7 +967,9 @@ void main() {
final
Offset
center
=
tester
.
getCenter
(
find
.
text
(
'B'
));
await
tester
.
startGesture
(
center
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
RepaintBoundary
),
matchesGoldenFile
(
'segmented_control_test.1.0.png'
));
await
expectLater
(
find
.
byType
(
RepaintBoundary
),
matchesGoldenFile
(
'segmented_control_test.1.0.png'
),
);
});
}
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