summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_merge_request_widget/components/terraform/terraform_plan_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/vue_merge_request_widget/components/terraform/terraform_plan_spec.js')
-rw-r--r--spec/frontend/vue_merge_request_widget/components/terraform/terraform_plan_spec.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/frontend/vue_merge_request_widget/components/terraform/terraform_plan_spec.js b/spec/frontend/vue_merge_request_widget/components/terraform/terraform_plan_spec.js
new file mode 100644
index 00000000000..3c9f6c2e165
--- /dev/null
+++ b/spec/frontend/vue_merge_request_widget/components/terraform/terraform_plan_spec.js
@@ -0,0 +1,93 @@
+import { GlLink, GlSprintf } from '@gitlab/ui';
+import { shallowMount } from '@vue/test-utils';
+import TerraformPlan from '~/vue_merge_request_widget/components/terraform/terraform_plan.vue';
+import {
+ invalidPlanWithName,
+ invalidPlanWithoutName,
+ validPlanWithName,
+ validPlanWithoutName,
+} from './mock_data';
+
+describe('TerraformPlan', () => {
+ let wrapper;
+
+ const findIcon = () => wrapper.find('[data-testid="change-type-icon"]');
+ const findLogButton = () => wrapper.find('[data-testid="terraform-report-link"]');
+
+ const mountWrapper = (propsData) => {
+ wrapper = shallowMount(TerraformPlan, { stubs: { GlLink, GlSprintf }, propsData });
+ };
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ describe('valid plan with job_name', () => {
+ beforeEach(() => {
+ mountWrapper({ plan: validPlanWithName });
+ });
+
+ it('displays a document icon', () => {
+ expect(findIcon().attributes('name')).toBe('doc-changes');
+ });
+
+ it('diplays the header text with a name', () => {
+ expect(wrapper.text()).toContain(`The job ${validPlanWithName.job_name} generated a report.`);
+ });
+
+ it('diplays the reported changes', () => {
+ expect(wrapper.text()).toContain(
+ `Reported Resource Changes: ${validPlanWithName.create} to add, ${validPlanWithName.update} to change, ${validPlanWithName.delete} to delete`,
+ );
+ });
+
+ it('renders button when url is found', () => {
+ expect(findLogButton().exists()).toBe(true);
+ expect(findLogButton().text()).toEqual('View full log');
+ });
+ });
+
+ describe('valid plan without job_name', () => {
+ beforeEach(() => {
+ mountWrapper({ plan: validPlanWithoutName });
+ });
+
+ it('diplays the header text without a name', () => {
+ expect(wrapper.text()).toContain('A report was generated in your pipelines.');
+ });
+ });
+
+ describe('invalid plan with job_name', () => {
+ beforeEach(() => {
+ mountWrapper({ plan: invalidPlanWithName });
+ });
+
+ it('displays a warning icon', () => {
+ expect(findIcon().attributes('name')).toBe('warning');
+ });
+
+ it('diplays the header text with a name', () => {
+ expect(wrapper.text()).toContain(
+ `The job ${invalidPlanWithName.job_name} failed to generate a report.`,
+ );
+ });
+
+ it('diplays generic error since report values are missing', () => {
+ expect(wrapper.text()).toContain('Generating the report caused an error.');
+ });
+ });
+
+ describe('invalid plan with out job_name', () => {
+ beforeEach(() => {
+ mountWrapper({ plan: invalidPlanWithoutName });
+ });
+
+ it('diplays the header text without a name', () => {
+ expect(wrapper.text()).toContain('A report failed to generate.');
+ });
+
+ it('does not render button because url is missing', () => {
+ expect(findLogButton().exists()).toBe(false);
+ });
+ });
+});