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
4bf2e557
Commit
4bf2e557
authored
Nov 05, 2019
by
Taufiq Rahman
Committed by
Shi-Hao Hong
Nov 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust and refactor all RaisedButton tests into its respective file (#44169)
parent
e5af60c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
236 additions
and
217 deletions
+236
-217
buttons_test.dart
packages/flutter/test/material/buttons_test.dart
+4
-217
raised_button_test.dart
packages/flutter/test/material/raised_button_test.dart
+232
-0
No files found.
packages/flutter/test/material/buttons_test.dart
View file @
4bf2e557
...
...
@@ -9,90 +9,12 @@ import 'package:flutter/widgets.dart';
import
'package:flutter_test/flutter_test.dart'
;
import
'../rendering/mock_canvas.dart'
;
import
'../widgets/semantics_tester.dart'
;
void
main
(
)
{
setUp
(()
{
debugResetSemanticsIdCounter
();
});
testWidgets
(
'RaisedButton defaults'
,
(
WidgetTester
tester
)
async
{
final
Finder
rawButtonMaterial
=
find
.
descendant
(
of:
find
.
byType
(
RaisedButton
),
matching:
find
.
byType
(
Material
),
);
// Enabled RaisedButton
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
Material
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0xffe0e0e0
));
expect
(
material
.
elevation
,
2.0
);
expect
(
material
.
shadowColor
,
const
Color
(
0xff000000
));
expect
(
material
.
shape
,
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
2.0
)));
expect
(
material
.
textStyle
.
color
,
const
Color
(
0xdd000000
));
expect
(
material
.
textStyle
.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
.
fontSize
,
14
);
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
RaisedButton
));
await
tester
.
startGesture
(
center
);
await
tester
.
pumpAndSettle
();
// Only elevation changes when enabled and pressed.
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0xffe0e0e0
));
expect
(
material
.
elevation
,
8.0
);
expect
(
material
.
shadowColor
,
const
Color
(
0xff000000
));
expect
(
material
.
shape
,
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
2.0
)));
expect
(
material
.
textStyle
.
color
,
const
Color
(
0xdd000000
));
expect
(
material
.
textStyle
.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
.
fontSize
,
14
);
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
// Disabled RaisedButton
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
null
,
child:
Text
(
'button'
),
),
),
);
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0x61000000
));
expect
(
material
.
elevation
,
0.0
);
expect
(
material
.
shadowColor
,
const
Color
(
0xff000000
));
expect
(
material
.
shape
,
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
2.0
)));
expect
(
material
.
textStyle
.
color
,
const
Color
(
0x61000000
));
expect
(
material
.
textStyle
.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
.
fontSize
,
14
);
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
});
testWidgets
(
'OutlineButton defaults'
,
(
WidgetTester
tester
)
async
{
final
Finder
rawButtonMaterial
=
find
.
descendant
(
of:
find
.
byType
(
OutlineButton
),
...
...
@@ -185,22 +107,7 @@ void main() {
await
gesture
.
addPointer
();
await
gesture
.
moveTo
(
tester
.
getCenter
(
find
.
byType
(
OutlineButton
)));
await
tester
.
pumpAndSettle
();
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
hoverColor
));
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
hoverColor:
hoverColor
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
await
tester
.
pumpAndSettle
();
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
final
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
hoverColor
));
gesture
.
removePointer
();
...
...
@@ -209,11 +116,11 @@ void main() {
testWidgets
(
'Do buttons work with focus'
,
(
WidgetTester
tester
)
async
{
const
Color
focusColor
=
Color
(
0xff001122
);
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'Raised
Button Node'
);
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'Outline
Button Node'
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Raised
Button
(
child:
Outline
Button
(
focusColor:
focusColor
,
focusNode:
focusNode
,
onPressed:
()
{
},
...
...
@@ -226,127 +133,7 @@ void main() {
focusNode
.
requestFocus
();
await
tester
.
pumpAndSettle
();
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
focusColor
));
focusNode
=
FocusNode
(
debugLabel:
'OutlineButton Node'
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
OutlineButton
(
focusColor:
focusColor
,
focusNode:
focusNode
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
focusNode
.
requestFocus
();
await
tester
.
pumpAndSettle
();
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
final
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
focusColor
));
});
testWidgets
(
'Does RaisedButton contribute semantics'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
RaisedButton
(
onPressed:
()
{
},
child:
const
Text
(
'ABC'
),
),
),
),
),
);
expect
(
semantics
,
hasSemantics
(
TestSemantics
.
root
(
children:
<
TestSemantics
>[
TestSemantics
.
rootChild
(
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
,
],
label:
'ABC'
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
88.0
,
48.0
),
transform:
Matrix4
.
translationValues
(
356.0
,
276.0
,
0.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
hasEnabledState
,
SemanticsFlag
.
isButton
,
SemanticsFlag
.
isEnabled
,
SemanticsFlag
.
isFocusable
,
],
),
],
),
ignoreId:
true
,
));
semantics
.
dispose
();
});
testWidgets
(
'RaisedButton size is configurable by ThemeData.materialTapTargetSize'
,
(
WidgetTester
tester
)
async
{
final
Key
key1
=
UniqueKey
();
await
tester
.
pumpWidget
(
Theme
(
data:
ThemeData
(
materialTapTargetSize:
MaterialTapTargetSize
.
padded
),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
RaisedButton
(
key:
key1
,
child:
const
SizedBox
(
width:
50.0
,
height:
8.0
),
onPressed:
()
{
},
),
),
),
),
),
);
expect
(
tester
.
getSize
(
find
.
byKey
(
key1
)),
const
Size
(
88.0
,
48.0
));
final
Key
key2
=
UniqueKey
();
await
tester
.
pumpWidget
(
Theme
(
data:
ThemeData
(
materialTapTargetSize:
MaterialTapTargetSize
.
shrinkWrap
),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
RaisedButton
(
key:
key2
,
child:
const
SizedBox
(
width:
50.0
,
height:
8.0
),
onPressed:
()
{
},
),
),
),
),
),
);
expect
(
tester
.
getSize
(
find
.
byKey
(
key2
)),
const
Size
(
88.0
,
36.0
));
});
testWidgets
(
'RaisedButton has no clip by default'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
RaisedButton
(
onPressed:
()
{
/* to make sure the button is enabled */
},
),
),
),
);
expect
(
tester
.
renderObject
(
find
.
byType
(
RaisedButton
)),
paintsExactlyCountTimes
(
#clipPath
,
0
),
);
});
}
packages/flutter/test/material/raised_button_test.dart
View file @
4bf2e557
...
...
@@ -7,7 +7,87 @@ import 'package:flutter/material.dart';
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/rendering.dart'
;
import
'../rendering/mock_canvas.dart'
;
import
'../widgets/semantics_tester.dart'
;
void
main
(
)
{
testWidgets
(
'RaisedButton defaults'
,
(
WidgetTester
tester
)
async
{
final
Finder
rawButtonMaterial
=
find
.
descendant
(
of:
find
.
byType
(
RaisedButton
),
matching:
find
.
byType
(
Material
),
);
// Enabled RaisedButton
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
Material
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0xffe0e0e0
));
expect
(
material
.
elevation
,
2.0
);
expect
(
material
.
shadowColor
,
const
Color
(
0xff000000
));
expect
(
material
.
shape
,
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
2.0
)));
expect
(
material
.
textStyle
.
color
,
const
Color
(
0xdd000000
));
expect
(
material
.
textStyle
.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
.
fontSize
,
14
);
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
RaisedButton
));
await
tester
.
startGesture
(
center
);
await
tester
.
pumpAndSettle
();
// Only elevation changes when enabled and pressed.
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0xffe0e0e0
));
expect
(
material
.
elevation
,
8.0
);
expect
(
material
.
shadowColor
,
const
Color
(
0xff000000
));
expect
(
material
.
shape
,
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
2.0
)));
expect
(
material
.
textStyle
.
color
,
const
Color
(
0xdd000000
));
expect
(
material
.
textStyle
.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
.
fontSize
,
14
);
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
// Disabled RaisedButton
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
onPressed:
null
,
child:
Text
(
'button'
),
),
),
);
material
=
tester
.
widget
<
Material
>(
rawButtonMaterial
);
expect
(
material
.
animationDuration
,
const
Duration
(
milliseconds:
200
));
expect
(
material
.
borderOnForeground
,
true
);
expect
(
material
.
borderRadius
,
null
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
expect
(
material
.
color
,
const
Color
(
0x61000000
));
expect
(
material
.
elevation
,
0.0
);
expect
(
material
.
shadowColor
,
const
Color
(
0xff000000
));
expect
(
material
.
shape
,
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
2.0
)));
expect
(
material
.
textStyle
.
color
,
const
Color
(
0x61000000
));
expect
(
material
.
textStyle
.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
.
fontSize
,
14
);
expect
(
material
.
textStyle
.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
});
testWidgets
(
'RaisedButton implements debugFillProperties'
,
(
WidgetTester
tester
)
async
{
final
DiagnosticPropertiesBuilder
builder
=
DiagnosticPropertiesBuilder
();
RaisedButton
(
...
...
@@ -325,6 +405,158 @@ void main() {
await
tester
.
longPress
(
raisedButton
);
expect
(
didLongPressButton
,
isTrue
);
});
testWidgets
(
'Does RaisedButton work with hover'
,
(
WidgetTester
tester
)
async
{
const
Color
hoverColor
=
Color
(
0xff001122
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
hoverColor:
hoverColor
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
);
await
gesture
.
addPointer
();
await
gesture
.
moveTo
(
tester
.
getCenter
(
find
.
byType
(
RaisedButton
)));
await
tester
.
pumpAndSettle
();
final
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
hoverColor
));
await
gesture
.
removePointer
();
});
testWidgets
(
'Does RaisedButton work with focus'
,
(
WidgetTester
tester
)
async
{
const
Color
focusColor
=
Color
(
0xff001122
);
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'RaisedButton Node'
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
RaisedButton
(
focusColor:
focusColor
,
focusNode:
focusNode
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
FocusManager
.
instance
.
highlightStrategy
=
FocusHighlightStrategy
.
alwaysTraditional
;
focusNode
.
requestFocus
();
await
tester
.
pumpAndSettle
();
final
RenderObject
inkFeatures
=
tester
.
allRenderObjects
.
firstWhere
((
RenderObject
object
)
=>
object
.
runtimeType
.
toString
()
==
'_RenderInkFeatures'
);
expect
(
inkFeatures
,
paints
..
rect
(
color:
focusColor
));
});
testWidgets
(
'Does RaisedButton contribute semantics'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
RaisedButton
(
onPressed:
()
{
},
child:
const
Text
(
'ABC'
),
),
),
),
),
);
expect
(
semantics
,
hasSemantics
(
TestSemantics
.
root
(
children:
<
TestSemantics
>[
TestSemantics
.
rootChild
(
actions:
<
SemanticsAction
>[
SemanticsAction
.
tap
,
],
label:
'ABC'
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
88.0
,
48.0
),
transform:
Matrix4
.
translationValues
(
356.0
,
276.0
,
0.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
hasEnabledState
,
SemanticsFlag
.
isButton
,
SemanticsFlag
.
isEnabled
,
SemanticsFlag
.
isFocusable
,
],
),
],
),
ignoreId:
true
,
));
semantics
.
dispose
();
});
testWidgets
(
'RaisedButton size is configurable by ThemeData.materialTapTargetSize'
,
(
WidgetTester
tester
)
async
{
final
Key
key1
=
UniqueKey
();
await
tester
.
pumpWidget
(
Theme
(
data:
ThemeData
(
materialTapTargetSize:
MaterialTapTargetSize
.
padded
),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
RaisedButton
(
key:
key1
,
child:
const
SizedBox
(
width:
50.0
,
height:
8.0
),
onPressed:
()
{
},
),
),
),
),
),
);
expect
(
tester
.
getSize
(
find
.
byKey
(
key1
)),
const
Size
(
88.0
,
48.0
));
final
Key
key2
=
UniqueKey
();
await
tester
.
pumpWidget
(
Theme
(
data:
ThemeData
(
materialTapTargetSize:
MaterialTapTargetSize
.
shrinkWrap
),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
RaisedButton
(
key:
key2
,
child:
const
SizedBox
(
width:
50.0
,
height:
8.0
),
onPressed:
()
{
},
),
),
),
),
),
);
expect
(
tester
.
getSize
(
find
.
byKey
(
key2
)),
const
Size
(
88.0
,
36.0
));
});
testWidgets
(
'RaisedButton has no clip by default'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
RaisedButton
(
onPressed:
()
{
/* to make sure the button is enabled */
},
),
),
),
);
expect
(
tester
.
renderObject
(
find
.
byType
(
RaisedButton
)),
paintsExactlyCountTimes
(
#clipPath
,
0
),
);
});
}
TextStyle
_iconStyle
(
WidgetTester
tester
,
IconData
icon
)
{
...
...
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