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
9f5eeb1b
Commit
9f5eeb1b
authored
Sep 21, 2016
by
Lex Berezhny
Committed by
Adam Barth
Sep 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unittest to check Input box initial value (#5976)
Adds unit test to verify the initial value of Input widgets.
parent
49e59231
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
13 deletions
+52
-13
AUTHORS
AUTHORS
+1
-0
form_test.dart
packages/flutter/test/widget/form_test.dart
+51
-13
No files found.
AUTHORS
View file @
9f5eeb1b
...
...
@@ -5,3 +5,4 @@
Google Inc.
Jim Simon <jim.j.simon@gmail.com>
Lex Berezhny <lex@damoti.com>
packages/flutter/test/widget/form_test.dart
View file @
9f5eeb1b
...
...
@@ -10,6 +10,7 @@ class MockKeyboard extends mojom.KeyboardProxy {
MockKeyboard
()
:
super
.
unbound
();
mojom
.
KeyboardClient
client
;
mojom
.
EditingState
currentState
;
@override
void
setClient
(
mojom
.
KeyboardClientStub
client
,
mojom
.
KeyboardConfiguration
configuraiton
)
{
...
...
@@ -23,7 +24,10 @@ class MockKeyboard extends mojom.KeyboardProxy {
void
hide
()
{}
@override
void
setEditingState
(
mojom
.
EditingState
state
)
{}
void
setEditingState
(
mojom
.
EditingState
state
)
{
currentState
=
state
;
}
}
void
main
(
)
{
...
...
@@ -43,7 +47,6 @@ void main() {
}
testWidgets
(
'Setter callback is called'
,
(
WidgetTester
tester
)
async
{
GlobalKey
inputKey
=
new
GlobalKey
();
String
fieldValue
;
Widget
builder
()
{
...
...
@@ -51,9 +54,8 @@ void main() {
child:
new
Material
(
child:
new
Form
(
child:
new
Input
(
key:
inputKey
,
formField:
new
FormField
<
String
>(
setter:
(
String
val
)
{
fieldValue
=
val
;
}
setter:
(
String
val
ue
)
{
fieldValue
=
value
;
}
)
)
)
...
...
@@ -63,12 +65,12 @@ void main() {
await
tester
.
pumpWidget
(
builder
());
Future
<
Null
>
checkText
(
String
testValue
)
{
enterText
(
testValue
);
expect
(
fieldValue
,
isNull
);
// Check that the FormField's setter was called.
Future
<
Null
>
checkText
(
String
testValue
)
async
{
enterText
(
testValue
);
// pump'ing is unnecessary because callback happens regardless of frames
expect
(
fieldValue
,
equals
(
testValue
));
return
tester
.
pumpWidget
(
builder
());
}
await
checkText
(
'Test'
);
...
...
@@ -98,11 +100,9 @@ void main() {
Future
<
Null
>
checkErrorText
(
String
testValue
)
async
{
enterText
(
testValue
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pump
();
// Check for a new Text widget with our error text.
expect
(
find
.
text
(
errorText
(
testValue
)),
findsOneWidget
);
return
null
;
}
await
checkErrorText
(
'Test'
);
...
...
@@ -128,7 +128,7 @@ void main() {
new
Input
(
key:
inputKey
,
formField:
new
FormField
<
String
>(
setter:
(
String
val
)
{
fieldValue
=
val
;
}
setter:
(
String
val
ue
)
{
fieldValue
=
value
;
}
)
),
new
Input
(
...
...
@@ -150,7 +150,7 @@ void main() {
Future
<
Null
>
checkErrorText
(
String
testValue
)
async
{
enterText
(
testValue
);
await
tester
.
pump
Widget
(
builder
()
);
await
tester
.
pump
(
);
expect
(
fieldValue
,
equals
(
testValue
));
...
...
@@ -162,4 +162,42 @@ void main() {
await
checkErrorText
(
'Test'
);
await
checkErrorText
(
''
);
});
testWidgets
(
'Provide initial value to input'
,
(
WidgetTester
tester
)
async
{
String
initialValue
=
'hello'
;
String
currentValue
;
Widget
builder
()
{
return
new
Center
(
child:
new
Material
(
child:
new
Form
(
child:
new
Input
(
value:
new
InputValue
(
text:
initialValue
),
formField:
new
FormField
<
String
>(
setter:
(
String
value
)
{
currentValue
=
value
;
}
)
)
)
)
);
}
await
tester
.
pumpWidget
(
builder
());
// initial value should be loaded into keyboard editing state
expect
(
mockKeyboard
.
currentState
,
isNotNull
);
expect
(
mockKeyboard
.
currentState
.
text
,
equals
(
initialValue
));
// initial value should also be visible in the raw input line
RawInputLineState
editableText
=
tester
.
state
(
find
.
byType
(
RawInputLine
));
expect
(
editableText
.
config
.
value
.
text
,
equals
(
initialValue
));
// sanity check, make sure we can still edit the text and everything updates
expect
(
currentValue
,
isNull
);
enterText
(
'world'
);
expect
(
currentValue
,
equals
(
'world'
));
await
tester
.
pump
();
expect
(
editableText
.
config
.
value
.
text
,
equals
(
'world'
));
});
}
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