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
4b59f66e
Commit
4b59f66e
authored
Jul 03, 2017
by
Ari Rizzitano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more dropdown tests
parent
5e8bc736
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
34 deletions
+47
-34
.eslintrc.json
+6
-0
src/Dropdown/Dropdown.test.jsx
+39
-32
src/Dropdown/index.jsx
+2
-2
No files found.
.eslintrc.json
View file @
4b59f66e
...
@@ -13,5 +13,11 @@
...
@@ -13,5 +13,11 @@
},
},
"env"
:
{
"env"
:
{
"jest"
:
true
"jest"
:
true
},
"overrides"
:
{
"files"
:
[
"*.stories.jsx"
,
"*.test.jsx"
],
"rules"
:
{
"import/no-extraneous-dependencies"
:
"off"
//
storybook
&
enzyme
should
stay
devDependencies
}
}
}
}
}
src/Dropdown/Dropdown.test.jsx
View file @
4b59f66e
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-extraneous-dependencies */
import
React
from
'react'
;
import
React
from
'react'
;
import
{
shallow
}
from
'enzyme'
;
import
{
shallow
,
mount
}
from
'enzyme'
;
import
Dropdown
from
'./index'
;
import
Dropdown
,
{
triggerKeys
}
from
'./index'
;
const
props
=
{
const
props
=
{
title
:
'Example'
,
title
:
'Example'
,
...
@@ -12,48 +12,55 @@ const props = {
...
@@ -12,48 +12,55 @@ const props = {
],
],
};
};
const
menuOpen
=
(
isOpen
,
wrapper
)
=>
{
expect
(
wrapper
.
hasClass
(
'show'
)).
toEqual
(
isOpen
);
expect
(
wrapper
.
find
(
'[type="button"]'
).
prop
(
'aria-expanded'
)).
toEqual
(
isOpen
);
expect
(
wrapper
.
find
(
'[aria-hidden=false]'
).
exists
()).
toEqual
(
isOpen
);
};
describe
(
'<Dropdown />'
,
()
=>
{
describe
(
'<Dropdown />'
,
()
=>
{
it
(
'renders correctly
'
,
()
=>
{
describe
(
'renders
'
,
()
=>
{
const
wrapper
=
shallow
(
const
wrapper
=
shallow
(
<
Dropdown
<
Dropdown
{
...
props
}
{
...
props
}
/>,
/>,
);
);
const
menu
=
wrapper
.
find
(
'ul'
);
const
menu
=
wrapper
.
find
(
'ul'
);
const
button
=
wrapper
.
find
(
'[type="button"]'
);
const
button
=
wrapper
.
find
(
'[type="button"]'
);
expect
(
button
.
exists
()).
toEqual
(
true
);
it
(
'with menu and toggle'
,
()
=>
{
expect
(
button
.
prop
(
'aria-expanded'
)).
toEqual
(
false
);
expect
(
button
.
exists
()).
toEqual
(
true
);
expect
(
menu
.
prop
(
'aria-label'
)).
toEqual
(
props
.
title
);
expect
(
menu
.
exists
()).
toEqual
(
true
);
expect
(
menu
.
exists
()).
toEqual
(
true
);
expect
(
menu
.
find
(
'li'
)).
toHaveLength
(
2
);
expect
(
menu
.
find
(
'li'
)).
toHaveLength
(
2
);
expect
(
menu
.
prop
(
'aria-label'
)).
toEqual
(
props
.
title
);
});
expect
(
menu
.
prop
(
'aria-hidden'
)).
toEqual
(
true
);
});
it
(
'renders correctly'
,
()
=>
{
const
wrapper
=
shallow
(
<
Dropdown
{
...
props
}
/>,
);
expect
(
wrapper
.
find
(
'[type="button"]'
).
exists
()).
toEqual
(
true
);
it
(
'with menu closed'
,
()
=>
{
expect
(
wrapper
.
find
(
'li'
)).
toHaveLength
(
2
);
menuOpen
(
false
,
wrapper
);
expect
(
wrapper
.
find
(
'[aria-expanded=false]'
).
exists
()).
toEqual
(
true
);
}
);
});
});
it
(
'opens on click'
,
()
=>
{
describe
(
'opens'
,
()
=>
{
const
wrapper
=
shallow
(
it
(
'on click'
,
()
=>
{
<
Dropdown
const
wrapper
=
mount
(
{
...
props
}
<
Dropdown
/>,
{
...
props
}
);
/>,
);
const
button
=
wrapper
.
find
(
'[type="button"]'
);
wrapper
.
find
(
'[type="button"]'
).
simulate
(
'click'
);
menuOpen
(
true
,
wrapper
);
});
button
.
simulate
(
'click'
);
triggerKeys
.
OPEN_MENU
.
forEach
((
key
)
=>
{
expect
(
wrapper
.
find
(
'[aria-hidden=false]'
).
exists
()).
toEqual
(
true
);
it
(
`on
${
key
}
`
,
()
=>
{
const
wrapper
=
mount
(
<
Dropdown
{
...
props
}
/>,
);
wrapper
.
find
(
'[type="button"]'
).
simulate
(
'keyDown'
,
{
key
});
menuOpen
(
true
,
wrapper
);
});
});
});
});
});
});
src/Dropdown/index.jsx
View file @
4b59f66e
...
@@ -7,7 +7,7 @@ import borders from 'bootstrap/scss/utilities/_borders.scss';
...
@@ -7,7 +7,7 @@ import borders from 'bootstrap/scss/utilities/_borders.scss';
import
pc
from
'../utils/base-styles.scss'
;
import
pc
from
'../utils/base-styles.scss'
;
import
Button
from
'../Button'
;
import
Button
from
'../Button'
;
const
triggerKeys
=
{
export
const
triggerKeys
=
{
OPEN_MENU
:
[
'ArrowDown'
,
'Space'
],
OPEN_MENU
:
[
'ArrowDown'
,
'Space'
],
CLOSE_MENU
:
[
'Escape'
],
CLOSE_MENU
:
[
'Escape'
],
NAVIGATE_DOWN
:
[
'ArrowDown'
,
'Tab'
],
NAVIGATE_DOWN
:
[
'ArrowDown'
,
'Tab'
],
...
@@ -45,7 +45,7 @@ class Dropdown extends React.Component {
...
@@ -45,7 +45,7 @@ class Dropdown extends React.Component {
}
}
componentDidUpdate
()
{
componentDidUpdate
()
{
if
(
this
.
state
.
open
&&
this
.
menuItems
.
length
>
0
)
{
if
(
this
.
state
.
open
)
{
this
.
menuItems
[
this
.
state
.
focusIndex
].
focus
();
this
.
menuItems
[
this
.
state
.
focusIndex
].
focus
();
}
else
if
(
this
.
toggleElem
)
{
}
else
if
(
this
.
toggleElem
)
{
this
.
toggleElem
.
focus
();
this
.
toggleElem
.
focus
();
...
...
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