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

actions_spec.js « cluster_dropdown « store « create_cluster « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 014b527161f3adbd6596a0f93ac4f250445f8720 (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
import testAction from 'helpers/vuex_action_helper';

import createState from '~/create_cluster/store/cluster_dropdown/state';
import * as types from '~/create_cluster/store/cluster_dropdown/mutation_types';
import actionsFactory from '~/create_cluster/store/cluster_dropdown/actions';

describe('Cluster dropdown Store Actions', () => {
  const items = [{ name: 'item 1' }];
  let fetchFn;
  let actions;

  beforeEach(() => {
    fetchFn = jest.fn();
    actions = actionsFactory(fetchFn);
  });

  describe('fetchItems', () => {
    describe('on success', () => {
      beforeEach(() => {
        fetchFn.mockResolvedValueOnce(items);
        actions = actionsFactory(fetchFn);
      });

      it('dispatches success with received items', () =>
        testAction(
          actions.fetchItems,
          null,
          createState(),
          [],
          [
            { type: 'requestItems' },
            {
              type: 'receiveItemsSuccess',
              payload: { items },
            },
          ],
        ));
    });

    describe('on failure', () => {
      const error = new Error('Could not fetch items');

      beforeEach(() => {
        fetchFn.mockRejectedValueOnce(error);
      });

      it('dispatches success with received items', () =>
        testAction(
          actions.fetchItems,
          null,
          createState(),
          [],
          [
            { type: 'requestItems' },
            {
              type: 'receiveItemsError',
              payload: { error },
            },
          ],
        ));
    });
  });

  describe('requestItems', () => {
    it(`commits ${types.REQUEST_ITEMS} mutation`, () =>
      testAction(actions.requestItems, null, createState(), [{ type: types.REQUEST_ITEMS }]));
  });

  describe('receiveItemsSuccess', () => {
    it(`commits ${types.RECEIVE_ITEMS_SUCCESS} mutation`, () =>
      testAction(actions.receiveItemsSuccess, { items }, createState(), [
        {
          type: types.RECEIVE_ITEMS_SUCCESS,
          payload: {
            items,
          },
        },
      ]));
  });

  describe('receiveItemsError', () => {
    it(`commits ${types.RECEIVE_ITEMS_ERROR} mutation`, () => {
      const error = new Error('Error fetching items');

      testAction(actions.receiveItemsError, { error }, createState(), [
        {
          type: types.RECEIVE_ITEMS_ERROR,
          payload: {
            error,
          },
        },
      ]);
    });
  });
});