summaryrefslogtreecommitdiff
path: root/spec/frontend/clusters_list/store/mutations_spec.js
blob: 2ca1c20ad567c538fc2bbf4399e910bf803a6acb (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
import * as types from '~/clusters_list/store/mutation_types';
import getInitialState from '~/clusters_list/store/state';
import mutations from '~/clusters_list/store/mutations';
import { apiData } from '../mock_data';

describe('Admin statistics panel mutations', () => {
  let state;

  const paginationInformation = {
    nextPage: 1,
    page: 1,
    perPage: 20,
    previousPage: 1,
    total: apiData.clusters.length,
    totalPages: 1,
  };

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

  describe(`${types.SET_CLUSTERS_DATA}`, () => {
    it('sets clusters and pagination values', () => {
      mutations[types.SET_CLUSTERS_DATA](state, { data: apiData, paginationInformation });

      expect(state.clusters).toBe(apiData.clusters);
      expect(state.clustersPerPage).toBe(paginationInformation.perPage);
      expect(state.hasAncestorClusters).toBe(apiData.has_ancestor_clusters);
      expect(state.totalCulsters).toBe(paginationInformation.total);
    });
  });

  describe(`${types.SET_LOADING_CLUSTERS}`, () => {
    it('sets value to false', () => {
      expect(state.loadingClusters).toBe(true);

      mutations[types.SET_LOADING_CLUSTERS](state, false);

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

  describe(`${types.SET_LOADING_NODES}`, () => {
    it('sets value to false', () => {
      expect(state.loadingNodes).toBe(true);

      mutations[types.SET_LOADING_NODES](state, false);

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

  describe(`${types.SET_PAGE}`, () => {
    it('changes page value', () => {
      mutations[types.SET_PAGE](state, 123);

      expect(state.page).toBe(123);
    });
  });
});