Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paragon
Overview
Overview
Details
Activity
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
OpenEdx
paragon
Commits
213b4fae
Unverified
Commit
213b4fae
authored
Dec 08, 2017
by
Michael Roytman
Committed by
GitHub
Dec 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
fix(asinput): Remove control of state.value from asInput
fix(asinput): Remove control of state.value from asInput
parents
a18fd5d7
8391ed4f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
src/asInput/asInput.test.jsx
+17
-2
src/asInput/index.jsx
+8
-0
No files found.
src/asInput/asInput.test.jsx
View file @
213b4fae
...
...
@@ -41,7 +41,7 @@ describe('asInput()', () => {
const
wrapper
=
mount
(<
InputTestComponent
{
...
props
}
/>);
expect
(
wrapper
.
find
(
'label'
).
text
()).
toEqual
(
props
.
label
);
expect
(
wrapper
.
find
(
'#description-asInput1'
).
text
()).
toEqual
(
props
.
description
);
expect
(
wrapper
.
state
(
'value'
)).
toEqual
(
props
.
value
);
expect
(
wrapper
.
prop
(
'value'
)).
toEqual
(
props
.
value
);
});
it
(
'creates generic prop id'
,
()
=>
{
...
...
@@ -81,6 +81,21 @@ describe('asInput()', () => {
expect
(
wrapper
.
find
(
'small'
).
prop
(
'id'
)).
toEqual
(
`description-
${
testId
}
`
);
});
it
(
'overrides state value when props value changes'
,
()
=>
{
const
initValue
=
'foofoo'
;
const
newValue
=
'barbar'
;
const
props
=
{
...
baseProps
,
value
:
initValue
,
};
const
wrapper
=
mount
(<
InputTestComponent
{
...
props
}
/>);
expect
(
wrapper
.
state
(
'value'
)).
toEqual
(
initValue
);
wrapper
.
setProps
({
value
:
newValue
,
});
expect
(
wrapper
.
state
(
'value'
)).
toEqual
(
newValue
);
});
describe
(
'fires'
,
()
=>
{
it
(
'blur handler'
,
()
=>
{
const
spy
=
jest
.
fn
();
...
...
@@ -149,7 +164,7 @@ describe('asInput()', () => {
const
err
=
wrapper
.
find
(
'.form-control-feedback'
);
expect
(
err
.
exists
()).
toEqual
(
true
);
expect
(
err
.
text
()).
toEqual
(
validationResult
.
validationMessage
);
//
expect(err.hasClass('invalid-feedback')).toEqual(true);
expect
(
err
.
hasClass
(
'invalid-feedback'
)).
toEqual
(
true
);
const
dangerIcon
=
wrapper
.
find
(
'.fa-exclamation-circle'
);
expect
(
dangerIcon
.
exists
()).
toEqual
(
true
);
...
...
src/asInput/index.jsx
View file @
213b4fae
...
...
@@ -46,6 +46,14 @@ const asInput = (WrappedComponent, labelFirst = true) => {
};
}
componentWillReceiveProps
(
nextProps
)
{
if
(
nextProps
.
value
!==
this
.
props
.
value
)
{
this
.
setState
({
value
:
nextProps
.
value
,
});
}
}
getDescriptions
()
{
// possible future work: multiple feedback msgs?
const
errorId
=
`error-
${
this
.
state
.
id
}
`
;
...
...
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