summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/stores/mutations/merge_request_spec.js
blob: e30ca22022f4cb2b5284420cc130b87909e5392d (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
import mutations from '~/ide/stores/mutations/merge_request';
import state from '~/ide/stores/state';

describe('IDE store merge request mutations', () => {
  let localState;

  beforeEach(() => {
    localState = state();
    localState.projects = { abcproject: { mergeRequests: {} } };

    mutations.SET_MERGE_REQUEST(localState, {
      projectPath: 'abcproject',
      mergeRequestId: 1,
      mergeRequest: {
        title: 'mr',
      },
    });
  });

  describe('SET_CURRENT_MERGE_REQUEST', () => {
    it('sets current merge request', () => {
      mutations.SET_CURRENT_MERGE_REQUEST(localState, 2);

      expect(localState.currentMergeRequestId).toBe(2);
    });
  });

  describe('SET_MERGE_REQUEST', () => {
    it('setsmerge request data', () => {
      const newMr = localState.projects.abcproject.mergeRequests[1];

      expect(newMr.title).toBe('mr');
      expect(newMr.active).toBeTruthy();
    });
  });

  describe('SET_MERGE_REQUEST_CHANGES', () => {
    it('sets merge request changes', () => {
      mutations.SET_MERGE_REQUEST_CHANGES(localState, {
        projectPath: 'abcproject',
        mergeRequestId: 1,
        changes: {
          diff: 'abc',
        },
      });

      const newMr = localState.projects.abcproject.mergeRequests[1];

      expect(newMr.changes.diff).toBe('abc');
    });
  });

  describe('SET_MERGE_REQUEST_VERSIONS', () => {
    it('sets merge request versions', () => {
      mutations.SET_MERGE_REQUEST_VERSIONS(localState, {
        projectPath: 'abcproject',
        mergeRequestId: 1,
        versions: [{ id: 123 }],
      });

      const newMr = localState.projects.abcproject.mergeRequests[1];

      expect(newMr.versions.length).toBe(1);
      expect(newMr.versions[0].id).toBe(123);
    });
  });
});