debian-mirror-gitlab/spec/javascripts/droplab/plugins/ajax_spec.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import AjaxCache from '~/lib/utils/ajax_cache';
import Ajax from '~/droplab/plugins/ajax';
describe('Ajax', () => {
describe('preprocessing', () => {
const config = {};
describe('is not configured', () => {
it('passes the data through', () => {
const data = ['data'];
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(Ajax.preprocessing(config, data)).toEqual(data);
});
});
describe('is configured', () => {
const processedArray = ['processed'];
beforeEach(() => {
config.preprocessing = () => processedArray;
spyOn(config, 'preprocessing').and.callFake(() => processedArray);
});
it('calls preprocessing', () => {
Ajax.preprocessing(config, []);
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(config.preprocessing.calls.count()).toBe(1);
});
it('overrides AjaxCache', () => {
2018-12-13 13:39:08 +05:30
spyOn(AjaxCache, 'override').and.callFake((endpoint, results) => {
expect(results).toEqual(processedArray);
});
2017-09-10 17:25:29 +05:30
Ajax.preprocessing(config, []);
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(AjaxCache.override.calls.count()).toBe(1);
});
});
});
});