diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 06:09:38 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 06:09:38 +0000 |
commit | ed9165c2abda1dca048a8d3cb8030d906c0bbb0c (patch) | |
tree | 226d7ad6b9abdc8d2534c3025b488ce9a754dee6 /spec/frontend/create_cluster | |
parent | b4b9b3854eddd2a4829113ebfc1812c3a332a7d9 (diff) | |
download | gitlab-ce-ed9165c2abda1dca048a8d3cb8030d906c0bbb0c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/create_cluster')
-rw-r--r-- | spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js | 76 | ||||
-rw-r--r-- | spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js | 97 |
2 files changed, 61 insertions, 112 deletions
diff --git a/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js b/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js index 8c3525207d6..c1ac3841136 100644 --- a/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js +++ b/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js @@ -1,16 +1,18 @@ import testAction from 'helpers/vuex_action_helper'; +import createState from '~/create_cluster/gke_cluster/store/state'; +import * as types from '~/create_cluster/gke_cluster/store/mutation_types'; import * as actions from '~/create_cluster/gke_cluster/store/actions'; -import { createStore } from '~/create_cluster/gke_cluster/store'; import gapi from '../helpers'; -import { selectedProjectMock, selectedZoneMock, selectedMachineTypeMock } from '../mock_data'; +import { + selectedProjectMock, + selectedZoneMock, + selectedMachineTypeMock, + gapiProjectsResponseMock, + gapiZonesResponseMock, + gapiMachineTypesResponseMock, +} from '../mock_data'; describe('GCP Cluster Dropdown Store Actions', () => { - let store; - - beforeEach(() => { - store = createStore(); - }); - describe('setProject', () => { it('should set project', done => { testAction( @@ -76,16 +78,16 @@ describe('GCP Cluster Dropdown Store Actions', () => { }); describe('fetchProjects', () => { - it('fetches projects from Google API', done => { - store - .dispatch('fetchProjects') - .then(() => { - expect(store.state.projects[0].projectId).toEqual(selectedProjectMock.projectId); - expect(store.state.projects[0].name).toEqual(selectedProjectMock.name); - - done(); - }) - .catch(done.fail); + it('fetches projects from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchProjects, + null, + state, + [{ type: types.SET_PROJECTS, payload: gapiProjectsResponseMock.projects }], + [], + ); }); }); @@ -112,28 +114,30 @@ describe('GCP Cluster Dropdown Store Actions', () => { }); describe('fetchZones', () => { - it('fetches zones from Google API', done => { - store - .dispatch('fetchZones') - .then(() => { - expect(store.state.zones[0].name).toEqual(selectedZoneMock); - - done(); - }) - .catch(done.fail); + it('fetches zones from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchZones, + null, + state, + [{ type: types.SET_ZONES, payload: gapiZonesResponseMock.items }], + [], + ); }); }); describe('fetchMachineTypes', () => { - it('fetches machine types from Google API', done => { - store - .dispatch('fetchMachineTypes') - .then(() => { - expect(store.state.machineTypes[0].name).toEqual(selectedMachineTypeMock); - - done(); - }) - .catch(done.fail); + it('fetches machine types from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchMachineTypes, + null, + state, + [{ type: types.SET_MACHINE_TYPES, payload: gapiMachineTypesResponseMock.items }], + [], + ); }); }); }); diff --git a/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js b/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js index 7ee6ff436e2..2a742b6ed8f 100644 --- a/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js +++ b/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js @@ -1,87 +1,32 @@ -import { createStore } from '~/create_cluster/gke_cluster/store'; +import createState from '~/create_cluster/gke_cluster/store/state'; import * as types from '~/create_cluster/gke_cluster/store/mutation_types'; +import mutations from '~/create_cluster/gke_cluster/store/mutations'; import { - selectedProjectMock, - selectedZoneMock, - selectedMachineTypeMock, gapiProjectsResponseMock, gapiZonesResponseMock, gapiMachineTypesResponseMock, } from '../mock_data'; describe('GCP Cluster Dropdown Store Mutations', () => { - let store; - - beforeEach(() => { - store = createStore(); - }); - - describe('SET_PROJECT', () => { - it('should set GCP project as selectedProject', () => { - const projectToSelect = gapiProjectsResponseMock.projects[0]; - - store.commit(types.SET_PROJECT, projectToSelect); - - expect(store.state.selectedProject.projectId).toEqual(selectedProjectMock.projectId); - expect(store.state.selectedProject.name).toEqual(selectedProjectMock.name); - }); - }); - - describe('SET_PROJECT_BILLING_STATUS', () => { - it('should set project billing status', () => { - store.commit(types.SET_PROJECT_BILLING_STATUS, true); - - expect(store.state.projectHasBillingEnabled).toBeTruthy(); - }); - }); - - describe('SET_ZONE', () => { - it('should set GCP zone as selectedZone', () => { - const zoneToSelect = gapiZonesResponseMock.items[0].name; - - store.commit(types.SET_ZONE, zoneToSelect); - - expect(store.state.selectedZone).toEqual(selectedZoneMock); - }); - }); - - describe('SET_MACHINE_TYPE', () => { - it('should set GCP machine type as selectedMachineType', () => { - const machineTypeToSelect = gapiMachineTypesResponseMock.items[0].name; - - store.commit(types.SET_MACHINE_TYPE, machineTypeToSelect); - - expect(store.state.selectedMachineType).toEqual(selectedMachineTypeMock); - }); - }); - - describe('SET_PROJECTS', () => { - it('should set Google API Projects response as projects', () => { - expect(store.state.projects.length).toEqual(0); - - store.commit(types.SET_PROJECTS, gapiProjectsResponseMock.projects); - - expect(store.state.projects.length).toEqual(gapiProjectsResponseMock.projects.length); - }); - }); - - describe('SET_ZONES', () => { - it('should set Google API Zones response as zones', () => { - expect(store.state.zones.length).toEqual(0); - - store.commit(types.SET_ZONES, gapiZonesResponseMock.items); - - expect(store.state.zones.length).toEqual(gapiZonesResponseMock.items.length); - }); - }); - - describe('SET_MACHINE_TYPES', () => { - it('should set Google API Machine Types response as machineTypes', () => { - expect(store.state.machineTypes.length).toEqual(0); - - store.commit(types.SET_MACHINE_TYPES, gapiMachineTypesResponseMock.items); - - expect(store.state.machineTypes.length).toEqual(gapiMachineTypesResponseMock.items.length); + describe.each` + mutation | stateProperty | mockData + ${types.SET_PROJECTS} | ${'projects'} | ${gapiProjectsResponseMock.projects} + ${types.SET_ZONES} | ${'zones'} | ${gapiZonesResponseMock.items} + ${types.SET_MACHINE_TYPES} | ${'machineTypes'} | ${gapiMachineTypesResponseMock.items} + ${types.SET_MACHINE_TYPE} | ${'selectedMachineType'} | ${gapiMachineTypesResponseMock.items[0].name} + ${types.SET_ZONE} | ${'selectedZone'} | ${gapiZonesResponseMock.items[0].name} + ${types.SET_PROJECT} | ${'selectedProject'} | ${gapiProjectsResponseMock.projects[0]} + ${types.SET_PROJECT_BILLING_STATUS} | ${'projectHasBillingEnabled'} | ${true} + ${types.SET_IS_VALIDATING_PROJECT_BILLING} | ${'isValidatingProjectBilling'} | ${true} + `('$mutation', ({ mutation, stateProperty, mockData }) => { + it(`should set the mutation payload to the ${stateProperty} state property`, () => { + const state = createState(); + + expect(state[stateProperty]).not.toBe(mockData); + + mutations[mutation](state, mockData); + + expect(state[stateProperty]).toBe(mockData); }); }); }); |