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
44e66936
Commit
44e66936
authored
Jun 21, 2017
by
Sarah Fischmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrote several tests for checkbox; made some small edits in component
parent
a5b7a4fb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
7 deletions
+17
-7
.eslintrc.json
+3
-0
__tests__/checkbox-test.jsx
+5
-4
src/CheckBox.jsx
+7
-2
stories/index.jsx
+2
-1
No files found.
.eslintrc.json
View file @
44e66936
...
@@ -7,5 +7,8 @@
...
@@ -7,5 +7,8 @@
},
},
"settings"
:
{
"settings"
:
{
"import/resolver"
:
"webpack"
"import/resolver"
:
"webpack"
},
"env"
:
{
"jest"
:
true
}
}
}
}
__tests__/checkbox-test.jsx
View file @
44e66936
/* 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
'../src/CheckBox'
;
import
CheckBox
from
'../src/CheckBox'
;
...
@@ -10,8 +11,8 @@ describe('<CheckBox />', () => {
...
@@ -10,8 +11,8 @@ describe('<CheckBox />', () => {
describedBy=
"this is a checkbox"
describedBy=
"this is a checkbox"
label=
"check me out!"
label=
"check me out!"
checked=
"false"
checked=
"false"
/>
/>
,
)
);
expect
(
wrapper
.
find
(
'[name="checkbox"]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[name="checkbox"]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[type="checkbox"]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[type="checkbox"]'
).
exists
()).
toEqual
(
true
);
...
@@ -42,7 +43,7 @@ describe('<CheckBox />', () => {
...
@@ -42,7 +43,7 @@ describe('<CheckBox />', () => {
expect
(
wrapper
.
find
(
'[aria-checked=true]'
).
exists
()).
toEqual
(
false
);
expect
(
wrapper
.
find
(
'[aria-checked=true]'
).
exists
()).
toEqual
(
false
);
});
});
it
(
'check that callback function is triggered when clicked'
,
()
=>
{
it
(
'check that callback function is triggered when clicked'
,
()
=>
{
const
wrapper
=
shallow
(
const
wrapper
=
shallow
(
<
CheckBox
<
CheckBox
name=
"checkbox"
name=
"checkbox"
...
@@ -84,7 +85,7 @@ describe('<CheckBox />', () => {
...
@@ -84,7 +85,7 @@ describe('<CheckBox />', () => {
describedBy=
"checkbox"
describedBy=
"checkbox"
label=
"I am disabled"
label=
"I am disabled"
checked=
"false"
checked=
"false"
disabled
=
{
true
}
disabled
/>,
/>,
);
);
...
...
src/CheckBox.jsx
View file @
44e66936
import
React
from
'react'
;
import
React
from
'react'
;
import
{
inputProps
}
from
'./utils/asInput'
;
import
{
inputProps
}
from
'./utils/asInput'
;
import
newId
from
'./utils/newId'
;
class
CheckBox
extends
React
.
Component
{
class
CheckBox
extends
React
.
Component
{
...
@@ -12,12 +13,15 @@ class CheckBox extends React.Component {
...
@@ -12,12 +13,15 @@ class CheckBox extends React.Component {
this
.
onChange
=
this
.
props
.
onChange
.
bind
(
this
);
this
.
onChange
=
this
.
props
.
onChange
.
bind
(
this
);
}
}
const
id
=
newId
(
'checkbox'
);
if
(
props
.
checked
===
'true'
)
{
if
(
props
.
checked
===
'true'
)
{
this
.
state
=
{
this
.
state
=
{
id
,
checked
:
true
,
checked
:
true
,
};
};
}
else
{
}
else
{
this
.
state
=
{
this
.
state
=
{
id
,
checked
:
false
,
checked
:
false
,
};
};
}
}
...
@@ -33,7 +37,7 @@ class CheckBox extends React.Component {
...
@@ -33,7 +37,7 @@ class CheckBox extends React.Component {
checked
:
true
,
checked
:
true
,
});
});
}
}
if
(
this
.
onChange
)
{
if
(
this
.
onChange
)
{
this
.
onChange
();
this
.
onChange
();
}
}
}
}
...
@@ -43,8 +47,9 @@ class CheckBox extends React.Component {
...
@@ -43,8 +47,9 @@ class CheckBox extends React.Component {
const
props
=
{
...
this
.
props
};
const
props
=
{
...
this
.
props
};
return
(
return
(
<
label
>
<
label
htmlFor=
{
this
.
state
.
id
}
>
<
input
<
input
id=
{
this
.
state
.
id
}
name=
{
props
.
name
}
name=
{
props
.
name
}
type=
"checkbox"
type=
"checkbox"
defaultChecked=
{
this
.
state
.
checked
}
defaultChecked=
{
this
.
state
.
checked
}
...
...
stories/index.jsx
View file @
44e66936
/* 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
{
storiesOf
,
linkTo
}
from
'@kadira/storybook'
;
import
{
storiesOf
,
linkTo
}
from
'@kadira/storybook'
;
...
@@ -141,7 +142,7 @@ storiesOf('CheckBox', module)
...
@@ -141,7 +142,7 @@ storiesOf('CheckBox', module)
describedBy=
"checkbox"
describedBy=
"checkbox"
label=
"you cannot check me out"
label=
"you cannot check me out"
checked=
"false"
checked=
"false"
disabled
=
"true"
disabled
/>
/>
))
))
.
add
(
'default checked'
,
()
=>
(
.
add
(
'default checked'
,
()
=>
(
...
...
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