summaryrefslogtreecommitdiff
path: root/spec/frontend/create_cluster/gke_cluster/stores/getters_spec.js
blob: 39106c3f6cae79e32b350c670b50a4be7185cb80 (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
import {
  hasProject,
  hasZone,
  hasMachineType,
  hasValidData,
} from '~/create_cluster/gke_cluster/store/getters';
import { selectedProjectMock, selectedZoneMock, selectedMachineTypeMock } from '../mock_data';

describe('GCP Cluster Dropdown Store Getters', () => {
  let state;

  describe('valid states', () => {
    beforeEach(() => {
      state = {
        projectHasBillingEnabled: true,
        selectedProject: selectedProjectMock,
        selectedZone: selectedZoneMock,
        selectedMachineType: selectedMachineTypeMock,
      };
    });

    describe('hasProject', () => {
      it('should return true when project is selected', () => {
        expect(hasProject(state)).toEqual(true);
      });
    });

    describe('hasZone', () => {
      it('should return true when zone is selected', () => {
        expect(hasZone(state)).toEqual(true);
      });
    });

    describe('hasMachineType', () => {
      it('should return true when machine type is selected', () => {
        expect(hasMachineType(state)).toEqual(true);
      });
    });

    describe('hasValidData', () => {
      it('should return true when a project, zone and machine type are selected', () => {
        expect(hasValidData(state, { hasZone: true, hasMachineType: true })).toEqual(true);
      });
    });
  });

  describe('invalid states', () => {
    beforeEach(() => {
      state = {
        selectedProject: {
          projectId: '',
          name: '',
        },
        selectedZone: '',
        selectedMachineType: '',
      };
    });

    describe('hasProject', () => {
      it('should return false when project is not selected', () => {
        expect(hasProject(state)).toEqual(false);
      });
    });

    describe('hasZone', () => {
      it('should return false when zone is not selected', () => {
        expect(hasZone(state)).toEqual(false);
      });
    });

    describe('hasMachineType', () => {
      it('should return false when machine type is not selected', () => {
        expect(hasMachineType(state)).toEqual(false);
      });
    });

    describe('hasValidData', () => {
      let getters;

      beforeEach(() => {
        getters = { hasZone: true, hasMachineType: true };
      });

      it('should return false when project is not billable', () => {
        state.projectHasBillingEnabled = false;

        expect(hasValidData(state, getters)).toEqual(false);
      });

      it('should return false when zone is not selected', () => {
        getters.hasZone = false;

        expect(hasValidData(state, getters)).toEqual(false);
      });

      it('should return false when machine type is not selected', () => {
        getters.hasMachineType = false;

        expect(hasValidData(state, getters)).toEqual(false);
      });
    });
  });
});