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

terraform_plan_spec.js « terraform « components « vue_mr_widget « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cc68ba0d9df8c1695a67337cf0c8276aca17ff03 (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
92
93
94
95
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 Terraform report ${validPlanWithName.job_name} was generated in your pipelines.`,
      );
    });

    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 Terraform 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 Terraform report ${invalidPlanWithName.job_name} failed to generate.`,
      );
    });

    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 Terraform report failed to generate.');
    });

    it('does not render button because url is missing', () => {
      expect(findLogButton().exists()).toBe(false);
    });
  });
});