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

actions_spec.js « store « commit « projects « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 458372229cf9de739a0bf205d4f28fe626b1671d (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
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { PROJECT_BRANCHES_ERROR } from '~/projects/commit/constants';
import * as actions from '~/projects/commit/store/actions';
import * as types from '~/projects/commit/store/mutation_types';
import getInitialState from '~/projects/commit/store/state';
import mockData from '../mock_data';

jest.mock('~/flash.js');

describe('Commit form modal store actions', () => {
  let axiosMock;
  let state;

  beforeEach(() => {
    axiosMock = new MockAdapter(axios);
    state = getInitialState();
  });

  afterEach(() => {
    axiosMock.restore();
  });

  describe('clearModal', () => {
    it('commits CLEAR_MODAL mutation', () => {
      testAction(actions.clearModal, {}, {}, [
        {
          type: types.CLEAR_MODAL,
        },
      ]);
    });
  });

  describe('requestBranches', () => {
    it('commits REQUEST_BRANCHES mutation', () => {
      testAction(actions.requestBranches, {}, {}, [
        {
          type: types.REQUEST_BRANCHES,
        },
      ]);
    });
  });

  describe('fetchBranches', () => {
    it('dispatch correct actions on fetchBranches', (done) => {
      jest
        .spyOn(axios, 'get')
        .mockImplementation(() => Promise.resolve({ data: mockData.mockBranches }));

      testAction(
        actions.fetchBranches,
        {},
        state,
        [
          {
            type: types.RECEIVE_BRANCHES_SUCCESS,
            payload: mockData.mockBranches,
          },
        ],
        [{ type: 'requestBranches' }],
        () => {
          done();
        },
      );
    });

    it('should show flash error and set error in state on fetchBranches failure', (done) => {
      jest.spyOn(axios, 'get').mockRejectedValue();

      testAction(actions.fetchBranches, {}, state, [], [{ type: 'requestBranches' }], () => {
        expect(createFlash).toHaveBeenCalledWith({ message: PROJECT_BRANCHES_ERROR });
        done();
      });
    });
  });

  describe('setBranch', () => {
    it('commits SET_BRANCH mutation', () => {
      testAction(
        actions.setBranch,
        {},
        {},
        [
          {
            type: types.SET_BRANCH,
            payload: {},
          },
        ],
        [
          {
            type: 'setSelectedBranch',
            payload: {},
          },
        ],
      );
    });
  });

  describe('setSelectedBranch', () => {
    it('commits SET_SELECTED_BRANCH mutation', () => {
      testAction(actions.setSelectedBranch, {}, {}, [
        {
          type: types.SET_SELECTED_BRANCH,
          payload: {},
        },
      ]);
    });
  });
});