diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 21:09:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 21:09:44 +0300 |
commit | 2c156e3c7bbade01c36eee18327f1ced6eebea79 (patch) | |
tree | 115fa8dbf6bc05037378b380311d31acb805f54c /spec/frontend | |
parent | 8e129497b2565b8c595ef4f806d9a9595ca654e5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
3 files changed, 93 insertions, 45 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 index 25034dcf5ad..34d9ee733c4 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 @@ -13,6 +13,7 @@ localVue.use(Vuex); describe('EksClusterConfigurationForm', () => { let store; let actions; + let getters; let state; let rolesState; let regionsState; @@ -29,8 +30,7 @@ describe('EksClusterConfigurationForm', () => { let securityGroupsActions; let vm; - beforeEach(() => { - state = eksClusterFormState(); + const createStore = (config = {}) => { actions = { createCluster: jest.fn(), setClusterName: jest.fn(), @@ -64,29 +64,44 @@ describe('EksClusterConfigurationForm', () => { securityGroupsActions = { fetchItems: jest.fn(), }; + state = { + ...eksClusterFormState(), + ...config.initialState, + }; rolesState = { ...clusterDropdownStoreState(), + ...config.rolesState, }; regionsState = { ...clusterDropdownStoreState(), + ...config.regionsState, }; vpcsState = { ...clusterDropdownStoreState(), + ...config.vpcsState, }; subnetsState = { ...clusterDropdownStoreState(), + ...config.subnetsState, }; keyPairsState = { ...clusterDropdownStoreState(), + ...config.keyPairsState, }; securityGroupsState = { ...clusterDropdownStoreState(), + ...config.securityGroupsState, }; instanceTypesState = { ...clusterDropdownStoreState(), + ...config.instanceTypesState, + }; + getters = { + subnetValid: config?.getters?.subnetValid || (() => false), }; store = new Vuex.Store({ state, + getters, actions, modules: { vpcs: { @@ -125,9 +140,29 @@ describe('EksClusterConfigurationForm', () => { }, }, }); - }); + }; - beforeEach(() => { + const createValidStateStore = initialState => { + createStore({ + initialState: { + clusterName: 'cluster name', + environmentScope: '*', + selectedRegion: 'region', + selectedRole: 'role', + selectedKeyPair: 'key pair', + selectedVpc: 'vpc', + selectedSubnet: ['subnet 1', 'subnet 2'], + selectedSecurityGroup: 'group', + selectedInstanceType: 'small-1', + ...initialState, + }, + getters: { + subnetValid: () => true, + }, + }); + }; + + const buildWrapper = () => { vm = shallowMount(EksClusterConfigurationForm, { localVue, store, @@ -137,27 +172,17 @@ describe('EksClusterConfigurationForm', () => { externalLinkIcon: '', }, }); + }; + + beforeEach(() => { + createStore(); + buildWrapper(); }); afterEach(() => { vm.destroy(); }); - const setAllConfigurationFields = () => { - store.replaceState({ - ...state, - clusterName: 'cluster name', - environmentScope: '*', - selectedRegion: 'region', - selectedRole: 'role', - selectedKeyPair: 'key pair', - selectedVpc: 'vpc', - selectedSubnet: 'subnet', - selectedSecurityGroup: 'group', - selectedInstanceType: 'small-1', - }); - }; - const findCreateClusterButton = () => vm.find('.js-create-cluster'); const findClusterNameInput = () => vm.find('[id=eks-cluster-name]'); const findEnvironmentScopeInput = () => vm.find('[id=eks-environment-scope]'); @@ -310,12 +335,29 @@ describe('EksClusterConfigurationForm', () => { expect(findSubnetDropdown().props('items')).toBe(subnetsState.items); }); - it('sets SubnetDropdown hasErrors to true when loading subnets fails', () => { - subnetsState.loadingItemsError = new Error(); + it('displays a validation error in the subnet dropdown when loading subnets fails', () => { + createStore({ + subnetsState: { + loadingItemsError: new Error(), + }, + }); + buildWrapper(); - return Vue.nextTick().then(() => { - expect(findSubnetDropdown().props('hasErrors')).toEqual(true); + expect(findSubnetDropdown().props('hasErrors')).toEqual(true); + }); + + it('displays a validation error in the subnet dropdown when a single subnet is selected', () => { + createStore({ + initialState: { + selectedSubnet: ['subnet 1'], + }, }); + buildWrapper(); + + expect(findSubnetDropdown().props('hasErrors')).toEqual(true); + expect(findSubnetDropdown().props('errorMessage')).toEqual( + 'You should select at least two subnets', + ); }); it('disables SecurityGroupDropdown when no vpc is selected', () => { @@ -386,11 +428,7 @@ describe('EksClusterConfigurationForm', () => { }); it('cleans selected subnet', () => { - expect(actions.setSubnet).toHaveBeenCalledWith( - expect.anything(), - { subnet: null }, - undefined, - ); + expect(actions.setSubnet).toHaveBeenCalledWith(expect.anything(), { subnet: [] }, undefined); }); it('cleans selected security group', () => { @@ -464,11 +502,7 @@ describe('EksClusterConfigurationForm', () => { }); it('cleans selected subnet', () => { - expect(actions.setSubnet).toHaveBeenCalledWith( - expect.anything(), - { subnet: null }, - undefined, - ); + expect(actions.setSubnet).toHaveBeenCalledWith(expect.anything(), { subnet: [] }, undefined); }); it('cleans selected security group', () => { @@ -573,22 +607,19 @@ describe('EksClusterConfigurationForm', () => { }); describe('when all cluster configuration fields are set', () => { - beforeEach(() => { - setAllConfigurationFields(); - }); - it('enables create cluster button', () => { + createValidStateStore(); + buildWrapper(); expect(findCreateClusterButton().props('disabled')).toBe(false); }); }); describe('when at least one cluster configuration field is not set', () => { beforeEach(() => { - setAllConfigurationFields(); - store.replaceState({ - ...state, - clusterName: '', + createValidStateStore({ + clusterName: null, }); + buildWrapper(); }); it('disables create cluster button', () => { @@ -596,13 +627,12 @@ describe('EksClusterConfigurationForm', () => { }); }); - describe('when isCreatingCluster', () => { + describe('when is creating cluster', () => { beforeEach(() => { - setAllConfigurationFields(); - store.replaceState({ - ...state, + createValidStateStore({ isCreatingCluster: true, }); + buildWrapper(); }); it('sets create cluster button as loading', () => { diff --git a/spec/frontend/create_cluster/eks_cluster/store/getters_spec.js b/spec/frontend/create_cluster/eks_cluster/store/getters_spec.js new file mode 100644 index 00000000000..7c26aeb9b93 --- /dev/null +++ b/spec/frontend/create_cluster/eks_cluster/store/getters_spec.js @@ -0,0 +1,13 @@ +import { subnetValid } from '~/create_cluster/eks_cluster/store/getters'; + +describe('EKS Cluster Store Getters', () => { + describe('subnetValid', () => { + it('returns true if there are 2 or more selected subnets', () => { + expect(subnetValid({ selectedSubnet: [1, 2] })).toBe(true); + }); + + it.each([[[], [1]]])('returns false if there are 1 or less selected subnets', subnets => { + expect(subnetValid({ selectedSubnet: subnets })).toBe(false); + }); + }); +}); diff --git a/spec/frontend/diffs/components/app_spec.js b/spec/frontend/diffs/components/app_spec.js index 15f91871437..78e3ff4a60c 100644 --- a/spec/frontend/diffs/components/app_spec.js +++ b/spec/frontend/diffs/components/app_spec.js @@ -41,6 +41,7 @@ describe('diffs/components/app', () => { endpoint: TEST_ENDPOINT, endpointMetadata: `${TEST_HOST}/diff/endpointMetadata`, endpointBatch: `${TEST_HOST}/diff/endpointBatch`, + endpointCoverage: `${TEST_HOST}/diff/endpointCoverage`, projectPath: 'namespace/project', currentUser: {}, changesEmptyStateIllustration: '', @@ -95,6 +96,7 @@ describe('diffs/components/app', () => { jest.spyOn(wrapper.vm, 'fetchDiffFiles').mockImplementation(fetchResolver); jest.spyOn(wrapper.vm, 'fetchDiffFilesMeta').mockImplementation(fetchResolver); jest.spyOn(wrapper.vm, 'fetchDiffFilesBatch').mockImplementation(fetchResolver); + jest.spyOn(wrapper.vm, 'fetchCoverageFiles').mockImplementation(fetchResolver); jest.spyOn(wrapper.vm, 'setDiscussions').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'startRenderDiffsQueue').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'unwatchDiscussions').mockImplementation(() => {}); @@ -250,6 +252,7 @@ describe('diffs/components/app', () => { expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); expect(wrapper.vm.fetchDiffFilesMeta).not.toHaveBeenCalled(); expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled(); + expect(wrapper.vm.fetchCoverageFiles).toHaveBeenCalled(); expect(wrapper.vm.unwatchDiscussions).toHaveBeenCalled(); expect(wrapper.vm.diffFilesLength).toEqual(100); expect(wrapper.vm.unwatchRetrievingBatches).toHaveBeenCalled(); @@ -269,6 +272,7 @@ describe('diffs/components/app', () => { expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); expect(wrapper.vm.fetchDiffFilesMeta).toHaveBeenCalled(); expect(wrapper.vm.fetchDiffFilesBatch).toHaveBeenCalled(); + expect(wrapper.vm.fetchCoverageFiles).toHaveBeenCalled(); expect(wrapper.vm.unwatchDiscussions).toHaveBeenCalled(); expect(wrapper.vm.diffFilesLength).toEqual(100); expect(wrapper.vm.unwatchRetrievingBatches).toHaveBeenCalled(); @@ -286,6 +290,7 @@ describe('diffs/components/app', () => { expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); expect(wrapper.vm.fetchDiffFilesMeta).toHaveBeenCalled(); expect(wrapper.vm.fetchDiffFilesBatch).toHaveBeenCalled(); + expect(wrapper.vm.fetchCoverageFiles).toHaveBeenCalled(); expect(wrapper.vm.unwatchDiscussions).toHaveBeenCalled(); expect(wrapper.vm.diffFilesLength).toEqual(100); expect(wrapper.vm.unwatchRetrievingBatches).toHaveBeenCalled(); |