diff options
Diffstat (limited to 'spec/frontend/terraform')
3 files changed, 114 insertions, 12 deletions
diff --git a/spec/frontend/terraform/components/empty_state_spec.js b/spec/frontend/terraform/components/empty_state_spec.js index c86160e18f3..1637ac2039c 100644 --- a/spec/frontend/terraform/components/empty_state_spec.js +++ b/spec/frontend/terraform/components/empty_state_spec.js @@ -1,4 +1,4 @@ -import { GlEmptyState, GlSprintf } from '@gitlab/ui'; +import { GlEmptyState, GlLink } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import EmptyState from '~/terraform/components/empty_state.vue'; @@ -8,19 +8,20 @@ describe('EmptyStateComponent', () => { const propsData = { image: '/image/path', }; + const docsUrl = '/help/user/infrastructure/terraform_state'; + const findEmptyState = () => wrapper.findComponent(GlEmptyState); + const findLink = () => wrapper.findComponent(GlLink); beforeEach(() => { - wrapper = shallowMount(EmptyState, { propsData, stubs: { GlEmptyState, GlSprintf } }); - return wrapper.vm.$nextTick(); - }); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; + wrapper = shallowMount(EmptyState, { propsData, stubs: { GlEmptyState, GlLink } }); }); it('should render content', () => { - expect(wrapper.find(GlEmptyState).exists()).toBe(true); + expect(findEmptyState().exists()).toBe(true); expect(wrapper.text()).toContain('Get started with Terraform'); }); + + it('should have a link to the GitLab managed Terraform States docs', () => { + expect(findLink().attributes('href')).toBe(docsUrl); + }); }); diff --git a/spec/frontend/terraform/components/init_command_modal_spec.js b/spec/frontend/terraform/components/init_command_modal_spec.js new file mode 100644 index 00000000000..dbdff899bac --- /dev/null +++ b/spec/frontend/terraform/components/init_command_modal_spec.js @@ -0,0 +1,79 @@ +import { GlLink, GlSprintf } from '@gitlab/ui'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import InitCommandModal from '~/terraform/components/init_command_modal.vue'; +import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue'; + +const accessTokensPath = '/path/to/access-tokens-page'; +const terraformApiUrl = 'https://gitlab.com/api/v4/projects/1'; +const username = 'username'; +const modalId = 'fake-modal-id'; +const stateName = 'production'; +const modalInfoCopyStr = `export GITLAB_ACCESS_TOKEN=<YOUR-ACCESS-TOKEN> +terraform init \\ + -backend-config="address=${terraformApiUrl}/${stateName}" \\ + -backend-config="lock_address=${terraformApiUrl}/${stateName}/lock" \\ + -backend-config="unlock_address=${terraformApiUrl}/${stateName}/lock" \\ + -backend-config="username=${username}" \\ + -backend-config="password=$GITLAB_ACCESS_TOKEN" \\ + -backend-config="lock_method=POST" \\ + -backend-config="unlock_method=DELETE" \\ + -backend-config="retry_wait_min=5" + `; + +describe('InitCommandModal', () => { + let wrapper; + + const propsData = { + modalId, + stateName, + }; + const provideData = { + accessTokensPath, + terraformApiUrl, + username, + }; + + const findExplanatoryText = () => wrapper.findByTestId('init-command-explanatory-text'); + const findLink = () => wrapper.findComponent(GlLink); + const findInitCommand = () => wrapper.findByTestId('terraform-init-command'); + const findCopyButton = () => wrapper.findComponent(ModalCopyButton); + + beforeEach(() => { + wrapper = shallowMountExtended(InitCommandModal, { + propsData, + provide: provideData, + stubs: { + GlSprintf, + }, + }); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + describe('on rendering', () => { + it('renders the explanatory text', () => { + expect(findExplanatoryText().text()).toContain('personal access token'); + }); + + it('renders the personal access token link', () => { + expect(findLink().attributes('href')).toBe(accessTokensPath); + }); + + it('renders the init command with the username and state name prepopulated', () => { + expect(findInitCommand().text()).toContain(username); + expect(findInitCommand().text()).toContain(stateName); + }); + + it('renders the copyToClipboard button', () => { + expect(findCopyButton().exists()).toBe(true); + }); + }); + + describe('when copy button is clicked', () => { + it('copies init command to clipboard', () => { + expect(findCopyButton().props('text')).toBe(modalInfoCopyStr); + }); + }); +}); diff --git a/spec/frontend/terraform/components/states_table_actions_spec.js b/spec/frontend/terraform/components/states_table_actions_spec.js index 61f6e9f0f7b..9d28e8ce294 100644 --- a/spec/frontend/terraform/components/states_table_actions_spec.js +++ b/spec/frontend/terraform/components/states_table_actions_spec.js @@ -3,6 +3,7 @@ import { createLocalVue, shallowMount } from '@vue/test-utils'; import VueApollo from 'vue-apollo'; import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; +import InitCommandModal from '~/terraform/components/init_command_modal.vue'; import StateActions from '~/terraform/components/states_table_actions.vue'; import lockStateMutation from '~/terraform/graphql/mutations/lock_state.mutation.graphql'; import removeStateMutation from '~/terraform/graphql/mutations/remove_state.mutation.graphql'; @@ -73,12 +74,14 @@ describe('StatesTableActions', () => { return wrapper.vm.$nextTick(); }; - const findActionsDropdown = () => wrapper.find(GlDropdown); + const findActionsDropdown = () => wrapper.findComponent(GlDropdown); + const findCopyBtn = () => wrapper.find('[data-testid="terraform-state-copy-init-command"]'); + const findCopyModal = () => wrapper.findComponent(InitCommandModal); const findLockBtn = () => wrapper.find('[data-testid="terraform-state-lock"]'); const findUnlockBtn = () => wrapper.find('[data-testid="terraform-state-unlock"]'); const findDownloadBtn = () => wrapper.find('[data-testid="terraform-state-download"]'); const findRemoveBtn = () => wrapper.find('[data-testid="terraform-state-remove"]'); - const findRemoveModal = () => wrapper.find(GlModal); + const findRemoveModal = () => wrapper.findComponent(GlModal); beforeEach(() => { return createComponent(); @@ -125,6 +128,25 @@ describe('StatesTableActions', () => { }); }); + describe('copy command button', () => { + it('displays a copy init command button', () => { + expect(findCopyBtn().text()).toBe('Copy Terraform init command'); + }); + + describe('when clicking the copy init command button', () => { + beforeEach(() => { + findCopyBtn().vm.$emit('click'); + + return waitForPromises(); + }); + + it('opens the modal', async () => { + expect(findCopyModal().exists()).toBe(true); + expect(findCopyModal().isVisible()).toBe(true); + }); + }); + }); + describe('download button', () => { it('displays a download button', () => { expect(findDownloadBtn().text()).toBe('Download JSON'); @@ -253,7 +275,7 @@ describe('StatesTableActions', () => { it('displays a remove modal', () => { expect(findRemoveModal().text()).toContain( - `You are about to remove the State file ${defaultProps.state.name}`, + `You are about to remove the state file ${defaultProps.state.name}`, ); }); |