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

utils_spec.js « blob « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f597aa016e10dfa1063eecfb0634184c1f99933 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as utils from '~/blob/utils';
import Editor from '~/editor/source_editor';

jest.mock('~/editor/source_editor');

describe('Blob utilities', () => {
  describe('initSourceEditor', () => {
    let editorEl;
    const blobPath = 'foo.txt';
    const blobContent = 'Foo bar';
    const blobGlobalId = 'snippet_777';

    beforeEach(() => {
      editorEl = document.createElement('div');
    });

    describe('Monaco editor', () => {
      it('initializes the Source Editor', () => {
        utils.initSourceEditor({ el: editorEl });
        expect(Editor).toHaveBeenCalledWith({
          scrollbar: {
            alwaysConsumeMouseWheel: false,
          },
        });
      });

      it.each([[{}], [{ blobPath, blobContent, blobGlobalId }]])(
        'creates the instance with the passed parameters %s',
        (extraParams) => {
          const params = {
            el: editorEl,
            ...extraParams,
          };

          expect(Editor.prototype.createInstance).not.toHaveBeenCalled();

          utils.initSourceEditor(params);

          expect(Editor.prototype.createInstance).toHaveBeenCalledWith(params);
        },
      );
    });
  });
  describe('getPageParamValue', () => {
    it('returns empty string if no perPage parameter is provided', () => {
      const pageParamValue = utils.getPageParamValue(5);
      expect(pageParamValue).toEqual('');
    });
    it('returns empty string if page is equal 1', () => {
      const pageParamValue = utils.getPageParamValue(1000, 1000);
      expect(pageParamValue).toEqual('');
    });
    it('returns correct page parameter value', () => {
      const pageParamValue = utils.getPageParamValue(1001, 1000);
      expect(pageParamValue).toEqual(2);
    });
    it('accepts strings as a parameter and returns correct result', () => {
      const pageParamValue = utils.getPageParamValue('1001', '1000');
      expect(pageParamValue).toEqual(2);
    });
  });
  describe('getPageSearchString', () => {
    it('returns empty search string if page parameter is empty value', () => {
      const path = utils.getPageSearchString('/blamePath', '');
      expect(path).toEqual('');
    });
    it('returns correct search string if value is provided', () => {
      const searchString = utils.getPageSearchString('/blamePath', 3);
      expect(searchString).toEqual('?page=3');
    });
  });
});