Commit 91e7ea3e authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'do-not-create-store-gke-cluster-tests' into 'master'

Do not instantiate stores in GKE store tests

See merge request gitlab-org/gitlab!27222
parents daa3d9cc 5e602966
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 }],
[],
);
});
});
});
......
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);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment