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

mutations_spec.js « store « related_merge_requests « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 21b6e26376bd13ba84de4253f1770b949f83f013 (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
import mutations from '~/related_merge_requests/store/mutations';
import * as types from '~/related_merge_requests/store/mutation_types';

describe('RelatedMergeRequests Store Mutations', () => {
  describe('SET_INITIAL_STATE', () => {
    it('should set initial state according to given data', () => {
      const apiEndpoint = '/api';
      const state = {};

      mutations[types.SET_INITIAL_STATE](state, { apiEndpoint });

      expect(state.apiEndpoint).toEqual(apiEndpoint);
    });
  });

  describe('REQUEST_DATA', () => {
    it('should set loading flag', () => {
      const state = {};

      mutations[types.REQUEST_DATA](state);

      expect(state.isFetchingMergeRequests).toEqual(true);
    });
  });

  describe('RECEIVE_DATA_SUCCESS', () => {
    it('should set loading flag and data', () => {
      const state = {};
      const mrs = [1, 2, 3];

      mutations[types.RECEIVE_DATA_SUCCESS](state, { data: mrs, total: mrs.length });

      expect(state.isFetchingMergeRequests).toEqual(false);
      expect(state.mergeRequests).toEqual(mrs);
      expect(state.totalCount).toEqual(mrs.length);
    });
  });

  describe('RECEIVE_DATA_ERROR', () => {
    it('should set loading and error flags', () => {
      const state = {};

      mutations[types.RECEIVE_DATA_ERROR](state);

      expect(state.isFetchingMergeRequests).toEqual(false);
      expect(state.hasErrorFetchingMergeRequests).toEqual(true);
    });
  });
});