summaryrefslogtreecommitdiff
path: root/spec/frontend/create_cluster/eks_cluster/components/create_eks_cluster_spec.js
blob: 4bf3ac430f5f063bdd53fa3e801c2b1af2a8b4fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';

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 ServiceCredentialsForm from '~/create_cluster/eks_cluster/components/service_credentials_form.vue';

const localVue = createLocalVue();
localVue.use(Vuex);

describe('CreateEksCluster', () => {
  let vm;
  let state;
  const gitlabManagedClusterHelpPath = 'gitlab-managed-cluster-help-path';
  const accountAndExternalIdsHelpPath = 'account-and-external-id-help-path';
  const createRoleArnHelpPath = 'role-arn-help-path';
  const kubernetesIntegrationHelpPath = 'kubernetes-integration';
  const externalLinkIcon = 'external-link';

  beforeEach(() => {
    state = { hasCredentials: false };
    const store = new Vuex.Store({
      state,
    });

    vm = shallowMount(CreateEksCluster, {
      propsData: {
        gitlabManagedClusterHelpPath,
        accountAndExternalIdsHelpPath,
        createRoleArnHelpPath,
        externalLinkIcon,
        kubernetesIntegrationHelpPath,
      },
      localVue,
      store,
    });
  });
  afterEach(() => vm.destroy());

  describe('when credentials are provided', () => {
    beforeEach(() => {
      state.hasCredentials = true;
    });

    it('displays eks cluster configuration form when credentials are valid', () => {
      expect(vm.find(EksClusterConfigurationForm).exists()).toBe(true);
    });

    describe('passes to the cluster configuration form', () => {
      it('help url for kubernetes integration documentation', () => {
        expect(vm.find(EksClusterConfigurationForm).props('gitlabManagedClusterHelpPath')).toBe(
          gitlabManagedClusterHelpPath,
        );
      });

      it('help url for gitlab managed cluster documentation', () => {
        expect(vm.find(EksClusterConfigurationForm).props('kubernetesIntegrationHelpPath')).toBe(
          kubernetesIntegrationHelpPath,
        );
      });
    });
  });

  describe('when credentials are invalid', () => {
    beforeEach(() => {
      state.hasCredentials = false;
    });

    it('displays service credentials form', () => {
      expect(vm.find(ServiceCredentialsForm).exists()).toBe(true);
    });

    describe('passes to the service credentials form', () => {
      it('help url for account and external ids', () => {
        expect(vm.find(ServiceCredentialsForm).props('accountAndExternalIdsHelpPath')).toBe(
          accountAndExternalIdsHelpPath,
        );
      });

      it('external link icon', () => {
        expect(vm.find(ServiceCredentialsForm).props('externalLinkIcon')).toBe(externalLinkIcon);
      });

      it('help url to create a role ARN', () => {
        expect(vm.find(ServiceCredentialsForm).props('createRoleArnHelpPath')).toBe(
          createRoleArnHelpPath,
        );
      });
    });
  });
});