* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * chore: apply amnesty on all existing issues * fix: failing xss-lint issues * refactor: apply amnesty on remaining issues * refactor: apply amnesty on new issues * fix: remove file level suppressions * refactor: apply amnesty on new issues
128 lines
4.9 KiB
JavaScript
128 lines
4.9 KiB
JavaScript
/* globals Sequence */
|
|
(function() {
|
|
'use strict';
|
|
|
|
describe('Sequence', function() {
|
|
var local = {},
|
|
keydownHandler,
|
|
keys = {
|
|
ENTER: 13,
|
|
LEFT: 37,
|
|
RIGHT: 39
|
|
};
|
|
|
|
beforeEach(function() {
|
|
var runtime = jasmine.createSpyObj('TestRuntime', ['handlerUrl']);
|
|
loadFixtures('sequence.html');
|
|
// eslint-disable-next-line no-multi-assign
|
|
local.XBlock = window.XBlock = jasmine.createSpyObj('XBlock', ['initializeBlocks']);
|
|
this.sequence = new Sequence($('.xblock-student_view-sequential'), runtime);
|
|
});
|
|
|
|
afterEach(function() {
|
|
delete local.XBlock;
|
|
});
|
|
|
|
keydownHandler = function(key) {
|
|
var event = document.createEvent('Event');
|
|
event.keyCode = key;
|
|
event.initEvent('keydown', false, false);
|
|
document.dispatchEvent(event);
|
|
};
|
|
|
|
describe('Navbar', function() {
|
|
it('works with keyboard navigation LEFT and ENTER', function() {
|
|
this.sequence.$('.nav-item[data-index=0]').focus();
|
|
keydownHandler(keys.LEFT);
|
|
keydownHandler(keys.ENTER);
|
|
|
|
expect(this.sequence.$('.nav-item[data-index=1]')).toHaveAttr({
|
|
'aria-expanded': 'false',
|
|
'aria-selected': 'false',
|
|
tabindex: '-1'
|
|
});
|
|
expect(this.sequence.$('.nav-item[data-index=0]')).toHaveAttr({
|
|
'aria-expanded': 'true',
|
|
'aria-selected': 'true',
|
|
tabindex: '0'
|
|
});
|
|
});
|
|
|
|
it('works with keyboard navigation RIGHT and ENTER', function() {
|
|
this.sequence.$('.nav-item[data-index=0]').focus();
|
|
keydownHandler(keys.RIGHT);
|
|
keydownHandler(keys.ENTER);
|
|
|
|
expect(this.sequence.$('.nav-item[data-index=0]')).toHaveAttr({
|
|
'aria-expanded': 'false',
|
|
'aria-selected': 'false',
|
|
tabindex: '-1'
|
|
});
|
|
expect(this.sequence.$('.nav-item[data-index=1]')).toHaveAttr({
|
|
'aria-expanded': 'true',
|
|
'aria-selected': 'true',
|
|
tabindex: '0'
|
|
});
|
|
});
|
|
|
|
it('Completion Indicator missing', function() {
|
|
this.sequence.$('.nav-item[data-index=0]').children('.check-circle').remove();
|
|
spyOn($, 'postWithPrefix').and.callFake(function(url, data, callback) {
|
|
callback({
|
|
complete: true
|
|
});
|
|
});
|
|
this.sequence.update_completion(1);
|
|
expect($.postWithPrefix).not.toHaveBeenCalled();
|
|
});
|
|
|
|
describe('Completion', function() {
|
|
beforeEach(function() {
|
|
expect(
|
|
this.sequence.$('.nav-item[data-index=0]').children('.check-circle').first()
|
|
.hasClass('is-hidden')
|
|
).toBe(true);
|
|
expect(
|
|
this.sequence.$('.nav-item[data-index=1]').children('.check-circle').first()
|
|
.hasClass('is-hidden')
|
|
).toBe(true);
|
|
});
|
|
|
|
afterEach(function() {
|
|
expect($.postWithPrefix).toHaveBeenCalled();
|
|
expect(
|
|
this.sequence.$('.nav-item[data-index=1]').children('.check-circle').first()
|
|
.hasClass('is-hidden')
|
|
).toBe(true);
|
|
});
|
|
|
|
it('API check returned true', function() {
|
|
spyOn($, 'postWithPrefix').and.callFake(function(url, data, callback) {
|
|
callback({
|
|
complete: true
|
|
});
|
|
});
|
|
this.sequence.update_completion(1);
|
|
expect(
|
|
this.sequence.$('.nav-item[data-index=0]').children('.check-circle').first()
|
|
.hasClass('is-hidden')
|
|
).toBe(false);
|
|
});
|
|
|
|
it('API check returned false', function() {
|
|
spyOn($, 'postWithPrefix').and.callFake(function(url, data, callback) {
|
|
callback({
|
|
complete: false
|
|
});
|
|
});
|
|
this.sequence.update_completion(1);
|
|
expect(
|
|
this.sequence.$('.nav-item[data-index=0]').children('.check-circle').first()
|
|
.hasClass('is-hidden')
|
|
).toBe(true);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}).call(this);
|