debian-mirror-gitlab/spec/javascripts/ajax_loading_spinner_spec.js

58 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import AjaxLoadingSpinner from '~/ajax_loading_spinner';
2017-08-17 22:00:37 +05:30
describe('Ajax Loading Spinner', () => {
2019-07-07 11:18:12 +05:30
const fixtureTemplate = 'static/ajax_loading_spinner.html';
2017-08-17 22:00:37 +05:30
preloadFixtures(fixtureTemplate);
beforeEach(() => {
loadFixtures(fixtureTemplate);
2018-03-17 18:26:18 +05:30
AjaxLoadingSpinner.init();
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
it('change current icon with spinner icon and disable link while waiting ajax response', done => {
spyOn($, 'ajax').and.callFake(req => {
2017-08-17 22:00:37 +05:30
const xhr = new XMLHttpRequest();
const ajaxLoadingSpinner = document.querySelector('.js-ajax-loading-spinner');
const icon = ajaxLoadingSpinner.querySelector('i');
req.beforeSend(xhr, { dataType: 'text/html' });
expect(icon).not.toHaveClass('fa-trash-o');
expect(icon).toHaveClass('fa-spinner');
expect(icon).toHaveClass('fa-spin');
expect(icon.dataset.icon).toEqual('fa-trash-o');
expect(ajaxLoadingSpinner.getAttribute('disabled')).toEqual('');
req.complete({});
done();
const deferred = $.Deferred();
return deferred.promise();
});
document.querySelector('.js-ajax-loading-spinner').click();
});
2018-12-13 13:39:08 +05:30
it('use original icon again and enabled the link after complete the ajax request', done => {
spyOn($, 'ajax').and.callFake(req => {
2017-08-17 22:00:37 +05:30
const xhr = new XMLHttpRequest();
const ajaxLoadingSpinner = document.querySelector('.js-ajax-loading-spinner');
req.beforeSend(xhr, { dataType: 'text/html' });
req.complete({});
const icon = ajaxLoadingSpinner.querySelector('i');
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(icon).toHaveClass('fa-trash-o');
expect(icon).not.toHaveClass('fa-spinner');
expect(icon).not.toHaveClass('fa-spin');
expect(ajaxLoadingSpinner.getAttribute('disabled')).toEqual(null);
done();
const deferred = $.Deferred();
return deferred.promise();
});
document.querySelector('.js-ajax-loading-spinner').click();
});
});