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
25ab5286
Commit
25ab5286
authored
Jul 05, 2017
by
Ari Rizzitano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asInput reorg + coverage, simplify checkbox, regenerate snapshots
parent
4de27183
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
125 additions
and
22 deletions
+125
-22
.storybook/__snapshots__/Storyshots.test.js.snap
+14
-14
src/CheckBox/CheckBox.test.jsx
+2
-3
src/CheckBox/index.jsx
+1
-1
src/InputSelect/index.jsx
+1
-1
src/InputText/index.jsx
+1
-1
src/asInput/asInput.test.jsx
+104
-0
src/asInput/index.jsx
+2
-2
yarn.lock
+0
-0
No files found.
.storybook/__snapshots__/Storyshots.test.js.snap
View file @
25ab5286
...
@@ -142,14 +142,14 @@ exports[`Storyshots InputSelect basic usage 1`] = `
...
@@ -142,14 +142,14 @@ exports[`Storyshots InputSelect basic usage 1`] = `
className="form-group"
className="form-group"
>
>
<label
<label
htmlFor="
text
Input5"
htmlFor="
as
Input5"
>
>
Fruits
Fruits
</label>
</label>
<select
<select
aria-describedby={undefined}
aria-describedby={undefined}
className="form-control"
className="form-control"
id="
text
Input5"
id="
as
Input5"
name="fruits"
name="fruits"
onBlur={[Function]}
onBlur={[Function]}
onChange={[Function]}
onChange={[Function]}
...
@@ -184,14 +184,14 @@ exports[`Storyshots InputSelect separate labels and values 1`] = `
...
@@ -184,14 +184,14 @@ exports[`Storyshots InputSelect separate labels and values 1`] = `
className="form-group"
className="form-group"
>
>
<label
<label
htmlFor="
text
Input6"
htmlFor="
as
Input6"
>
>
New England States
New England States
</label>
</label>
<select
<select
aria-describedby={undefined}
aria-describedby={undefined}
className="form-control"
className="form-control"
id="
text
Input6"
id="
as
Input6"
name="new-england-states"
name="new-england-states"
onBlur={[Function]}
onBlur={[Function]}
onChange={[Function]}
onChange={[Function]}
...
@@ -236,14 +236,14 @@ exports[`Storyshots InputSelect separate option groups 1`] = `
...
@@ -236,14 +236,14 @@ exports[`Storyshots InputSelect separate option groups 1`] = `
className="form-group"
className="form-group"
>
>
<label
<label
htmlFor="
text
Input7"
htmlFor="
as
Input7"
>
>
Northeast States
Northeast States
</label>
</label>
<select
<select
aria-describedby={undefined}
aria-describedby={undefined}
className="form-control"
className="form-control"
id="
text
Input7"
id="
as
Input7"
name="northeast-states"
name="northeast-states"
onBlur={[Function]}
onBlur={[Function]}
onChange={[Function]}
onChange={[Function]}
...
@@ -336,14 +336,14 @@ exports[`Storyshots InputSelect with validation 1`] = `
...
@@ -336,14 +336,14 @@ exports[`Storyshots InputSelect with validation 1`] = `
className="form-group"
className="form-group"
>
>
<label
<label
htmlFor="
text
Input8"
htmlFor="
as
Input8"
>
>
Favorite Color
Favorite Color
</label>
</label>
<select
<select
aria-describedby={undefined}
aria-describedby={undefined}
className="form-control"
className="form-control"
id="
text
Input8"
id="
as
Input8"
name="color"
name="color"
onBlur={[Function]}
onBlur={[Function]}
onChange={[Function]}
onChange={[Function]}
...
@@ -393,7 +393,7 @@ exports[`Storyshots InputText minimal usage 1`] = `
...
@@ -393,7 +393,7 @@ exports[`Storyshots InputText minimal usage 1`] = `
className="form-group"
className="form-group"
>
>
<label
<label
htmlFor="
text
Input9"
htmlFor="
as
Input9"
>
>
First Name
First Name
</label>
</label>
...
@@ -402,7 +402,7 @@ exports[`Storyshots InputText minimal usage 1`] = `
...
@@ -402,7 +402,7 @@ exports[`Storyshots InputText minimal usage 1`] = `
aria-invalid={false}
aria-invalid={false}
className="form-control"
className="form-control"
disabled={false}
disabled={false}
id="
text
Input9"
id="
as
Input9"
name="name"
name="name"
onBlur={[Function]}
onBlur={[Function]}
onChange={[Function]}
onChange={[Function]}
...
@@ -419,16 +419,16 @@ exports[`Storyshots InputText validation 1`] = `
...
@@ -419,16 +419,16 @@ exports[`Storyshots InputText validation 1`] = `
className="form-group"
className="form-group"
>
>
<label
<label
htmlFor="
text
Input10"
htmlFor="
as
Input10"
>
>
Username
Username
</label>
</label>
<input
<input
aria-describedby="undefined description-
text
Input10"
aria-describedby="undefined description-
as
Input10"
aria-invalid={false}
aria-invalid={false}
className="form-control"
className="form-control"
disabled={false}
disabled={false}
id="
text
Input10"
id="
as
Input10"
name="username"
name="username"
onBlur={[Function]}
onBlur={[Function]}
onChange={[Function]}
onChange={[Function]}
...
@@ -439,7 +439,7 @@ exports[`Storyshots InputText validation 1`] = `
...
@@ -439,7 +439,7 @@ exports[`Storyshots InputText validation 1`] = `
/>
/>
<small
<small
className="form-text"
className="form-text"
id="description-
text
Input10"
id="description-
as
Input10"
>
>
The unique name that identifies you throughout the site.
The unique name that identifies you throughout the site.
</small>
</small>
...
...
src/CheckBox/CheckBox.test.jsx
View file @
25ab5286
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */
import
React
from
'react'
;
import
React
from
'react'
;
import
{
shallow
,
mount
}
from
'enzyme'
;
import
{
shallow
,
mount
}
from
'enzyme'
;
import
CheckBox
from
'./index'
;
import
CheckBox
from
'./index'
;
...
@@ -45,16 +44,16 @@ describe('<CheckBox />', () => {
...
@@ -45,16 +44,16 @@ describe('<CheckBox />', () => {
});
});
it
(
'check that callback function is triggered when clicked'
,
()
=>
{
it
(
'check that callback function is triggered when clicked'
,
()
=>
{
const
spy
=
jest
.
fn
();
const
wrapper
=
shallow
(
const
wrapper
=
shallow
(
<
CheckBox
<
CheckBox
name=
"checkbox"
name=
"checkbox"
descibedBy=
"checkbox"
descibedBy=
"checkbox"
label=
"check me out!"
label=
"check me out!"
checked=
"false"
checked=
"false"
onChange=
{
()
=>
console
.
log
(
'the checkbox changed state'
)
}
onChange=
{
spy
}
/>,
/>,
);
);
const
spy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'onChange'
);
expect
(
spy
).
toHaveBeenCalledTimes
(
0
);
expect
(
spy
).
toHaveBeenCalledTimes
(
0
);
wrapper
.
find
(
'input'
).
simulate
(
'click'
);
wrapper
.
find
(
'input'
).
simulate
(
'click'
);
...
...
src/CheckBox/index.jsx
View file @
25ab5286
import
React
from
'react'
;
import
React
from
'react'
;
import
{
inputProps
}
from
'../
utils/
asInput'
;
import
{
inputProps
}
from
'../asInput'
;
import
newId
from
'../utils/newId'
;
import
newId
from
'../utils/newId'
;
class
CheckBox
extends
React
.
Component
{
class
CheckBox
extends
React
.
Component
{
...
...
src/InputSelect/index.jsx
View file @
25ab5286
...
@@ -2,7 +2,7 @@ import React from 'react';
...
@@ -2,7 +2,7 @@ import React from 'react';
import
{
Input
}
from
'reactstrap'
;
import
{
Input
}
from
'reactstrap'
;
import
PropTypes
from
'prop-types'
;
import
PropTypes
from
'prop-types'
;
import
asInput
,
{
inputProps
}
from
'../
utils/
asInput'
;
import
asInput
,
{
inputProps
}
from
'../asInput'
;
class
Select
extends
React
.
Component
{
class
Select
extends
React
.
Component
{
static
getOption
(
option
,
i
)
{
static
getOption
(
option
,
i
)
{
...
...
src/InputText/index.jsx
View file @
25ab5286
import
React
from
'react'
;
import
React
from
'react'
;
import
{
Input
}
from
'reactstrap'
;
import
{
Input
}
from
'reactstrap'
;
import
asInput
,
{
inputProps
}
from
'../
utils/
asInput'
;
import
asInput
,
{
inputProps
}
from
'../asInput'
;
function
Text
(
props
)
{
function
Text
(
props
)
{
return
(
return
(
...
...
src/asInput/asInput.test.jsx
0 → 100644
View file @
25ab5286
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable react/prop-types */
import
React
from
'react'
;
import
{
mount
}
from
'enzyme'
;
import
asInput
from
'./index'
;
function
testComponent
(
props
)
{
return
(
<
input
defaultValue=
{
props
.
value
}
onBlur=
{
props
.
onBlur
}
onChange=
{
props
.
onChange
}
/>
);
}
const
InputTestComponent
=
asInput
(
testComponent
);
const
baseProps
=
{
type
:
'text'
,
name
:
'test'
,
label
:
'test component'
,
description
:
'i am a test component'
,
};
describe
(
'asInput()'
,
()
=>
{
it
(
'renders'
,
()
=>
{
const
props
=
{
...
baseProps
,
value
:
'foofoo'
,
};
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
);
});
describe
(
'fires'
,
()
=>
{
it
(
'blur handler'
,
()
=>
{
const
spy
=
jest
.
fn
();
const
props
=
{
...
baseProps
,
onBlur
:
spy
,
};
const
wrapper
=
mount
(
<
InputTestComponent
{
...
props
}
/>,
);
wrapper
.
find
(
'input'
).
simulate
(
'blur'
);
expect
(
spy
).
toHaveBeenCalledTimes
(
1
);
});
it
(
'change handler'
,
()
=>
{
const
spy
=
jest
.
fn
();
const
props
=
{
...
baseProps
,
onChange
:
spy
,
};
const
wrapper
=
mount
(
<
InputTestComponent
{
...
props
}
/>,
);
wrapper
.
find
(
'input'
).
simulate
(
'change'
);
expect
(
spy
).
toHaveBeenCalledTimes
(
1
);
});
describe
(
'validator'
,
()
=>
{
it
(
'on blur'
,
()
=>
{
const
spy
=
jest
.
fn
();
spy
.
mockReturnValueOnce
({
isValid
:
true
});
const
props
=
{
...
baseProps
,
validator
:
spy
,
};
const
wrapper
=
mount
(
<
InputTestComponent
{
...
props
}
/>,
);
wrapper
.
find
(
'input'
).
simulate
(
'blur'
);
expect
(
spy
).
toHaveBeenCalledTimes
(
1
);
});
it
(
'and displays error message when invalid'
,
()
=>
{
const
spy
=
jest
.
fn
();
const
validationResult
=
{
isValid
:
false
,
validationMessage
:
'Invalid!!1'
,
};
spy
.
mockReturnValueOnce
(
validationResult
);
const
props
=
{
...
baseProps
,
validator
:
spy
,
};
const
wrapper
=
mount
(
<
InputTestComponent
{
...
props
}
/>,
);
wrapper
.
find
(
'input'
).
simulate
(
'blur'
);
expect
(
spy
).
toHaveBeenCalledTimes
(
1
);
const
err
=
wrapper
.
find
(
'.form-control-feedback'
);
expect
(
err
.
exists
()).
toEqual
(
true
);
expect
(
err
.
text
()).
toEqual
(
validationResult
.
validationMessage
);
});
});
});
});
src/
utils/asInput
.jsx
→
src/
asInput/index
.jsx
View file @
25ab5286
...
@@ -3,7 +3,7 @@ import React from 'react';
...
@@ -3,7 +3,7 @@ import React from 'react';
import
PropTypes
from
'prop-types'
;
import
PropTypes
from
'prop-types'
;
import
{
FormGroup
,
FormFeedback
,
FormText
}
from
'reactstrap'
;
import
{
FormGroup
,
FormFeedback
,
FormText
}
from
'reactstrap'
;
import
newId
from
'./newId'
;
import
newId
from
'.
./utils
/newId'
;
const
getDisplayName
=
WrappedComponent
=>
WrappedComponent
.
displayName
||
WrappedComponent
.
name
||
'Component'
;
const
getDisplayName
=
WrappedComponent
=>
WrappedComponent
.
displayName
||
WrappedComponent
.
name
||
'Component'
;
...
@@ -29,7 +29,7 @@ const asInput = (WrappedComponent) => {
...
@@ -29,7 +29,7 @@ const asInput = (WrappedComponent) => {
this
.
handleChange
=
this
.
handleChange
.
bind
(
this
);
this
.
handleChange
=
this
.
handleChange
.
bind
(
this
);
this
.
handleBlur
=
this
.
handleBlur
.
bind
(
this
);
this
.
handleBlur
=
this
.
handleBlur
.
bind
(
this
);
const
id
=
newId
(
'
text
Input'
);
const
id
=
newId
(
'
as
Input'
);
this
.
state
=
{
this
.
state
=
{
id
,
id
,
value
:
this
.
props
.
value
,
value
:
this
.
props
.
value
,
...
...
yarn.lock
View file @
25ab5286
This diff is collapsed.
Click to expand it.
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