Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
f6d34711
Commit
f6d34711
authored
Oct 08, 2015
by
clrux
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10086 from edx/clrux/ac-76-test-cleanup
Fixing JS tests for the accordion navigation
parents
c580d4db
a631a662
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
29 deletions
+29
-29
lms/static/js/fixtures/accordion.html
+4
-4
lms/static/js/spec/navigation_spec.js
+25
-25
No files found.
lms/static/js/fixtures/accordion.html
View file @
f6d34711
<div
class=
"course-wrapper"
>
<div
class=
"course-wrapper"
>
<div
class=
"accordion"
>
<div
class=
"accordion"
>
<a
href=
"accordion-menu-1"
role=
"button"
class=
"button-chapter chapter"
aria-controls=
"accordion-menu-1"
>
<a
href=
"accordion-menu-1"
role=
"button"
class=
"button-chapter chapter
is-open
"
aria-controls=
"accordion-menu-1"
>
<span
class=
"group-heading"
>
<span
class=
"group-heading
active
"
>
1 Introduction Chapter
1 Introduction Chapter
</span>
</span>
</a>
</a>
<div
class=
"chapter-content-container"
id=
"accordion-menu-1"
tabindex=
"-1"
aria-expanded=
"true"
>
<div
class=
"chapter-content-container
is-open
"
id=
"accordion-menu-1"
tabindex=
"-1"
aria-expanded=
"true"
>
<div
class=
"chapter-menu"
>
<div
class=
"chapter-menu
is-open
"
>
<div
class=
"menu-item"
>
<div
class=
"menu-item"
>
<a
href=
"#"
>
<a
href=
"#"
>
<p>
1 edX Homepage
</p>
<p>
1 edX Homepage
</p>
...
...
lms/static/js/spec/navigation_spec.js
View file @
f6d34711
...
@@ -4,6 +4,10 @@ define(['jquery', 'js/utils/navigation'], function($) {
...
@@ -4,6 +4,10 @@ define(['jquery', 'js/utils/navigation'], function($) {
describe
(
'Course Navigation Accordion'
,
function
()
{
describe
(
'Course Navigation Accordion'
,
function
()
{
var
accordion
,
button
,
heading
,
chapterContent
,
chapterMenu
;
var
accordion
,
button
,
heading
,
chapterContent
,
chapterMenu
;
function
keyPressEvent
(
key
)
{
return
$
.
Event
(
'keydown'
,
{
which
:
key
});
}
beforeEach
(
function
()
{
beforeEach
(
function
()
{
loadFixtures
(
'js/fixtures/accordion.html'
);
loadFixtures
(
'js/fixtures/accordion.html'
);
...
@@ -13,6 +17,7 @@ define(['jquery', 'js/utils/navigation'], function($) {
...
@@ -13,6 +17,7 @@ define(['jquery', 'js/utils/navigation'], function($) {
chapterContent
=
accordion
.
children
(
'.chapter-content-container'
);
chapterContent
=
accordion
.
children
(
'.chapter-content-container'
);
chapterMenu
=
chapterContent
.
children
(
'.chapter-menu'
);
chapterMenu
=
chapterContent
.
children
(
'.chapter-menu'
);
this
.
KEY
=
$
.
ui
.
keyCode
;
spyOn
(
$
.
fn
,
'focus'
).
andCallThrough
();
spyOn
(
$
.
fn
,
'focus'
).
andCallThrough
();
edx
.
util
.
navigation
.
init
();
edx
.
util
.
navigation
.
init
();
});
});
...
@@ -26,35 +31,37 @@ define(['jquery', 'js/utils/navigation'], function($) {
...
@@ -26,35 +31,37 @@ define(['jquery', 'js/utils/navigation'], function($) {
});
});
it
(
'ensures aria attributes are present'
,
function
()
{
it
(
'ensures aria attributes are present'
,
function
()
{
expect
(
chapterContent
).
toHaveAttr
({
expect
(
accordion
.
find
(
'.chapter-content-container'
).
first
()
).
toHaveAttr
({
'aria-expanded'
:
'true'
'aria-expanded'
:
'true'
});
});
expect
(
accordion
.
find
(
'.chapter-content-container'
).
last
()).
toHaveAttr
({
'aria-expanded'
:
'false'
});
});
});
it
(
'ensures only one active item'
,
function
()
{
it
(
'ensures only one active item'
,
function
()
{
expect
(
chapterMenu
.
find
(
'.active'
).
length
).
toBe
(
1
);
expect
(
$
(
chapterMenu
)
.
find
(
'.active'
).
length
).
toBe
(
1
);
});
});
});
});
describe
(
'open section with mouse click'
,
function
()
{
describe
(
'open section with mouse click'
,
function
()
{
it
(
'ensures new section is opened and previous section is closed'
,
function
()
{
it
(
'ensures new section is opened and previous section is closed'
,
function
()
{
button
:
eq
(
1
).
click
(
);
accordion
.
find
(
'.button-chapter'
).
last
().
trigger
(
'click'
);
expect
(
chapterContent
:
eq
(
0
)).
not
.
toHaveClass
(
'is-open'
);
expect
(
accordion
.
find
(
'.chapter-content-container'
).
first
(
)).
not
.
toHaveClass
(
'is-open'
);
expect
(
chapterContent
:
eq
(
1
)).
toHaveClass
(
'is-open'
);
expect
(
accordion
.
find
(
'.chapter-content-container'
).
last
(
)).
toHaveClass
(
'is-open'
);
expect
(
button
:
eq
(
0
)).
not
.
toHaveClass
(
'is-open'
);
expect
(
accordion
.
find
(
'.button-chapter'
).
first
()).
not
.
toHaveClass
(
'is-open'
);
expect
(
button
:
eq
(
1
)).
toHaveClass
(
'is-open'
);
expect
(
accordion
.
find
(
'.button-chapter'
).
last
()).
toHaveClass
(
'is-open'
);
expect
(
chapterContent
:
eq
(
1
).
focus
).
toHaveBeenCalled
();
});
});
it
(
'ensure proper aria and attrs'
,
function
()
{
it
(
'ensure proper aria and attrs'
,
function
()
{
expect
(
chapterContent
:
eq
(
1
)).
toHaveAttr
({
expect
(
accordion
.
find
(
'.chapter-content-container'
).
first
(
)).
toHaveAttr
({
'aria-expanded'
:
'false'
'aria-expanded'
:
'false'
});
});
expect
(
chapterContent
:
eq
(
0
)).
toHaveAttr
({
expect
(
accordion
.
find
(
'.chapter-content-container'
).
last
(
)).
toHaveAttr
({
'aria-expanded'
:
'true'
'aria-expanded'
:
'true'
});
});
});
});
...
@@ -62,28 +69,21 @@ define(['jquery', 'js/utils/navigation'], function($) {
...
@@ -62,28 +69,21 @@ define(['jquery', 'js/utils/navigation'], function($) {
describe
(
'open section with spacebar'
,
function
()
{
describe
(
'open section with spacebar'
,
function
()
{
function
keyPressEvent
(
key
)
{
return
$
.
Event
(
'keydown'
,
{
keyCode
:
key
});
}
it
(
'ensures new section is opened and previous section is closed'
,
function
()
{
it
(
'ensures new section is opened and previous section is closed'
,
function
()
{
button
:
eq
(
1
).
focus
();
accordion
.
find
(
'.button-chapter'
).
last
().
focus
().
trigger
(
keyPressEvent
(
this
.
KEY
.
SPACE
));
// Spacebar
button
.
trigger
(
keyPressEvent
(
32
));
// Spacebar
expect
(
chapterContent
:
eq
(
0
)).
not
.
toHaveClass
(
'is-open'
);
expect
(
chapterContent
:
eq
(
1
)).
toHaveClass
(
'is-open'
);
expect
(
button
:
eq
(
0
)).
not
.
toHaveClass
(
'is-open'
);
expect
(
accordion
.
find
(
'.chapter-content-container'
).
first
(
)).
not
.
toHaveClass
(
'is-open'
);
expect
(
button
:
eq
(
1
)).
toHaveClass
(
'is-open'
);
expect
(
accordion
.
find
(
'.chapter-content-container'
).
last
(
)).
toHaveClass
(
'is-open'
);
expect
(
chapterContent
:
eq
(
1
).
focus
).
toHaveBeenCalled
();
expect
(
accordion
.
find
(
'.button-chapter'
).
first
()).
not
.
toHaveClass
(
'is-open'
);
expect
(
accordion
.
find
(
'.button-chapter'
).
last
()).
toHaveClass
(
'is-open'
);
});
});
it
(
'ensure proper aria and attrs'
,
function
()
{
it
(
'ensure proper aria and attrs'
,
function
()
{
expect
(
chapterContent
:
eq
(
1
)).
toHaveAttr
({
expect
(
accordion
.
find
(
'.chapter-content-container'
).
first
(
)).
toHaveAttr
({
'aria-expanded'
:
'false'
'aria-expanded'
:
'false'
});
});
expect
(
chapterContent
:
eq
(
0
)).
toHaveAttr
({
expect
(
accordion
.
find
(
'.chapter-content-container'
).
last
(
)).
toHaveAttr
({
'aria-expanded'
:
'true'
'aria-expanded'
:
'true'
});
});
});
});
...
...
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