summaryrefslogtreecommitdiff
path: root/spec/frontend/code_navigation/store/mutations_spec.js
blob: b2f1b3bddfd9aa16c8f6f80217d63045a55c6662 (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
import mutations from '~/code_navigation/store/mutations';
import createState from '~/code_navigation/store/state';

let state;

describe('Code navigation mutations', () => {
  beforeEach(() => {
    state = createState();
  });

  describe('SET_INITIAL_DATA', () => {
    it('sets initial data', () => {
      mutations.SET_INITIAL_DATA(state, {
        blobs: ['test'],
        definitionPathPrefix: 'https://test.com/blob/main',
        wrapTextNodes: true,
      });

      expect(state.blobs).toEqual(['test']);
      expect(state.definitionPathPrefix).toBe('https://test.com/blob/main');
      expect(state.wrapTextNodes).toBe(true);
    });
  });

  describe('REQUEST_DATA', () => {
    it('sets loading true', () => {
      mutations.REQUEST_DATA(state);

      expect(state.loading).toBe(true);
    });
  });

  describe('REQUEST_DATA_SUCCESS', () => {
    it('sets loading false', () => {
      mutations.REQUEST_DATA_SUCCESS(state, ['test']);

      expect(state.loading).toBe(false);
    });

    it('sets data', () => {
      mutations.REQUEST_DATA_SUCCESS(state, { path: 'index.js', normalizedData: ['test'] });

      expect(state.data).toEqual({ 'index.js': ['test'] });
    });
  });

  describe('REQUEST_DATA_ERROR', () => {
    it('sets loading false', () => {
      mutations.REQUEST_DATA_ERROR(state);

      expect(state.loading).toBe(false);
    });
  });

  describe('SET_CURRENT_DEFINITION', () => {
    it('sets current definition and position', () => {
      mutations.SET_CURRENT_DEFINITION(state, { definition: 'test', position: { x: 0 } });

      expect(state.currentDefinition).toBe('test');
      expect(state.currentDefinitionPosition).toEqual({ x: 0 });
    });
  });
});