gitlab-org--gitlab-foss/spec/javascripts/droplab/plugins/ajax_spec.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

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-10-09 14:03:09 -04:00
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-10-09 14:03:09 -04:00
expect(config.preprocessing.calls.count()).toBe(1);
});
it('overrides AjaxCache', () => {
2018-10-09 14:03:09 -04:00
spyOn(AjaxCache, 'override').and.callFake((endpoint, results) => {
2018-10-17 03:13:26 -04:00
expect(results).toEqual(processedArray);
2018-10-09 14:03:09 -04:00
});
Ajax.preprocessing(config, []);
2018-10-09 14:03:09 -04:00
expect(AjaxCache.override.calls.count()).toBe(1);
});
});
});
});