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
4ad83fa0
Commit
4ad83fa0
authored
Sep 25, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port some more tests to fn3
parent
96b0801c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
96 deletions
+117
-96
widget_tester.dart
packages/unit/test/fn3/widget_tester.dart
+7
-0
syncing_test.dart
packages/unit/test/widget/syncing_test.dart
+104
-90
transform_test.dart
packages/unit/test/widget/transform_test.dart
+6
-6
No files found.
packages/unit/test/fn3/widget_tester.dart
View file @
4ad83fa0
...
...
@@ -86,6 +86,13 @@ class WidgetTester {
return
element
?.
state
;
}
State
findStateByConfig
(
Widget
config
)
{
StatefulComponentElement
element
=
findElement
((
Element
element
)
{
return
element
is
StatefulComponentElement
&&
element
.
state
.
config
==
config
;
});
return
element
?.
state
;
}
Point
getCenter
(
Element
element
)
{
return
_getElementPoint
(
element
,
(
Size
size
)
=>
size
.
center
(
Point
.
origin
));
}
...
...
packages/unit/test/widget/syncing_test.dart
View file @
4ad83fa0
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
class
TestState
extends
StatefulComponent
{
TestState
({
this
.
child
,
this
.
persistentState
,
this
.
syncedState
});
Widget
child
;
class
TestWidget
extends
StatefulComponent
{
TestWidget
({
this
.
child
,
this
.
persistentState
,
this
.
syncedState
});
final
Widget
child
;
final
int
persistentState
;
final
int
syncedState
;
TestWidgetState
createState
()
=>
new
TestWidgetState
();
}
class
TestWidgetState
extends
State
<
TestWidget
>
{
int
persistentState
;
int
syncedState
;
int
syncs
=
0
;
void
syncConstructorArguments
(
TestState
source
)
{
child
=
source
.
child
;
syncedState
=
source
.
syncedState
;
int
updates
=
0
;
void
initState
(
BuildContext
context
)
{
super
.
initState
(
context
);
persistentState
=
config
.
persistentState
;
syncedState
=
config
.
syncedState
;
}
void
didUpdateConfig
(
TestWidget
oldConfig
)
{
syncedState
=
config
.
syncedState
;
// we explicitly do NOT sync the persistentState from the new instance
// because we're using that to track whether we got recreated
syncs
+=
1
;
}
Widget
build
()
{
return
child
;
updates
+=
1
;
}
Widget
build
(
BuildContext
context
)
=>
config
.
child
;
}
void
main
(
)
{
test
(
'no change'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
()
{
return
new
Container
(
tester
.
pumpFrame
(
new
Container
(
child:
new
Container
(
child:
new
Test
State
(
child:
new
Test
Widget
(
persistentState:
1
,
child:
new
Container
()
)
)
)
;
}
);
)
);
Test
State
stateWidget
=
tester
.
findWidget
((
widget
)
=>
widget
is
Tes
tState
);
Test
WidgetState
state
=
tester
.
findStateOfType
(
TestWidge
tState
);
expect
(
state
Widget
.
persistentState
,
equals
(
1
));
expect
(
state
Widget
.
sync
s
,
equals
(
0
));
expect
(
state
.
persistentState
,
equals
(
1
));
expect
(
state
.
update
s
,
equals
(
0
));
tester
.
pumpFrame
(
()
{
return
new
Container
(
tester
.
pumpFrame
(
new
Container
(
child:
new
Container
(
child:
new
Test
State
(
child:
new
Test
Widget
(
persistentState:
2
,
child:
new
Container
()
)
)
)
;
}
);
)
);
expect
(
state
Widget
.
persistentState
,
equals
(
1
));
expect
(
state
Widget
.
sync
s
,
equals
(
1
));
expect
(
state
.
persistentState
,
equals
(
1
));
expect
(
state
.
update
s
,
equals
(
1
));
tester
.
pumpFrame
(
new
Container
());
});
test
(
'remove one'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(
()
{
return
new
Container
(
tester
.
pumpFrame
(
new
Container
(
child:
new
Container
(
child:
new
Test
State
(
child:
new
Test
Widget
(
persistentState:
10
,
child:
new
Container
()
)
)
)
;
}
);
)
);
Test
State
stateWidget
=
tester
.
findWidget
((
widget
)
=>
widget
is
Tes
tState
);
Test
WidgetState
state
=
tester
.
findStateOfType
(
TestWidge
tState
);
expect
(
state
Widget
.
persistentState
,
equals
(
10
));
expect
(
state
Widget
.
sync
s
,
equals
(
0
));
expect
(
state
.
persistentState
,
equals
(
10
));
expect
(
state
.
update
s
,
equals
(
0
));
tester
.
pumpFrame
(
()
{
return
new
Container
(
child:
new
Test
State
(
tester
.
pumpFrame
(
new
Container
(
child:
new
Test
Widget
(
persistentState:
11
,
child:
new
Container
()
)
);
});
)
);
state
=
tester
.
findStateOfType
(
TestWidgetState
);
expect
(
state
Widget
.
persistentState
,
equals
(
10
));
expect
(
state
Widget
.
syncs
,
equals
(
1
));
expect
(
state
.
persistentState
,
equals
(
11
));
expect
(
state
.
updates
,
equals
(
0
));
tester
.
pumpFrame
(
new
Container
());
});
test
(
'swap instances around'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
Widget
a
,
b
;
tester
.
pumpFrame
(()
{
a
=
new
TestState
(
persistentState:
0x61
,
syncedState:
0x41
,
child:
new
Text
(
'apple'
));
b
=
new
TestState
(
persistentState:
0x62
,
syncedState:
0x42
,
child:
new
Text
(
'banana'
));
return
new
Column
([]);
});
Widget
a
=
new
TestWidget
(
persistentState:
0x61
,
syncedState:
0x41
,
child:
new
Text
(
'apple'
));
Widget
b
=
new
TestWidget
(
persistentState:
0x62
,
syncedState:
0x42
,
child:
new
Text
(
'banana'
));
tester
.
pumpFrame
(
new
Column
([]));
GlobalKey
keyA
=
new
GlobalKey
();
GlobalKey
keyB
=
new
GlobalKey
();
TestState
foundA
,
foundB
;
tester
.
pumpFrame
(()
{
return
new
Column
([
tester
.
pumpFrame
(
new
Column
([
new
Container
(
key:
keyA
,
child:
a
...
...
@@ -118,21 +130,23 @@ void main() {
key:
keyB
,
child:
b
)
]);
});
])
);
TestWidgetState
first
,
second
;
f
oundA
=
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
keyA
)
as
Container
).
child
as
TestState
;
foundB
=
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
keyB
)
as
Container
).
child
as
TestState
;
f
irst
=
tester
.
findStateByConfig
(
a
)
;
second
=
tester
.
findStateByConfig
(
b
)
;
expect
(
f
oundA
,
equals
(
a
));
expect
(
f
oundA
.
persistentState
,
equals
(
0x61
));
expect
(
f
oundA
.
syncedState
,
equals
(
0x41
));
expect
(
foundB
,
equals
(
b
));
expect
(
foundB
.
persistentState
,
equals
(
0x62
));
expect
(
foundB
.
syncedState
,
equals
(
0x42
));
expect
(
f
irst
.
config
,
equals
(
a
));
expect
(
f
irst
.
persistentState
,
equals
(
0x61
));
expect
(
f
irst
.
syncedState
,
equals
(
0x41
));
expect
(
second
.
config
,
equals
(
b
));
expect
(
second
.
persistentState
,
equals
(
0x62
));
expect
(
second
.
syncedState
,
equals
(
0x42
));
tester
.
pumpFrame
(
()
{
return
new
Column
([
tester
.
pumpFrame
(
new
Column
([
new
Container
(
key:
keyA
,
child:
a
...
...
@@ -141,25 +155,25 @@ void main() {
key:
keyB
,
child:
b
)
])
;
}
);
])
);
f
oundA
=
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
keyA
)
as
Container
).
child
as
TestState
;
foundB
=
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
keyB
)
as
Container
).
child
as
TestState
;
f
irst
=
tester
.
findStateByConfig
(
a
)
;
second
=
tester
.
findStateByConfig
(
b
)
;
// same as before
expect
(
f
oundA
,
equals
(
a
));
expect
(
f
oundA
.
persistentState
,
equals
(
0x61
));
expect
(
f
oundA
.
syncedState
,
equals
(
0x41
));
expect
(
foundB
,
equals
(
b
));
expect
(
foundB
.
persistentState
,
equals
(
0x62
));
expect
(
foundB
.
syncedState
,
equals
(
0x42
));
expect
(
f
irst
.
config
,
equals
(
a
));
expect
(
f
irst
.
persistentState
,
equals
(
0x61
));
expect
(
f
irst
.
syncedState
,
equals
(
0x41
));
expect
(
second
.
config
,
equals
(
b
));
expect
(
second
.
persistentState
,
equals
(
0x62
));
expect
(
second
.
syncedState
,
equals
(
0x42
));
// now we swap the nodes over
// since they are both "old" nodes, they shouldn't sync with each other even though they look alike
tester
.
pumpFrame
(
()
{
return
new
Column
([
tester
.
pumpFrame
(
new
Column
([
new
Container
(
key:
keyA
,
child:
b
...
...
@@ -168,18 +182,18 @@ void main() {
key:
keyB
,
child:
a
)
])
;
}
);
f
oundA
=
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
keyA
)
as
Container
).
child
as
TestState
;
foundB
=
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
keyB
)
as
Container
).
child
as
TestState
;
expect
(
f
oundA
,
equals
(
b
));
expect
(
f
oundA
.
persistentState
,
equals
(
0x62
));
expect
(
f
oundA
.
syncedState
,
equals
(
0x42
));
expect
(
foundB
,
equals
(
a
));
expect
(
foundB
.
persistentState
,
equals
(
0x61
));
expect
(
foundB
.
syncedState
,
equals
(
0x41
));
])
);
f
irst
=
tester
.
findStateByConfig
(
b
)
;
second
=
tester
.
findStateByConfig
(
a
)
;
expect
(
f
irst
.
config
,
equals
(
b
));
expect
(
f
irst
.
persistentState
,
equals
(
0x61
));
expect
(
f
irst
.
syncedState
,
equals
(
0x42
));
expect
(
second
.
config
,
equals
(
a
));
expect
(
second
.
persistentState
,
equals
(
0x62
));
expect
(
second
.
syncedState
,
equals
(
0x41
));
});
...
...
packages/unit/test/widget/transform_test.dart
View file @
4ad83fa0
import
'package:sky/
widgets
.dart'
;
import
'package:sky/
src/fn3
.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
import
'
../fn3/
widget_tester.dart'
;
void
main
(
)
{
test
(
'Transform origin'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
bool
didReceiveTap
=
false
;
tester
.
pumpFrame
(
()
{
return
new
Stack
([
tester
.
pumpFrame
(
new
Stack
([
new
Positioned
(
top:
100.0
,
left:
100.0
,
...
...
@@ -39,8 +39,8 @@ void main() {
)
)
)
])
;
}
);
])
);
expect
(
didReceiveTap
,
isFalse
);
tester
.
tapAt
(
new
Point
(
110.0
,
110.0
));
...
...
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