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
84cf5489
Commit
84cf5489
authored
Jan 10, 2017
by
Adam Barth
Committed by
GitHub
Jan 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve test coverage (#7401)
This patch adds a number of tests for previously untested lines.
parent
258fc011
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
297 additions
and
46 deletions
+297
-46
table.dart
packages/flutter/lib/src/widgets/table.dart
+9
-1
text_selection.dart
packages/flutter/lib/src/widgets/text_selection.dart
+1
-1
ticker_provider.dart
packages/flutter/lib/src/widgets/ticker_provider.dart
+2
-4
switch_test.dart
packages/flutter/test/material/switch_test.dart
+43
-36
table_test.dart
packages/flutter/test/widgets/table_test.dart
+166
-0
ticker_provider_test.dart
packages/flutter/test/widgets/ticker_provider_test.dart
+10
-4
title_test.dart
packages/flutter/test/widgets/title_test.dart
+16
-0
transitions_test.dart
packages/flutter/test/widgets/transitions_test.dart
+16
-0
unique_widget_test.dart
packages/flutter/test/widgets/unique_widget_test.dart
+34
-0
No files found.
packages/flutter/lib/src/widgets/table.dart
View file @
84cf5489
...
...
@@ -269,7 +269,15 @@ class _TableElement extends RenderObjectElement {
@override
void
removeChildRenderObject
(
RenderObject
child
)
{
assert
(
_debugWillReattachChildren
);
assert
(()
{
if
(
_debugWillReattachChildren
)
return
true
;
for
(
Element
forgottenChild
in
_forgottenChildren
)
{
if
(
forgottenChild
.
renderObject
==
child
)
return
true
;
}
return
false
;
});
TableCellParentData
childParentData
=
child
.
parentData
;
renderObject
.
setChild
(
childParentData
.
x
,
childParentData
.
y
,
null
);
}
...
...
packages/flutter/lib/src/widgets/text_selection.dart
View file @
84cf5489
...
...
@@ -401,13 +401,13 @@ class _TextSelectionHandleOverlayState extends State<_TextSelectionHandleOverlay
if
(
config
.
selection
.
isCollapsed
)
return
TextSelectionHandleType
.
collapsed
;
assert
(
endpoint
.
direction
!=
null
);
switch
(
endpoint
.
direction
)
{
case
TextDirection
.
ltr
:
return
ltrType
;
case
TextDirection
.
rtl
:
return
rtlType
;
}
assert
(
endpoint
.
direction
!=
null
);
return
null
;
}
}
packages/flutter/lib/src/widgets/ticker_provider.dart
View file @
84cf5489
...
...
@@ -130,11 +130,9 @@ abstract class SingleTickerProviderStateMixin implements State<dynamic>, TickerP
if
(
_ticker
!=
null
)
{
if
(
_ticker
.
isActive
&&
_ticker
.
muted
)
description
.
add
(
'ticker active but muted'
);
else
if
(
_ticker
.
isActive
)
else
if
(
_ticker
.
isActive
)
description
.
add
(
'ticker active'
);
else
if
(
_ticker
.
muted
)
else
if
(
_ticker
.
muted
)
description
.
add
(
'ticker inactive and muted'
);
else
description
.
add
(
'ticker inactive'
);
...
...
packages/flutter/test/material/switch_test.dart
View file @
84cf5489
...
...
@@ -6,42 +6,6 @@ import 'package:flutter/material.dart';
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
class
TestBoxPainter
extends
BoxPainter
{
TestBoxPainter
(
VoidCallback
onChanged
):
super
(
onChanged
);
@override
void
paint
(
Canvas
canvas
,
Offset
offset
,
ImageConfiguration
configuration
)
{
}
}
class
TestDecoration
extends
Decoration
{
int
listeners
=
0
;
@override
Decoration
lerpFrom
(
Decoration
a
,
double
t
)
{
if
(
t
==
0.0
)
return
a
;
if
(
t
==
1.0
)
return
this
;
return
new
TestDecoration
();
}
@override
Decoration
lerpTo
(
Decoration
b
,
double
t
)
{
if
(
t
==
1.0
)
return
b
;
if
(
t
==
0.0
)
return
this
;
return
new
TestDecoration
();
}
@override
BoxPainter
createBoxPainter
([
VoidCallback
onChanged
])
{
if
(
onChanged
!=
null
)
listeners
+=
1
;
return
new
TestBoxPainter
(
onChanged
);
}
}
void
main
(
)
{
testWidgets
(
'Switch can toggle on tap'
,
(
WidgetTester
tester
)
async
{
Key
switchKey
=
new
UniqueKey
();
...
...
@@ -71,4 +35,47 @@ void main() {
await
tester
.
tap
(
find
.
byKey
(
switchKey
));
expect
(
value
,
isTrue
);
});
testWidgets
(
'Switch can drag'
,
(
WidgetTester
tester
)
async
{
bool
value
=
false
;
await
tester
.
pumpWidget
(
new
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
new
Material
(
child:
new
Center
(
child:
new
Switch
(
value:
value
,
onChanged:
(
bool
newValue
)
{
setState
(()
{
value
=
newValue
;
});
}
)
)
);
}
)
);
expect
(
value
,
isFalse
);
await
tester
.
scroll
(
find
.
byType
(
Switch
),
const
Offset
(-
30.0
,
0.0
));
expect
(
value
,
isFalse
);
await
tester
.
scroll
(
find
.
byType
(
Switch
),
const
Offset
(
30.0
,
0.0
));
expect
(
value
,
isTrue
);
await
tester
.
pump
();
await
tester
.
scroll
(
find
.
byType
(
Switch
),
const
Offset
(
30.0
,
0.0
));
expect
(
value
,
isTrue
);
await
tester
.
pump
();
await
tester
.
scroll
(
find
.
byType
(
Switch
),
const
Offset
(-
30.0
,
0.0
));
expect
(
value
,
isFalse
);
});
}
packages/flutter/test/widgets/table_test.dart
View file @
84cf5489
...
...
@@ -6,6 +6,18 @@ import 'package:flutter_test/flutter_test.dart';
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
class
TestStatefulWidget
extends
StatefulWidget
{
TestStatefulWidget
({
Key
key
})
:
super
(
key:
key
);
@override
TestStatefulWidgetState
createState
()
=>
new
TestStatefulWidgetState
();
}
class
TestStatefulWidgetState
extends
State
<
TestStatefulWidget
>
{
@override
Widget
build
(
BuildContext
context
)
=>
new
Container
();
}
void
main
(
)
{
testWidgets
(
'Table widget - control test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
...
...
@@ -331,5 +343,159 @@ void main() {
expect
(
contexts
.
length
,
equals
(
2
));
expect
(
contexts
[
0
],
equals
(
contexts
[
1
]));
});
testWidgets
(
'Table widget - keyed rows'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
Table
(
children:
<
TableRow
>[
new
TableRow
(
key:
const
ValueKey
<
int
>(
1
),
children:
<
Widget
>[
new
TestStatefulWidget
(
key:
const
ValueKey
<
int
>(
11
)),
new
TestStatefulWidget
(
key:
const
ValueKey
<
int
>(
12
)),
],
),
new
TableRow
(
key:
const
ValueKey
<
int
>(
2
),
children:
<
Widget
>[
new
TestStatefulWidget
(
key:
const
ValueKey
<
int
>(
21
)),
new
TestStatefulWidget
(
key:
const
ValueKey
<
int
>(
22
)),
],
),
]
)
);
TestStatefulWidgetState
state11
=
tester
.
state
(
find
.
byKey
(
const
ValueKey
<
int
>(
11
)));
TestStatefulWidgetState
state12
=
tester
.
state
(
find
.
byKey
(
const
ValueKey
<
int
>(
12
)));
TestStatefulWidgetState
state21
=
tester
.
state
(
find
.
byKey
(
const
ValueKey
<
int
>(
21
)));
TestStatefulWidgetState
state22
=
tester
.
state
(
find
.
byKey
(
const
ValueKey
<
int
>(
22
)));
expect
(
state11
.
mounted
,
isTrue
);
expect
(
state12
.
mounted
,
isTrue
);
expect
(
state21
.
mounted
,
isTrue
);
expect
(
state22
.
mounted
,
isTrue
);
await
tester
.
pumpWidget
(
new
Table
(
children:
<
TableRow
>[
new
TableRow
(
key:
const
ValueKey
<
int
>(
2
),
children:
<
Widget
>[
new
TestStatefulWidget
(
key:
const
ValueKey
<
int
>(
21
)),
new
TestStatefulWidget
(
key:
const
ValueKey
<
int
>(
22
)),
],
),
]
)
);
expect
(
state11
.
mounted
,
isFalse
);
expect
(
state12
.
mounted
,
isFalse
);
expect
(
state21
.
mounted
,
isTrue
);
expect
(
state22
.
mounted
,
isTrue
);
});
testWidgets
(
'Table widget - global key reparenting'
,
(
WidgetTester
tester
)
async
{
GlobalKey
key
=
new
GlobalKey
();
Key
tableKey
=
new
UniqueKey
();
await
tester
.
pumpWidget
(
new
Column
(
children:
<
Widget
>
[
new
Expanded
(
key:
tableKey
,
child:
new
Table
(
children:
<
TableRow
>[
new
TableRow
(
children:
<
Widget
>[
new
Container
(
key:
const
ValueKey
<
int
>(
1
)),
new
TestStatefulWidget
(
key:
key
),
new
Container
(
key:
const
ValueKey
<
int
>(
2
)),
],
),
],
),
),
],
),
);
RenderTable
table
=
tester
.
renderObject
(
find
.
byType
(
Table
));
expect
(
table
.
row
(
0
).
length
,
3
);
await
tester
.
pumpWidget
(
new
Column
(
children:
<
Widget
>
[
new
Expanded
(
child:
new
TestStatefulWidget
(
key:
key
)),
new
Expanded
(
key:
tableKey
,
child:
new
Table
(
children:
<
TableRow
>[
new
TableRow
(
children:
<
Widget
>[
new
Container
(
key:
const
ValueKey
<
int
>(
1
)),
new
Container
(
key:
const
ValueKey
<
int
>(
2
)),
],
),
],
),
),
],
),
);
expect
(
tester
.
renderObject
(
find
.
byType
(
Table
)),
equals
(
table
));
expect
(
table
.
row
(
0
).
length
,
2
);
await
tester
.
pumpWidget
(
new
Column
(
children:
<
Widget
>
[
new
Expanded
(
key:
tableKey
,
child:
new
Table
(
children:
<
TableRow
>[
new
TableRow
(
children:
<
Widget
>[
new
Container
(
key:
const
ValueKey
<
int
>(
1
)),
new
TestStatefulWidget
(
key:
key
),
new
Container
(
key:
const
ValueKey
<
int
>(
2
)),
],
),
],
),
),
],
),
);
expect
(
tester
.
renderObject
(
find
.
byType
(
Table
)),
equals
(
table
));
expect
(
table
.
row
(
0
).
length
,
3
);
await
tester
.
pumpWidget
(
new
Column
(
children:
<
Widget
>
[
new
Expanded
(
key:
tableKey
,
child:
new
Table
(
children:
<
TableRow
>[
new
TableRow
(
children:
<
Widget
>[
new
Container
(
key:
const
ValueKey
<
int
>(
1
)),
new
Container
(
key:
const
ValueKey
<
int
>(
2
)),
],
),
],
),
),
new
Expanded
(
child:
new
TestStatefulWidget
(
key:
key
)),
],
),
);
expect
(
tester
.
renderObject
(
find
.
byType
(
Table
)),
equals
(
table
));
expect
(
table
.
row
(
0
).
length
,
2
);
});
// TODO(ianh): Test handling of TableCell object
}
packages/flutter/test/widgets/ticker_provider_test.dart
View file @
84cf5489
...
...
@@ -7,10 +7,13 @@ import 'package:flutter/material.dart';
void
main
(
)
{
testWidgets
(
'TickerMode'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
TickerMode
(
Widget
widget
=
new
TickerMode
(
enabled:
false
,
child:
new
LinearProgressIndicator
()
));
);
expect
(
widget
.
toString
,
isNot
(
throwsException
));
await
tester
.
pumpWidget
(
widget
);
expect
(
tester
.
binding
.
transientCallbackCount
,
0
);
...
...
@@ -52,7 +55,10 @@ void main() {
});
testWidgets
(
'SingleTickerProviderStateMixin can handle not being used'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
BoringTickerTest
());
Widget
widget
=
new
BoringTickerTest
();
expect
(
widget
.
toString
,
isNot
(
throwsException
));
await
tester
.
pumpWidget
(
widget
);
await
tester
.
pumpWidget
(
new
Container
());
// the test is that this doesn't crash, like it used to...
});
...
...
packages/flutter/test/widgets/title_test.dart
0 → 100644
View file @
84cf5489
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
void
main
(
)
{
testWidgets
(
'toString control test'
,
(
WidgetTester
tester
)
async
{
Widget
widget
=
new
Title
(
color:
const
Color
(
0xFF00FF00
),
title:
'Awesome app'
,
);
expect
(
widget
.
toString
,
isNot
(
throwsException
));
});
}
packages/flutter/test/widgets/transitions_test.dart
0 → 100644
View file @
84cf5489
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
void
main
(
)
{
testWidgets
(
'toString control test'
,
(
WidgetTester
tester
)
async
{
Widget
widget
=
new
FadeTransition
(
opacity:
kAlwaysCompleteAnimation
,
child:
new
Text
(
'Ready'
),
);
expect
(
widget
.
toString
,
isNot
(
throwsException
));
});
}
packages/flutter/test/widgets/unique_widget_test.dart
0 → 100644
View file @
84cf5489
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
class
TestUniqueWidget
extends
UniqueWidget
<
TestUniqueWidgetState
>
{
TestUniqueWidget
({
GlobalKey
key
})
:
super
(
key:
key
);
@override
TestUniqueWidgetState
createState
()
=>
new
TestUniqueWidgetState
();
}
class
TestUniqueWidgetState
extends
State
<
TestUniqueWidget
>
{
@override
Widget
build
(
BuildContext
context
)
=>
new
Container
();
}
void
main
(
)
{
testWidgets
(
'Unique widget control test'
,
(
WidgetTester
tester
)
async
{
TestUniqueWidget
widget
=
new
TestUniqueWidget
(
key:
new
GlobalKey
());
await
tester
.
pumpWidget
(
widget
);
TestUniqueWidgetState
state
=
widget
.
currentState
;
expect
(
state
,
isNotNull
);
await
tester
.
pumpWidget
(
new
Container
(
child:
widget
));
expect
(
widget
.
currentState
,
equals
(
state
));
});
}
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