summaryrefslogtreecommitdiff
path: root/spec/frontend/reports/codequality_report/store/mutations_spec.js
blob: 658abf3088c59d820f101b9296711c86d4a7c9b1 (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
73
74
75
76
77
78
79
80
import mutations from '~/reports/codequality_report/store/mutations';
import createStore from '~/reports/codequality_report/store';

describe('Codequality Reports mutations', () => {
  let localState;
  let localStore;

  beforeEach(() => {
    localStore = createStore();
    localState = localStore.state;
  });

  describe('SET_PATHS', () => {
    it('sets paths to given values', () => {
      const basePath = 'base.json';
      const headPath = 'head.json';
      const baseBlobPath = 'base/blob/path/';
      const headBlobPath = 'head/blob/path/';
      const helpPath = 'help.html';

      mutations.SET_PATHS(localState, {
        basePath,
        headPath,
        baseBlobPath,
        headBlobPath,
        helpPath,
      });

      expect(localState.basePath).toEqual(basePath);
      expect(localState.headPath).toEqual(headPath);
      expect(localState.baseBlobPath).toEqual(baseBlobPath);
      expect(localState.headBlobPath).toEqual(headBlobPath);
      expect(localState.helpPath).toEqual(helpPath);
    });
  });

  describe('REQUEST_REPORTS', () => {
    it('sets isLoading to true', () => {
      mutations.REQUEST_REPORTS(localState);

      expect(localState.isLoading).toEqual(true);
    });
  });

  describe('RECEIVE_REPORTS_SUCCESS', () => {
    it('sets isLoading to false', () => {
      mutations.RECEIVE_REPORTS_SUCCESS(localState, {});

      expect(localState.isLoading).toEqual(false);
    });

    it('sets hasError to false', () => {
      mutations.RECEIVE_REPORTS_SUCCESS(localState, {});

      expect(localState.hasError).toEqual(false);
    });

    it('sets newIssues and resolvedIssues from response data', () => {
      const data = { newIssues: [{ id: 1 }], resolvedIssues: [{ id: 2 }] };
      mutations.RECEIVE_REPORTS_SUCCESS(localState, data);

      expect(localState.newIssues).toEqual(data.newIssues);
      expect(localState.resolvedIssues).toEqual(data.resolvedIssues);
    });
  });

  describe('RECEIVE_REPORTS_ERROR', () => {
    it('sets isLoading to false', () => {
      mutations.RECEIVE_REPORTS_ERROR(localState);

      expect(localState.isLoading).toEqual(false);
    });

    it('sets hasError to true', () => {
      mutations.RECEIVE_REPORTS_ERROR(localState);

      expect(localState.hasError).toEqual(true);
    });
  });
});