Commit 06c996be authored by Enrique Alcantara's avatar Enrique Alcantara Committed by Tiger

Move accountId, externalId, and hasCredentials

to be part of the Vuex store state
parent 617f68c8
<script> <script>
import ServiceCredentialsForm from './service_credentials_form.vue'; import ServiceCredentialsForm from './service_credentials_form.vue';
import EksClusterConfigurationForm from './eks_cluster_configuration_form.vue'; import EksClusterConfigurationForm from './eks_cluster_configuration_form.vue';
import { mapState } from 'vuex';
export default { export default {
components: { components: {
...@@ -24,18 +25,9 @@ export default { ...@@ -24,18 +25,9 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
externalId: { },
type: String, computed: {
required: true, ...mapState(['hasCredentials']),
},
accountId: {
type: String,
required: true,
},
validCredentials: {
type: Boolean,
required: true,
},
}, },
}; };
</script> </script>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlFormInput, GlButton } from '@gitlab/ui'; import { GlFormInput, GlButton } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import _ from 'underscore'; import _ from 'underscore';
import { mapState } from 'vuex';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
export default { export default {
...@@ -11,14 +12,6 @@ export default { ...@@ -11,14 +12,6 @@ export default {
ClipboardButton, ClipboardButton,
}, },
props: { props: {
accountId: {
type: String,
required: true,
},
externalId: {
type: String,
required: true,
},
accountAndExternalIdsHelpPath: { accountAndExternalIdsHelpPath: {
type: String, type: String,
required: true, required: true,
...@@ -34,6 +27,7 @@ export default { ...@@ -34,6 +27,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(['accountId', 'externalId']),
accountAndExternalIdsHelpText() { accountAndExternalIdsHelpText() {
const escapedUrl = _.escape(this.accountAndExternalIdsHelpPath); const escapedUrl = _.escape(this.accountAndExternalIdsHelpPath);
......
...@@ -6,42 +6,39 @@ import createStore from './store'; ...@@ -6,42 +6,39 @@ import createStore from './store';
Vue.use(Vuex); Vue.use(Vuex);
export default el => { export default el => {
const { gitlabManagedClusterHelpPath, kubernetesIntegrationHelpPath } = el.dataset; const {
gitlabManagedClusterHelpPath,
kubernetesIntegrationHelpPath,
accountAndExternalIdsHelpPath,
createRoleArnHelpPath,
externalId,
accountId,
hasCredentials,
createCredentialsPath,
} = el.dataset;
return new Vue({ return new Vue({
el, el,
store: createStore(), store: createStore({
components: { initialState: {
CreateEksCluster, hasCredentials,
},
data() {
const {
gitlabManagedClusterHelpPath,
accountAndExternalIdsHelpPath,
createRoleArnHelpPath,
externalId,
accountId,
validCredentials,
} = document.querySelector(this.$options.el).dataset;
return {
gitlabManagedClusterHelpPath,
accountAndExternalIdsHelpPath,
createRoleArnHelpPath,
externalId, externalId,
accountId, accountId,
validCredentials, },
}; apiPaths: {
createCredentialsPath,
},
}),
components: {
CreateEksCluster,
}, },
render(createElement) { render(createElement) {
return createElement('create-eks-cluster', { return createElement('create-eks-cluster', {
props: { props: {
gitlabManagedClusterHelpPath: this.gitlabManagedClusterHelpPath, gitlabManagedClusterHelpPath,
accountAndExternalIdsHelpPath: this.accountAndExternalIdsHelpPath, kubernetesIntegrationHelpPath,
createRoleArnHelpPath: this.createRoleArnHelpPath, accountAndExternalIdsHelpPath,
externalId: this.externalId, createRoleArnHelpPath,
accountId: this.accountId,
validCredentials: this.validCredentials,
}, },
}); });
}, },
......
...@@ -8,12 +8,12 @@ import clusterDropdownStore from './cluster_dropdown'; ...@@ -8,12 +8,12 @@ import clusterDropdownStore from './cluster_dropdown';
import * as awsServices from '../services/aws_services_facade'; import * as awsServices from '../services/aws_services_facade';
const createStore = () => const createStore = ({ initialState }) =>
new Vuex.Store({ new Vuex.Store({
actions, actions,
getters, getters,
mutations, mutations,
state: state(), state: Object.assign(state(), initialState),
modules: { modules: {
roles: { roles: {
namespaced: true, namespaced: true,
......
...@@ -2,7 +2,11 @@ import { KUBERNETES_VERSIONS } from '../constants'; ...@@ -2,7 +2,11 @@ import { KUBERNETES_VERSIONS } from '../constants';
export default () => ({ export default () => ({
isValidatingCredentials: false, isValidatingCredentials: false,
validCredentials: false, hasCredentials: false,
invalidCredentials: false,
invalidCredentialsError: null,
accountId: '',
externalId: '',
clusterName: '', clusterName: '',
environmentScope: '*', environmentScope: '*',
......
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
'account-id' => Gitlab::CurrentSettings.eks_account_id, 'account-id' => Gitlab::CurrentSettings.eks_account_id,
'external-id' => @aws_role.role_external_id, 'external-id' => @aws_role.role_external_id,
'kubernetes-integration-help-path' => help_page_path('user/project/clusters/index'), 'kubernetes-integration-help-path' => help_page_path('user/project/clusters/index'),
'valid-credentials' => @aws_role.role_arn.present? } } 'has-credentials' => @aws_role.role_arn.present? } }
import { shallowMount } from '@vue/test-utils'; import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import CreateEksCluster from '~/create_cluster/eks_cluster/components/create_eks_cluster.vue'; import CreateEksCluster from '~/create_cluster/eks_cluster/components/create_eks_cluster.vue';
import EksClusterConfigurationForm from '~/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue'; import EksClusterConfigurationForm from '~/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue';
import ServiceCredentialsForm from '~/create_cluster/eks_cluster/components/service_credentials_form.vue'; import ServiceCredentialsForm from '~/create_cluster/eks_cluster/components/service_credentials_form.vue';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('CreateEksCluster', () => { describe('CreateEksCluster', () => {
let vm; let vm;
const accountId = 'accountId'; let state;
const externalId = 'externalId';
const gitlabManagedClusterHelpPath = 'gitlab-managed-cluster-help-path'; const gitlabManagedClusterHelpPath = 'gitlab-managed-cluster-help-path';
const accountAndExternalIdsHelpPath = 'account-and-external-id-help-path'; const accountAndExternalIdsHelpPath = 'account-and-external-id-help-path';
const createRoleArnHelpPath = 'role-arn-help-path'; const createRoleArnHelpPath = 'role-arn-help-path';
beforeEach(() => { beforeEach(() => {
state = { hasCredentials: false };
const store = new Vuex.Store({
state,
});
vm = shallowMount(CreateEksCluster, { vm = shallowMount(CreateEksCluster, {
propsData: { propsData: {
validCredentials: false,
accountId,
externalId,
gitlabManagedClusterHelpPath, gitlabManagedClusterHelpPath,
accountAndExternalIdsHelpPath, accountAndExternalIdsHelpPath,
createRoleArnHelpPath, createRoleArnHelpPath,
}, },
localVue,
store,
}); });
}); });
afterEach(() => vm.destroy()); afterEach(() => vm.destroy());
describe('when credentials are valid', () => { describe('when credentials are provided', () => {
beforeEach(() => { beforeEach(() => {
vm.setProps({ validCredentials: true }); state.hasCredentials = true;
}); });
it('displays eks cluster configuration form when credentials are valid', () => { it('displays eks cluster configuration form when credentials are valid', () => {
expect(vm.find(EksClusterConfigurationForm).exists()).toBe(true); expect(vm.find(EksClusterConfigurationForm).exists()).toBe(true);
}); });
it('provides gitlabManagedClusterHelpPath to eks cluster config form', () => {
expect(vm.find(EksClusterConfigurationForm).props('gitlabManagedClusterHelpPath')).toBe(
gitlabManagedClusterHelpPath,
);
});
}); });
describe('when credentials are invalid', () => { describe('when credentials are invalid', () => {
beforeEach(() => { beforeEach(() => {
vm.setProps({ validCredentials: false }); state.hasCredentials = false;
}); });
it('displays service credentials form', () => { it('displays service credentials form', () => {
...@@ -52,11 +53,6 @@ describe('CreateEksCluster', () => { ...@@ -52,11 +53,6 @@ describe('CreateEksCluster', () => {
}); });
describe('passes to the service credentials form', () => { describe('passes to the service credentials form', () => {
it('account id and external id', () => {
expect(vm.find(ServiceCredentialsForm).props('externalId')).toBe(externalId);
expect(vm.find(ServiceCredentialsForm).props('accountId')).toBe(accountId);
});
it('help url for account and external ids', () => { it('help url for account and external ids', () => {
expect(vm.find(ServiceCredentialsForm).props('accountAndExternalIdsHelpPath')).toBe( expect(vm.find(ServiceCredentialsForm).props('accountAndExternalIdsHelpPath')).toBe(
accountAndExternalIdsHelpPath, accountAndExternalIdsHelpPath,
......
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