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

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Ajax from '~/droplab/plugins/ajax';
2021-03-11 19:13:27 +05:30
import AjaxCache from '~/lib/utils/ajax_cache';
2017-09-10 17:25:29 +05:30
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-13 15:44:24 +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-13 15:44:24 +05:30
expect(config.preprocessing.mock.calls.length).toBe(1);
2017-09-10 17:25:29 +05:30
});
it('overrides AjaxCache', () => {
2020-03-13 15:44:24 +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-13 15:44:24 +05:30
expect(AjaxCache.override.mock.calls.length).toBe(1);
2017-09-10 17:25:29 +05:30
});
});
});
});