summaryrefslogtreecommitdiff
path: root/spec/frontend/batch_comments/stores/modules/batch_comments/mutations_spec.js
blob: a86726269ef54547b6a3acfa6fe51acd51a68782 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import createState from '~/batch_comments/stores/modules/batch_comments/state';
import mutations from '~/batch_comments/stores/modules/batch_comments/mutations';
import * as types from '~/batch_comments/stores/modules/batch_comments/mutation_types';

describe('Batch comments mutations', () => {
  let state;

  beforeEach(() => {
    state = createState();
  });

  describe(types.ADD_NEW_DRAFT, () => {
    it('adds processed object into drafts array', () => {
      const draft = { id: 1, note: 'test' };

      mutations[types.ADD_NEW_DRAFT](state, draft);

      expect(state.drafts).toEqual([
        {
          ...draft,
          isDraft: true,
        },
      ]);
    });
  });

  describe(types.DELETE_DRAFT, () => {
    it('removes draft from array by ID', () => {
      state.drafts.push({ id: 1 }, { id: 2 });

      mutations[types.DELETE_DRAFT](state, 1);

      expect(state.drafts).toEqual([{ id: 2 }]);
    });
  });

  describe(types.SET_BATCH_COMMENTS_DRAFTS, () => {
    it('adds to processed drafts in state', () => {
      const drafts = [{ id: 1 }, { id: 2 }];

      mutations[types.SET_BATCH_COMMENTS_DRAFTS](state, drafts);

      expect(state.drafts).toEqual([
        {
          id: 1,
          isDraft: true,
        },
        {
          id: 2,
          isDraft: true,
        },
      ]);
    });
  });

  describe(types.REQUEST_PUBLISH_REVIEW, () => {
    it('sets isPublishing to true', () => {
      mutations[types.REQUEST_PUBLISH_REVIEW](state);

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

  describe(types.RECEIVE_PUBLISH_REVIEW_SUCCESS, () => {
    it('resets drafts', () => {
      state.drafts.push('test');

      mutations[types.RECEIVE_PUBLISH_REVIEW_SUCCESS](state);

      expect(state.drafts).toEqual([]);
    });

    it('sets isPublishing to false', () => {
      state.isPublishing = true;

      mutations[types.RECEIVE_PUBLISH_REVIEW_SUCCESS](state);

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

  describe(types.RECEIVE_PUBLISH_REVIEW_ERROR, () => {
    it('updates isPublishing to false', () => {
      state.isPublishing = true;

      mutations[types.RECEIVE_PUBLISH_REVIEW_ERROR](state);

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

  describe(types.REQUEST_DISCARD_REVIEW, () => {
    it('sets isDiscarding to true', () => {
      mutations[types.REQUEST_DISCARD_REVIEW](state);

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

  describe(types.RECEIVE_DISCARD_REVIEW_SUCCESS, () => {
    it('emptys drafts array', () => {
      state.drafts.push('test');

      mutations[types.RECEIVE_DISCARD_REVIEW_SUCCESS](state);

      expect(state.drafts).toEqual([]);
    });

    it('sets isDiscarding to false', () => {
      state.isDiscarding = true;

      mutations[types.RECEIVE_DISCARD_REVIEW_SUCCESS](state);

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

  describe(types.RECEIVE_DISCARD_REVIEW_ERROR, () => {
    it('updates isDiscarding to false', () => {
      state.isDiscarding = true;

      mutations[types.RECEIVE_DISCARD_REVIEW_ERROR](state);

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

  describe(types.RECEIVE_DRAFT_UPDATE_SUCCESS, () => {
    it('updates draft in store', () => {
      state.drafts.push({ id: 1 });

      mutations[types.RECEIVE_DRAFT_UPDATE_SUCCESS](state, { id: 1, note: 'test' });

      expect(state.drafts).toEqual([
        {
          id: 1,
          note: 'test',
          isDraft: true,
        },
      ]);
    });
  });

  describe(types.OPEN_REVIEW_DROPDOWN, () => {
    it('sets showPreviewDropdown to true', () => {
      mutations[types.OPEN_REVIEW_DROPDOWN](state);

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

  describe(types.CLOSE_REVIEW_DROPDOWN, () => {
    it('sets showPreviewDropdown to false', () => {
      mutations[types.CLOSE_REVIEW_DROPDOWN](state);

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