* 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
85 lines
3.5 KiB
JavaScript
85 lines
3.5 KiB
JavaScript
/* globals sandbox */
|
|
|
|
(function(sandbox) {
|
|
'use strict';
|
|
|
|
// eslint-disable-next-line global-require
|
|
require(['jquery', 'backbone', 'cms/js/main', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers', 'jquery.cookie'],
|
|
function($, Backbone, main, AjaxHelpers) {
|
|
describe('CMS', function() {
|
|
it('should initialize URL', function() {
|
|
expect(window.CMS.URL).toBeDefined();
|
|
});
|
|
});
|
|
describe('main helper', function() {
|
|
beforeEach(function() {
|
|
this.previousAjaxSettings = $.extend(true, {}, $.ajaxSettings);
|
|
spyOn($, 'cookie').and.callFake(function(param) {
|
|
if (param === 'csrftoken') {
|
|
return 'stubCSRFToken';
|
|
}
|
|
});
|
|
return main();
|
|
});
|
|
afterEach(function() {
|
|
$.ajaxSettings = this.previousAjaxSettings;
|
|
return $.ajaxSettings;
|
|
});
|
|
it('turn on Backbone emulateHTTP', function() {
|
|
expect(Backbone.emulateHTTP).toBeTruthy();
|
|
});
|
|
it('setup AJAX CSRF token', function() {
|
|
expect($.ajaxSettings.headers['X-CSRFToken']).toEqual('stubCSRFToken');
|
|
});
|
|
});
|
|
describe('AJAX Errors', function() {
|
|
var server;
|
|
server = null;
|
|
beforeEach(function() {
|
|
appendSetFixtures(sandbox({
|
|
id: 'page-notification'
|
|
}));
|
|
});
|
|
afterEach(function() {
|
|
return server && server.restore();
|
|
});
|
|
it('successful AJAX request does not pop an error notification', function() {
|
|
server = AjaxHelpers.server([
|
|
200, {
|
|
'Content-Type': 'application/json'
|
|
}, '{}'
|
|
]);
|
|
expect($('#page-notification')).toBeEmpty();
|
|
$.ajax('/test');
|
|
expect($('#page-notification')).toBeEmpty();
|
|
server.respond();
|
|
expect($('#page-notification')).toBeEmpty();
|
|
});
|
|
it('AJAX request with error should pop an error notification', function() {
|
|
server = AjaxHelpers.server([
|
|
500, {
|
|
'Content-Type': 'application/json'
|
|
}, '{}'
|
|
]);
|
|
$.ajax('/test');
|
|
server.respond();
|
|
expect($('#page-notification')).not.toBeEmpty();
|
|
expect($('#page-notification')).toContainElement('div.wrapper-notification-error');
|
|
});
|
|
it('can override AJAX request with error so it does not pop an error notification', function() {
|
|
server = AjaxHelpers.server([
|
|
500, {
|
|
'Content-Type': 'application/json'
|
|
}, '{}'
|
|
]);
|
|
$.ajax({
|
|
url: '/test',
|
|
notifyOnError: false
|
|
});
|
|
server.respond();
|
|
expect($('#page-notification')).toBeEmpty();
|
|
});
|
|
});
|
|
});
|
|
}).call(this, sandbox);
|