Commit 9a786d08 by Christina Roberts

Merge pull request #11395 from edx/christina/fix-test-typo

Fix unit tests so they are testing aria-expanded.
parents 71a6779d 8f19128d
<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 is-open" aria-controls="accordion-menu-1"> <a href="accordion-menu-1" role="button" class="button-chapter chapter is-open" aria-controls="accordion-menu-1" aria-expanded="true">
<span class="group-heading active"> <span class="group-heading active">
1 Introduction Chapter 1 Introduction Chapter
</span> </span>
</a> </a>
<div class="chapter-content-container is-open" id="accordion-menu-1" tabindex="-1" aria-expanded="true"> <div class="chapter-content-container is-open" id="accordion-menu-1" tabindex="-1">
<div class="chapter-menu is-open"> <div class="chapter-menu is-open">
<div class="menu-item"> <div class="menu-item">
<a href="#"> <a href="#">
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
</a> </a>
</div> </div>
</div> </div>
<a href="accordion-menu-2" role="button" class="button-chapter chapter" aria-controls="accordion-menu-2"> <a href="accordion-menu-2" role="button" class="button-chapter chapter" aria-controls="accordion-menu-2" aria-expanded="false">
<span class="group-heading"> <span class="group-heading">
2 Another Chapter 2 Another Chapter
</span> </span>
</a> </a>
<div class="chapter-content-container" id="accordion-menu-2" tabindex="-1" aria-expanded="false"> <div class="chapter-content-container" id="accordion-menu-2" tabindex="-1">
<div class="chapter-menu"> <div class="chapter-menu">
<div class="menu-item"> <div class="menu-item">
<a href="#"> <a href="#">
......
...@@ -2,7 +2,7 @@ define(['jquery', 'js/utils/navigation'], function($) { ...@@ -2,7 +2,7 @@ define(['jquery', 'js/utils/navigation'], function($) {
'use strict'; 'use strict';
describe('Course Navigation Accordion', function() { describe('Course Navigation Accordion', function() {
var accordion, button, heading, chapterContent, chapterMenu; var accordion, chapterMenu;
function keyPressEvent(key) { function keyPressEvent(key) {
return $.Event('keydown', { which: key }); return $.Event('keydown', { which: key });
...@@ -12,10 +12,7 @@ define(['jquery', 'js/utils/navigation'], function($) { ...@@ -12,10 +12,7 @@ define(['jquery', 'js/utils/navigation'], function($) {
loadFixtures('js/fixtures/accordion.html'); loadFixtures('js/fixtures/accordion.html');
accordion = $('.accordion'); accordion = $('.accordion');
button = accordion.children('.button-chapter'); chapterMenu = accordion.children('.chapter-content-container').children('.chapter-menu');
heading = button.children('.group-heading');
chapterContent = accordion.children('.chapter-content-container');
chapterMenu = chapterContent.children('.chapter-menu');
this.KEY = $.ui.keyCode; this.KEY = $.ui.keyCode;
spyOn($.fn, 'focus').andCallThrough(); spyOn($.fn, 'focus').andCallThrough();
...@@ -31,13 +28,8 @@ define(['jquery', 'js/utils/navigation'], function($) { ...@@ -31,13 +28,8 @@ define(['jquery', 'js/utils/navigation'], function($) {
}); });
it('ensures aria attributes are present', function() { it('ensures aria attributes are present', function() {
expect(accordion.find('.chapter-content-container').first()).toHaveAttr({ expect(accordion.find('.button-chapter').first()).toHaveAttr('aria-expanded', 'true');
'aria-expanded': 'true' expect(accordion.find('.button-chapter').last()).toHaveAttr('aria-expanded', 'false');
});
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() {
...@@ -58,19 +50,17 @@ define(['jquery', 'js/utils/navigation'], function($) { ...@@ -58,19 +50,17 @@ define(['jquery', 'js/utils/navigation'], function($) {
}); });
it('ensure proper aria and attrs', function() { it('ensure proper aria and attrs', function() {
expect(accordion.find('.chapter-content-container').first()).toHaveAttr({ accordion.find('.button-chapter').last().trigger('click');
'aria-expanded': 'false'
}); expect(accordion.find('.button-chapter').first()).toHaveAttr('aria-expanded', 'false');
expect(accordion.find('.chapter-content-container').last()).toHaveAttr({ expect(accordion.find('.button-chapter').last()).toHaveAttr('aria-expanded', 'true');
'aria-expanded': 'true'
});
}); });
}); });
describe('open section with spacebar', function() { describe('open section with spacebar', 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() {
accordion.find('.button-chapter').last().focus().trigger(keyPressEvent(this.KEY.SPACE)); // Spacebar accordion.find('.button-chapter').last().focus().trigger(keyPressEvent(this.KEY.SPACE));
expect(accordion.find('.chapter-content-container').first()).not.toHaveClass('is-open'); expect(accordion.find('.chapter-content-container').first()).not.toHaveClass('is-open');
expect(accordion.find('.chapter-content-container').last()).toHaveClass('is-open'); expect(accordion.find('.chapter-content-container').last()).toHaveClass('is-open');
...@@ -80,12 +70,10 @@ define(['jquery', 'js/utils/navigation'], function($) { ...@@ -80,12 +70,10 @@ define(['jquery', 'js/utils/navigation'], function($) {
}); });
it('ensure proper aria and attrs', function() { it('ensure proper aria and attrs', function() {
expect(accordion.find('.chapter-content-container').first()).toHaveAttr({ accordion.find('.button-chapter').last().focus().trigger(keyPressEvent(this.KEY.SPACE));
'aria-expanded': 'false'
}); expect(accordion.find('.button-chapter').first()).toHaveAttr('aria-expanded', 'false');
expect(accordion.find('.chapter-content-container').last()).toHaveAttr({ expect(accordion.find('.button-chapter').last()).toHaveAttr('aria-expanded', 'true');
'aria-expanded': 'true'
});
}); });
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment