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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/create_cluster/eks_cluster')
-rw-r--r--spec/frontend/create_cluster/eks_cluster/components/eks_cluster_configuration_form_spec.js62
-rw-r--r--spec/frontend/create_cluster/eks_cluster/components/region_dropdown_spec.js64
-rw-r--r--spec/frontend/create_cluster/eks_cluster/store/actions_spec.js88
-rw-r--r--spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js36
4 files changed, 250 insertions, 0 deletions
diff --git a/spec/frontend/create_cluster/eks_cluster/components/eks_cluster_configuration_form_spec.js b/spec/frontend/create_cluster/eks_cluster/components/eks_cluster_configuration_form_spec.js
new file mode 100644
index 00000000000..57f7cbab2c2
--- /dev/null
+++ b/spec/frontend/create_cluster/eks_cluster/components/eks_cluster_configuration_form_spec.js
@@ -0,0 +1,62 @@
+import { shallowMount, createLocalVue } from '@vue/test-utils';
+import Vuex from 'vuex';
+import EksClusterConfigurationForm from '~/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue';
+import RegionDropdown from '~/create_cluster/eks_cluster/components/region_dropdown.vue';
+
+const localVue = createLocalVue();
+localVue.use(Vuex);
+
+describe('EksClusterConfigurationForm', () => {
+ let store;
+ let actions;
+ let state;
+
+ beforeEach(() => {
+ actions = {
+ fetchRegions: jest.fn(),
+ };
+ state = {
+ regions: [{ name: 'region 1' }],
+ isLoadingRegions: false,
+ loadingRegionsError: { message: '' },
+ };
+ store = new Vuex.Store({
+ state,
+ actions,
+ });
+ });
+
+ const buildVM = (props = {}) =>
+ shallowMount(EksClusterConfigurationForm, {
+ propsData: props,
+ localVue,
+ store,
+ });
+
+ describe('when mounted', () => {
+ it('fetches available regions', () => {
+ buildVM();
+ expect(actions.fetchRegions).toHaveBeenCalled();
+ });
+ });
+
+ it('sets isLoadingRegions to RegionDropdown loading property', () => {
+ state.isLoadingRegions = true;
+
+ const vm = buildVM();
+
+ expect(vm.find(RegionDropdown).props('loading')).toEqual(state.isLoadingRegions);
+ });
+
+ it('sets regions to RegionDropdown regions property', () => {
+ const vm = buildVM();
+
+ expect(vm.find(RegionDropdown).props('regions')).toEqual(state.regions);
+ });
+
+ it('sets loadingRegionsError to RegionDropdown error property', () => {
+ const vm = buildVM();
+
+ expect(vm.find(RegionDropdown).props('error')).toEqual(state.loadingRegionsError);
+ });
+});
diff --git a/spec/frontend/create_cluster/eks_cluster/components/region_dropdown_spec.js b/spec/frontend/create_cluster/eks_cluster/components/region_dropdown_spec.js
new file mode 100644
index 00000000000..1d553159628
--- /dev/null
+++ b/spec/frontend/create_cluster/eks_cluster/components/region_dropdown_spec.js
@@ -0,0 +1,64 @@
+import { shallowMount } from '@vue/test-utils';
+
+import ClusterFormDropdown from '~/create_cluster/eks_cluster/components/cluster_form_dropdown.vue';
+import RegionDropdown from '~/create_cluster/eks_cluster/components/region_dropdown.vue';
+
+describe('RegionDropdown', () => {
+ const buildVM = (props = {}) =>
+ shallowMount(RegionDropdown, {
+ propsData: props,
+ });
+
+ it('renders a cluster-form-dropdown', () => {
+ expect(
+ buildVM()
+ .find(ClusterFormDropdown)
+ .exists(),
+ ).toBe(true);
+ });
+
+ it('sets regions to cluster-form-dropdown items property', () => {
+ const regions = [{ name: 'basic' }];
+ const vm = buildVM({ regions });
+
+ expect(vm.find(ClusterFormDropdown).props('items')).toEqual(regions);
+ });
+
+ it('sets a loading text', () => {
+ const vm = buildVM();
+
+ expect(vm.find(ClusterFormDropdown).props('loadingText')).toEqual('Loading Regions');
+ });
+
+ it('sets a placeholder', () => {
+ const vm = buildVM();
+
+ expect(vm.find(ClusterFormDropdown).props('placeholder')).toEqual('Select a region');
+ });
+
+ it('sets an empty results text', () => {
+ const vm = buildVM();
+
+ expect(vm.find(ClusterFormDropdown).props('emptyText')).toEqual('No region found');
+ });
+
+ it('sets a search field placeholder', () => {
+ const vm = buildVM();
+
+ expect(vm.find(ClusterFormDropdown).props('searchFieldPlaceholder')).toEqual('Search regions');
+ });
+
+ it('sets hasErrors property', () => {
+ const vm = buildVM({ error: {} });
+
+ expect(vm.find(ClusterFormDropdown).props('hasErrors')).toEqual(true);
+ });
+
+ it('sets an error message', () => {
+ const vm = buildVM();
+
+ expect(vm.find(ClusterFormDropdown).props('errorMessage')).toEqual(
+ 'Could not load regions from your AWS account',
+ );
+ });
+});
diff --git a/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js b/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js
new file mode 100644
index 00000000000..a575fd0d8be
--- /dev/null
+++ b/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js
@@ -0,0 +1,88 @@
+import testAction from 'helpers/vuex_action_helper';
+
+import * as awsServicesFacade from '~/create_cluster/eks_cluster/services/aws_services_facade';
+import createState from '~/create_cluster/eks_cluster/store/state';
+import * as types from '~/create_cluster/eks_cluster/store/mutation_types';
+import * as actions from '~/create_cluster/eks_cluster/store/actions';
+
+describe('EKS Cluster Store Actions', () => {
+ const regions = [{ name: 'region 1' }];
+
+ describe('fetchRegions', () => {
+ describe('on success', () => {
+ beforeEach(() => {
+ jest.spyOn(awsServicesFacade, 'fetchRegions').mockResolvedValueOnce(regions);
+ });
+
+ it('dispatches success with received regions', () =>
+ testAction(
+ actions.fetchRegions,
+ null,
+ createState(),
+ [],
+ [
+ { type: 'requestRegions' },
+ {
+ type: 'receiveRegionsSuccess',
+ payload: { regions },
+ },
+ ],
+ ));
+ });
+
+ describe('on failure', () => {
+ const error = new Error('Could not fetch regions');
+
+ beforeEach(() => {
+ jest.spyOn(awsServicesFacade, 'fetchRegions').mockRejectedValueOnce(error);
+ });
+
+ it('dispatches success with received regions', () =>
+ testAction(
+ actions.fetchRegions,
+ null,
+ createState(),
+ [],
+ [
+ { type: 'requestRegions' },
+ {
+ type: 'receiveRegionsError',
+ payload: { error },
+ },
+ ],
+ ));
+ });
+ });
+
+ describe('requestRegions', () => {
+ it(`commits ${types.REQUEST_REGIONS} mutation`, () =>
+ testAction(actions.requestRegions, null, createState(), [{ type: types.REQUEST_REGIONS }]));
+ });
+
+ describe('receiveRegionsSuccess', () => {
+ it(`commits ${types.RECEIVE_REGIONS_SUCCESS} mutation`, () =>
+ testAction(actions.receiveRegionsSuccess, { regions }, createState(), [
+ {
+ type: types.RECEIVE_REGIONS_SUCCESS,
+ payload: {
+ regions,
+ },
+ },
+ ]));
+ });
+
+ describe('receiveRegionsError', () => {
+ it(`commits ${types.RECEIVE_REGIONS_ERROR} mutation`, () => {
+ const error = new Error('Error fetching regions');
+
+ testAction(actions.receiveRegionsError, { error }, createState(), [
+ {
+ type: types.RECEIVE_REGIONS_ERROR,
+ payload: {
+ error,
+ },
+ },
+ ]);
+ });
+ });
+});
diff --git a/spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js b/spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js
new file mode 100644
index 00000000000..e9121f0c449
--- /dev/null
+++ b/spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js
@@ -0,0 +1,36 @@
+import {
+ REQUEST_REGIONS,
+ RECEIVE_REGIONS_ERROR,
+ RECEIVE_REGIONS_SUCCESS,
+} from '~/create_cluster/eks_cluster/store/mutation_types';
+import createState from '~/create_cluster/eks_cluster/store/state';
+import mutations from '~/create_cluster/eks_cluster/store/mutations';
+
+describe('Create EKS cluster store mutations', () => {
+ let state;
+ let emptyPayload;
+ let regions;
+ let error;
+
+ beforeEach(() => {
+ emptyPayload = {};
+ regions = [{ name: 'regions-1' }];
+ error = new Error('could not load error');
+ state = createState();
+ });
+
+ it.each`
+ mutation | mutatedProperty | payload | expectedValue | expectedValueDescription
+ ${REQUEST_REGIONS} | ${'isLoadingRegions'} | ${emptyPayload} | ${true} | ${true}
+ ${REQUEST_REGIONS} | ${'loadingRegionsError'} | ${emptyPayload} | ${null} | ${null}
+ ${RECEIVE_REGIONS_SUCCESS} | ${'isLoadingRegions'} | ${{ regions }} | ${false} | ${false}
+ ${RECEIVE_REGIONS_SUCCESS} | ${'regions'} | ${{ regions }} | ${regions} | ${'regions payload'}
+ ${RECEIVE_REGIONS_ERROR} | ${'isLoadingRegions'} | ${{ error }} | ${false} | ${false}
+ ${RECEIVE_REGIONS_ERROR} | ${'error'} | ${{ error }} | ${error} | ${'received error object'}
+ `(`$mutation sets $mutatedProperty to $expectedValueDescription`, data => {
+ const { mutation, mutatedProperty, payload, expectedValue } = data;
+
+ mutations[mutation](state, payload);
+ expect(state[mutatedProperty]).toBe(expectedValue);
+ });
+});