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

actions_spec.js « stores « mr_notes « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c6578453d853e8ce5926babb62058983e7d9ec2f (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
import MockAdapter from 'axios-mock-adapter';

import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils';

import { setEndpoints, setMrMetadata, fetchMrMetadata } from '~/mr_notes/stores/actions';
import mutationTypes from '~/mr_notes/stores/mutation_types';

describe('MR Notes Mutator Actions', () => {
  describe('setEndpoints', () => {
    it('should trigger the SET_ENDPOINTS state mutation', (done) => {
      const endpoints = { endpointA: 'a' };

      testAction(
        setEndpoints,
        endpoints,
        {},
        [
          {
            type: mutationTypes.SET_ENDPOINTS,
            payload: endpoints,
          },
        ],
        [],
        done,
      );
    });
  });

  describe('setMrMetadata', () => {
    it('should trigger the SET_MR_METADATA state mutation', async () => {
      const mrMetadata = { propA: 'a', propB: 'b' };

      await testAction(
        setMrMetadata,
        mrMetadata,
        {},
        [
          {
            type: mutationTypes.SET_MR_METADATA,
            payload: mrMetadata,
          },
        ],
        [],
      );
    });
  });

  describe('fetchMrMetadata', () => {
    const mrMetadata = { meta: true, data: 'foo' };
    const state = {
      endpoints: {
        metadata: 'metadata',
      },
    };
    let mock;

    beforeEach(() => {
      mock = new MockAdapter(axios);

      mock.onGet(state.endpoints.metadata).reply(200, mrMetadata);
    });

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

    it('should fetch the data from the API', async () => {
      await fetchMrMetadata({ state, dispatch: () => {} });

      await axios.waitForAll();

      expect(mock.history.get).toHaveLength(1);
      expect(mock.history.get[0].url).toBe(state.endpoints.metadata);
    });

    it('should set the fetched data into state', () => {
      return testAction(
        fetchMrMetadata,
        {},
        state,
        [],
        [
          {
            type: 'setMrMetadata',
            payload: mrMetadata,
          },
        ],
      );
    });
  });
});