Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-28 15:24:19 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-28 15:24:19 +0300
commit72cb3bee798655c2d370dfedf3c04665aaa43aa3 (patch)
tree4f57c272abd6067ed3dfdf38bca9220b3ea13bf5 /spec/frontend/terraform
parent70c1d0352e39c3c04caaa3082c3ffb4ad5c29b32 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/terraform')
-rw-r--r--spec/frontend/terraform/components/empty_state_spec.js23
-rw-r--r--spec/frontend/terraform/components/init_command_modal_spec.js72
2 files changed, 65 insertions, 30 deletions
diff --git a/spec/frontend/terraform/components/empty_state_spec.js b/spec/frontend/terraform/components/empty_state_spec.js
index db3de556244..293b59007c9 100644
--- a/spec/frontend/terraform/components/empty_state_spec.js
+++ b/spec/frontend/terraform/components/empty_state_spec.js
@@ -1,6 +1,7 @@
-import { GlEmptyState, GlLink } from '@gitlab/ui';
+import { GlEmptyState, GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import EmptyState from '~/terraform/components/empty_state.vue';
+import InitCommandModal from '~/terraform/components/init_command_modal.vue';
describe('EmptyStateComponent', () => {
let wrapper;
@@ -10,7 +11,9 @@ describe('EmptyStateComponent', () => {
};
const docsUrl = '/help/user/infrastructure/iac/terraform_state';
const findEmptyState = () => wrapper.findComponent(GlEmptyState);
- const findLink = () => wrapper.findComponent(GlLink);
+ const findButton = () => wrapper.findComponent(GlButton);
+ const findCopyModal = () => wrapper.findComponent(InitCommandModal);
+ const findCopyButton = () => wrapper.find('[data-testid="terraform-state-copy-init-command"]');
beforeEach(() => {
wrapper = shallowMount(EmptyState, { propsData });
@@ -22,7 +25,19 @@ describe('EmptyStateComponent', () => {
);
});
- it('should have a link to the GitLab managed Terraform states docs', () => {
- expect(findLink().attributes('href')).toBe(docsUrl);
+ it('buttons explore documentation should have a link to the GitLab managed Terraform states docs', () => {
+ expect(findButton().attributes('href')).toBe(docsUrl);
+ });
+
+ describe('copy command button', () => {
+ it('displays a copy init command button', () => {
+ expect(findCopyButton().text()).toBe('Copy Terraform init command');
+ });
+
+ it('opens the modal on copy button click', async () => {
+ await findCopyButton().vm.$emit('click');
+
+ expect(findCopyModal().isVisible()).toBe(true);
+ });
});
});
diff --git a/spec/frontend/terraform/components/init_command_modal_spec.js b/spec/frontend/terraform/components/init_command_modal_spec.js
index ca9aa26a776..4015482b81b 100644
--- a/spec/frontend/terraform/components/init_command_modal_spec.js
+++ b/spec/frontend/terraform/components/init_command_modal_spec.js
@@ -8,6 +8,7 @@ const terraformApiUrl = 'https://gitlab.com/api/v4/projects/1';
const username = 'username';
const modalId = 'fake-modal-id';
const stateName = 'aws/eu-central-1';
+const stateNamePlaceholder = '<YOUR-STATE-NAME>';
const stateNameEncoded = encodeURIComponent(stateName);
const modalInfoCopyStr = `export GITLAB_ACCESS_TOKEN=<YOUR-ACCESS-TOKEN>
terraform init \\
@@ -34,49 +35,68 @@ describe('InitCommandModal', () => {
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(() => {
+ const mountComponent = ({ props = propsData } = {}) => {
wrapper = shallowMountExtended(InitCommandModal, {
- propsData,
+ propsData: props,
provide: provideData,
stubs: {
GlSprintf,
},
});
- });
+ };
- describe('on rendering', () => {
- it('renders the explanatory text', () => {
- expect(findExplanatoryText().text()).toContain('personal access token');
- });
+ 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);
- it('renders the personal access token link', () => {
- expect(findLink().attributes('href')).toBe(accessTokensPath);
+ describe('when has stateName', () => {
+ beforeEach(() => {
+ mountComponent();
});
- describe('init command', () => {
- it('includes correct address', () => {
- expect(findInitCommand().text()).toContain(
- `-backend-config="address=${terraformApiUrl}/${stateNameEncoded}"`,
- );
+ 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('includes correct username', () => {
- expect(findInitCommand().text()).toContain(`-backend-config="username=${username}"`);
+
+ describe('init command', () => {
+ it('includes correct address', () => {
+ expect(findInitCommand().text()).toContain(
+ `-backend-config="address=${terraformApiUrl}/${stateNameEncoded}"`,
+ );
+ });
+ it('includes correct username', () => {
+ expect(findInitCommand().text()).toContain(`-backend-config="username=${username}"`);
+ });
+ });
+
+ it('renders the copyToClipboard button', () => {
+ expect(findCopyButton().exists()).toBe(true);
});
});
- 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);
+ });
});
});
+ describe('when has no stateName', () => {
+ beforeEach(() => {
+ mountComponent({ props: { modalId } });
+ });
- describe('when copy button is clicked', () => {
- it('copies init command to clipboard', () => {
- expect(findCopyButton().props('text')).toBe(modalInfoCopyStr);
+ describe('on rendering', () => {
+ it('includes correct address', () => {
+ expect(findInitCommand().text()).toContain(
+ `-backend-config="address=${terraformApiUrl}/${stateNamePlaceholder}"`,
+ );
+ });
});
});
});