summaryrefslogtreecommitdiff
path: root/spec/frontend/create_cluster
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-09 15:05:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-09 15:05:58 +0000
commitcc6b394a063eb77c90505e4adca2e2da2e29c3a2 (patch)
tree94ec203489b9c800b832c7bd4f1b7aadc5a96958 /spec/frontend/create_cluster
parent0a850868dfb85086cba8320cee9dac4657dcae6c (diff)
downloadgitlab-ce-cc6b394a063eb77c90505e4adca2e2da2e29c3a2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/create_cluster')
-rw-r--r--spec/frontend/create_cluster/eks_cluster/components/cluster_form_dropdown_spec.js25
-rw-r--r--spec/frontend/create_cluster/eks_cluster/components/eks_cluster_configuration_form_spec.js126
-rw-r--r--spec/frontend/create_cluster/eks_cluster/components/role_name_dropdown_spec.js43
-rw-r--r--spec/frontend/create_cluster/eks_cluster/store/actions_spec.js22
-rw-r--r--spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js22
5 files changed, 173 insertions, 65 deletions
diff --git a/spec/frontend/create_cluster/eks_cluster/components/cluster_form_dropdown_spec.js b/spec/frontend/create_cluster/eks_cluster/components/cluster_form_dropdown_spec.js
index e873ef0b2fa..366c2fc7b26 100644
--- a/spec/frontend/create_cluster/eks_cluster/components/cluster_form_dropdown_spec.js
+++ b/spec/frontend/create_cluster/eks_cluster/components/cluster_form_dropdown_spec.js
@@ -7,12 +7,22 @@ import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidde
describe('ClusterFormDropdown', () => {
let vm;
+ const firstItem = { name: 'item 1', value: 1 };
+ const secondItem = { name: 'item 2', value: 2 };
+ const items = [firstItem, secondItem, { name: 'item 3', value: 3 }];
beforeEach(() => {
vm = shallowMount(ClusterFormDropdown);
});
afterEach(() => vm.destroy());
+ describe('when initial value is provided', () => {
+ it('sets selectedItem to initial value', () => {
+ vm.setProps({ items, value: secondItem.value });
+ expect(vm.find(DropdownButton).props('toggleText')).toEqual(secondItem.name);
+ });
+ });
+
describe('when no item is selected', () => {
it('displays placeholder text', () => {
const placeholder = 'placeholder';
@@ -24,18 +34,19 @@ describe('ClusterFormDropdown', () => {
});
describe('when an item is selected', () => {
- const selectedItem = { name: 'Name', value: 'value' };
-
beforeEach(() => {
- vm.setData({ selectedItem });
+ vm.setProps({ items });
+ vm.findAll('.js-dropdown-item')
+ .at(1)
+ .trigger('click');
});
it('displays selected item label', () => {
- expect(vm.find(DropdownButton).props('toggleText')).toEqual(selectedItem.name);
+ expect(vm.find(DropdownButton).props('toggleText')).toEqual(secondItem.name);
});
it('sets selected value to dropdown hidden input', () => {
- expect(vm.find(DropdownHiddenInput).props('value')).toEqual(selectedItem.value);
+ expect(vm.find(DropdownHiddenInput).props('value')).toEqual(secondItem.value);
});
});
@@ -124,9 +135,7 @@ describe('ClusterFormDropdown', () => {
});
it('it filters results by search query', () => {
- const secondItem = { name: 'second item' };
- const items = [{ name: 'first item' }, secondItem];
- const searchQuery = 'second';
+ const searchQuery = secondItem.name;
vm.setProps({ items });
vm.setData({ searchQuery });
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
index cc7c6735a80..df214442369 100644
--- 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
@@ -14,12 +14,16 @@ describe('EksClusterConfigurationForm', () => {
let store;
let actions;
let state;
+ let rolesState;
let regionsState;
let vpcsState;
let subnetsState;
+ let keyPairsState;
let vpcsActions;
+ let rolesActions;
let regionsActions;
let subnetsActions;
+ let keyPairsActions;
let vm;
beforeEach(() => {
@@ -28,16 +32,27 @@ describe('EksClusterConfigurationForm', () => {
setRegion: jest.fn(),
setVpc: jest.fn(),
setSubnet: jest.fn(),
+ setRole: jest.fn(),
+ setKeyPair: jest.fn(),
};
regionsActions = {
fetchItems: jest.fn(),
};
+ keyPairsActions = {
+ fetchItems: jest.fn(),
+ };
vpcsActions = {
fetchItems: jest.fn(),
};
subnetsActions = {
fetchItems: jest.fn(),
};
+ rolesActions = {
+ fetchItems: jest.fn(),
+ };
+ rolesState = {
+ ...clusterDropdownStoreState(),
+ };
regionsState = {
...clusterDropdownStoreState(),
};
@@ -47,6 +62,9 @@ describe('EksClusterConfigurationForm', () => {
subnetsState = {
...clusterDropdownStoreState(),
};
+ keyPairsState = {
+ ...clusterDropdownStoreState(),
+ };
store = new Vuex.Store({
state,
actions,
@@ -66,6 +84,16 @@ describe('EksClusterConfigurationForm', () => {
state: subnetsState,
actions: subnetsActions,
},
+ roles: {
+ namespaced: true,
+ state: rolesState,
+ actions: rolesActions,
+ },
+ keyPairs: {
+ namespaced: true,
+ state: keyPairsState,
+ actions: keyPairsActions,
+ },
},
});
});
@@ -82,13 +110,37 @@ describe('EksClusterConfigurationForm', () => {
});
const findRegionDropdown = () => vm.find(RegionDropdown);
+ const findKeyPairDropdown = () => vm.find('[field-id="eks-key-pair"]');
const findVpcDropdown = () => vm.find('[field-id="eks-vpc"]');
const findSubnetDropdown = () => vm.find('[field-id="eks-subnet"]');
+ const findRoleDropdown = () => vm.find('[field-id="eks-role"]');
describe('when mounted', () => {
it('fetches available regions', () => {
expect(regionsActions.fetchItems).toHaveBeenCalled();
});
+
+ it('fetches available roles', () => {
+ expect(rolesActions.fetchItems).toHaveBeenCalled();
+ });
+ });
+
+ it('sets isLoadingRoles to RoleDropdown loading property', () => {
+ rolesState.isLoadingItems = true;
+
+ return Vue.nextTick().then(() => {
+ expect(findRoleDropdown().props('loading')).toBe(rolesState.isLoadingItems);
+ });
+ });
+
+ it('sets roles to RoleDropdown items property', () => {
+ expect(findRoleDropdown().props('items')).toBe(rolesState.items);
+ });
+
+ it('sets RoleDropdown hasErrors to true when loading roles failed', () => {
+ rolesState.loadingItemsError = new Error();
+
+ expect(findRoleDropdown().props('hasErrors')).toEqual(true);
});
it('sets isLoadingRegions to RegionDropdown loading property', () => {
@@ -107,6 +159,36 @@ describe('EksClusterConfigurationForm', () => {
expect(findRegionDropdown().props('error')).toBe(regionsState.loadingItemsError);
});
+ it('disables KeyPairDropdown when no region is selected', () => {
+ expect(findKeyPairDropdown().props('disabled')).toBe(true);
+ });
+
+ it('enables KeyPairDropdown when no region is selected', () => {
+ state.selectedRegion = { name: 'west-1 ' };
+
+ return Vue.nextTick().then(() => {
+ expect(findKeyPairDropdown().props('disabled')).toBe(false);
+ });
+ });
+
+ it('sets isLoadingKeyPairs to KeyPairDropdown loading property', () => {
+ keyPairsState.isLoadingItems = true;
+
+ return Vue.nextTick().then(() => {
+ expect(findKeyPairDropdown().props('loading')).toBe(keyPairsState.isLoadingItems);
+ });
+ });
+
+ it('sets keyPairs to KeyPairDropdown items property', () => {
+ expect(findKeyPairDropdown().props('items')).toBe(keyPairsState.items);
+ });
+
+ it('sets KeyPairDropdown hasErrors to true when loading key pairs fails', () => {
+ keyPairsState.loadingItemsError = new Error();
+
+ expect(findKeyPairDropdown().props('hasErrors')).toEqual(true);
+ });
+
it('disables VpcDropdown when no region is selected', () => {
expect(findVpcDropdown().props('disabled')).toBe(true);
});
@@ -131,8 +213,10 @@ describe('EksClusterConfigurationForm', () => {
expect(findVpcDropdown().props('items')).toBe(vpcsState.items);
});
- it('sets loadingVpcsError to VpcDropdown hasErrors property', () => {
- expect(findVpcDropdown().props('hasErrors')).toBe(vpcsState.loadingItemsError);
+ it('sets VpcDropdown hasErrors to true when loading vpcs fails', () => {
+ vpcsState.loadingItemsError = new Error();
+
+ expect(findVpcDropdown().props('hasErrors')).toEqual(true);
});
it('disables SubnetDropdown when no vpc is selected', () => {
@@ -159,8 +243,10 @@ describe('EksClusterConfigurationForm', () => {
expect(findSubnetDropdown().props('items')).toBe(subnetsState.items);
});
- it('sets loadingSubnetsError to SubnetDropdown hasErrors property', () => {
- expect(findSubnetDropdown().props('hasErrors')).toBe(subnetsState.loadingItemsError);
+ it('sets SubnetDropdown hasErrors to true when loading subnets fails', () => {
+ subnetsState.loadingItemsError = new Error();
+
+ expect(findSubnetDropdown().props('hasErrors')).toEqual(true);
});
describe('when region is selected', () => {
@@ -177,6 +263,14 @@ describe('EksClusterConfigurationForm', () => {
it('fetches available vpcs', () => {
expect(vpcsActions.fetchItems).toHaveBeenCalledWith(expect.anything(), { region }, undefined);
});
+
+ it('fetches available key pairs', () => {
+ expect(keyPairsActions.fetchItems).toHaveBeenCalledWith(
+ expect.anything(),
+ { region },
+ undefined,
+ );
+ });
});
describe('when vpc is selected', () => {
@@ -206,4 +300,28 @@ describe('EksClusterConfigurationForm', () => {
expect(actions.setSubnet).toHaveBeenCalledWith(expect.anything(), { subnet }, undefined);
});
});
+
+ describe('when role is selected', () => {
+ const role = { name: 'admin' };
+
+ beforeEach(() => {
+ findRoleDropdown().vm.$emit('input', role);
+ });
+
+ it('dispatches setRole action', () => {
+ expect(actions.setRole).toHaveBeenCalledWith(expect.anything(), { role }, undefined);
+ });
+ });
+
+ describe('when key pair is selected', () => {
+ const keyPair = { name: 'key pair' };
+
+ beforeEach(() => {
+ findKeyPairDropdown().vm.$emit('input', keyPair);
+ });
+
+ it('dispatches setKeyPair action', () => {
+ expect(actions.setKeyPair).toHaveBeenCalledWith(expect.anything(), { keyPair }, undefined);
+ });
+ });
});
diff --git a/spec/frontend/create_cluster/eks_cluster/components/role_name_dropdown_spec.js b/spec/frontend/create_cluster/eks_cluster/components/role_name_dropdown_spec.js
deleted file mode 100644
index 657637c1b56..00000000000
--- a/spec/frontend/create_cluster/eks_cluster/components/role_name_dropdown_spec.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import { shallowMount } from '@vue/test-utils';
-
-import ClusterFormDropdown from '~/create_cluster/eks_cluster/components/cluster_form_dropdown.vue';
-import RoleNameDropdown from '~/create_cluster/eks_cluster/components/role_name_dropdown.vue';
-
-describe('RoleNameDropdown', () => {
- let vm;
-
- beforeEach(() => {
- vm = shallowMount(RoleNameDropdown);
- });
- afterEach(() => vm.destroy());
-
- it('renders a cluster-form-dropdown', () => {
- expect(vm.find(ClusterFormDropdown).exists()).toBe(true);
- });
-
- it('sets roles to cluster-form-dropdown items property', () => {
- const roles = [{ name: 'basic' }];
-
- vm.setProps({ roles });
-
- expect(vm.find(ClusterFormDropdown).props('items')).toEqual(roles);
- });
-
- it('sets a loading text', () => {
- expect(vm.find(ClusterFormDropdown).props('loadingText')).toEqual('Loading IAM Roles');
- });
-
- it('sets a placeholder', () => {
- expect(vm.find(ClusterFormDropdown).props('placeholder')).toEqual('Select role name');
- });
-
- it('sets an empty results text', () => {
- expect(vm.find(ClusterFormDropdown).props('emptyText')).toEqual('No IAM Roles found');
- });
-
- it('sets a search field placeholder', () => {
- expect(vm.find(ClusterFormDropdown).props('searchFieldPlaceholder')).toEqual(
- 'Search IAM Roles',
- );
- });
-});
diff --git a/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js b/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js
index 893c657e699..aa7ced81e0d 100644
--- a/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js
+++ b/spec/frontend/create_cluster/eks_cluster/store/actions_spec.js
@@ -2,24 +2,36 @@ import testAction from 'helpers/vuex_action_helper';
import createState from '~/create_cluster/eks_cluster/store/state';
import * as actions from '~/create_cluster/eks_cluster/store/actions';
-import { SET_REGION, SET_VPC, SET_SUBNET } from '~/create_cluster/eks_cluster/store/mutation_types';
+import {
+ SET_REGION,
+ SET_VPC,
+ SET_KEY_PAIR,
+ SET_SUBNET,
+ SET_ROLE,
+} from '~/create_cluster/eks_cluster/store/mutation_types';
describe('EKS Cluster Store Actions', () => {
let region;
let vpc;
let subnet;
+ let role;
+ let keyPair;
beforeEach(() => {
region = { name: 'regions-1' };
vpc = { name: 'vpc-1' };
subnet = { name: 'subnet-1' };
+ role = { name: 'role-1' };
+ keyPair = { name: 'key-pair-1' };
});
it.each`
- action | mutation | payload | payloadDescription
- ${'setRegion'} | ${SET_REGION} | ${{ region }} | ${'region'}
- ${'setVpc'} | ${SET_VPC} | ${{ vpc }} | ${'vpc'}
- ${'setSubnet'} | ${SET_SUBNET} | ${{ subnet }} | ${'subnet'}
+ action | mutation | payload | payloadDescription
+ ${'setRole'} | ${SET_ROLE} | ${{ role }} | ${'role'}
+ ${'setRegion'} | ${SET_REGION} | ${{ region }} | ${'region'}
+ ${'setKeyPair'} | ${SET_KEY_PAIR} | ${{ keyPair }} | ${'key pair'}
+ ${'setVpc'} | ${SET_VPC} | ${{ vpc }} | ${'vpc'}
+ ${'setSubnet'} | ${SET_SUBNET} | ${{ subnet }} | ${'subnet'}
`(`$action commits $mutation with $payloadDescription payload`, data => {
const { action, mutation, payload } = data;
diff --git a/spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js b/spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js
index 38199471f79..966406386ac 100644
--- a/spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js
+++ b/spec/frontend/create_cluster/eks_cluster/store/mutations_spec.js
@@ -1,4 +1,10 @@
-import { SET_REGION, SET_VPC, SET_SUBNET } from '~/create_cluster/eks_cluster/store/mutation_types';
+import {
+ SET_REGION,
+ SET_VPC,
+ SET_KEY_PAIR,
+ SET_SUBNET,
+ SET_ROLE,
+} 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';
@@ -7,20 +13,26 @@ describe('Create EKS cluster store mutations', () => {
let region;
let vpc;
let subnet;
+ let role;
+ let keyPair;
beforeEach(() => {
region = { name: 'regions-1' };
vpc = { name: 'vpc-1' };
subnet = { name: 'subnet-1' };
+ role = { name: 'role-1' };
+ keyPair = { name: 'key pair' };
state = createState();
});
it.each`
- mutation | mutatedProperty | payload | expectedValue | expectedValueDescription
- ${SET_REGION} | ${'selectedRegion'} | ${{ region }} | ${region} | ${'selected region payload'}
- ${SET_VPC} | ${'selectedVpc'} | ${{ vpc }} | ${vpc} | ${'selected vpc payload'}
- ${SET_SUBNET} | ${'selectedSubnet'} | ${{ subnet }} | ${subnet} | ${'selected sybnet payload'}
+ mutation | mutatedProperty | payload | expectedValue | expectedValueDescription
+ ${SET_ROLE} | ${'selectedRole'} | ${{ role }} | ${role} | ${'selected role payload'}
+ ${SET_REGION} | ${'selectedRegion'} | ${{ region }} | ${region} | ${'selected region payload'}
+ ${SET_KEY_PAIR} | ${'selectedKeyPair'} | ${{ keyPair }} | ${keyPair} | ${'selected key pair payload'}
+ ${SET_VPC} | ${'selectedVpc'} | ${{ vpc }} | ${vpc} | ${'selected vpc payload'}
+ ${SET_SUBNET} | ${'selectedSubnet'} | ${{ subnet }} | ${subnet} | ${'selected sybnet payload'}
`(`$mutation sets $mutatedProperty to $expectedValueDescription`, data => {
const { mutation, mutatedProperty, payload, expectedValue } = data;