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;
|
2020-03-09 13:42:32 +05:30
|
|
|
jest.spyOn(config, 'preprocessing').mockImplementation(() => processedArray);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls preprocessing', () => {
|
|
|
|
Ajax.preprocessing(config, []);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(config.preprocessing.mock.calls.length).toBe(1);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('overrides AjaxCache', () => {
|
2020-03-09 13:42:32 +05:30
|
|
|
jest.spyOn(AjaxCache, 'override').mockImplementation((endpoint, results) => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(results).toEqual(processedArray);
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
Ajax.preprocessing(config, []);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(AjaxCache.override.mock.calls.length).toBe(1);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|