Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ajax_spec.js « plugins « droplab « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c6452e8337e4e0aa3443ed9a8a08d9cb6bf30fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Ajax from '~/droplab/plugins/ajax';
import AjaxCache from '~/lib/utils/ajax_cache';

describe('Ajax', () => {
  describe('preprocessing', () => {
    const config = {};

    describe('is not configured', () => {
      it('passes the data through', () => {
        const data = ['data'];

        expect(Ajax.preprocessing(config, data)).toEqual(data);
      });
    });

    describe('is configured', () => {
      const processedArray = ['processed'];

      beforeEach(() => {
        config.preprocessing = () => processedArray;
        jest.spyOn(config, 'preprocessing').mockImplementation(() => processedArray);
      });

      it('calls preprocessing', () => {
        Ajax.preprocessing(config, []);

        expect(config.preprocessing.mock.calls.length).toBe(1);
      });

      it('overrides AjaxCache', () => {
        jest.spyOn(AjaxCache, 'override').mockImplementation((endpoint, results) => {
          expect(results).toEqual(processedArray);
        });

        Ajax.preprocessing(config, []);

        expect(AjaxCache.override.mock.calls.length).toBe(1);
      });
    });
  });
});