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

runner_aws_instructions_spec.js « instructions « runner_instructions « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6d8f895a1859349704e2b10bc64f21979b290000 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import {
  GlAccordion,
  GlAccordionItem,
  GlButton,
  GlFormRadio,
  GlFormRadioGroup,
  GlLink,
  GlSprintf,
} from '@gitlab/ui';
import { getBaseURL, visitUrl } from '~/lib/utils/url_utility';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { mockTracking } from 'helpers/tracking_helper';
import {
  AWS_README_URL,
  AWS_CF_BASE_URL,
  AWS_TEMPLATES_BASE_URL,
  AWS_EASY_BUTTONS,
} from '~/vue_shared/components/runner_instructions/constants';
import { __ } from '~/locale';

import RunnerAwsInstructions from '~/vue_shared/components/runner_instructions/instructions/runner_aws_instructions.vue';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';

jest.mock('~/lib/utils/url_utility', () => ({
  ...jest.requireActual('~/lib/utils/url_utility'),
  visitUrl: jest.fn(),
}));

const mockRegistrationToken = 'MY_TOKEN';

describe('RunnerAwsInstructions', () => {
  let wrapper;

  const findEasyButtonsRadioGroup = () => wrapper.findComponent(GlFormRadioGroup);
  const findEasyButtons = () => wrapper.findAllComponents(GlFormRadio);
  const findEasyButtonAt = (i) => findEasyButtons().at(i);
  const findLink = () => wrapper.findComponent(GlLink);
  const findModalCopyButton = () => wrapper.findComponent(ModalCopyButton);
  const findOkButton = () =>
    wrapper
      .findAllComponents(GlButton)
      .filter((w) => w.props('variant') === 'confirm')
      .at(0);
  const findCloseButton = () => wrapper.findByText(__('Close'));

  const createComponent = ({ props = {} } = {}) => {
    wrapper = shallowMountExtended(RunnerAwsInstructions, {
      propsData: {
        registrationToken: mockRegistrationToken,
        ...props,
      },
      stubs: {
        GlSprintf,
      },
    });
  };

  beforeEach(() => {
    createComponent();
  });

  it('should contain every button', () => {
    expect(findEasyButtons()).toHaveLength(AWS_EASY_BUTTONS.length);
  });

  const AWS_EASY_BUTTONS_PARAMS = AWS_EASY_BUTTONS.map((val, idx) => ({ ...val, idx }));

  describe.each(AWS_EASY_BUTTONS_PARAMS)(
    'easy button %#',
    ({ idx, description, moreDetails1, moreDetails2, templateName, stackName }) => {
      it('should contain button description', () => {
        const text = findEasyButtonAt(idx).text();

        expect(text).toContain(description);
        expect(text).toContain(moreDetails1);
        expect(text).toContain(moreDetails2);
      });

      it('should show more details', () => {
        const accordion = findEasyButtonAt(idx).findComponent(GlAccordion);
        const accordionItem = accordion.findComponent(GlAccordionItem);

        expect(accordion.props('headerLevel')).toBe(3);
        expect(accordionItem.props('title')).toBe(__('More Details'));
        expect(accordionItem.props('titleVisible')).toBe(__('Less Details'));
      });

      describe('when clicked', () => {
        let trackingSpy;

        beforeEach(() => {
          trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);

          findEasyButtonsRadioGroup().vm.$emit('input', idx);
          findOkButton().vm.$emit('click');
        });

        it('should contain the correct link', () => {
          const templateUrl = encodeURIComponent(AWS_TEMPLATES_BASE_URL + templateName);
          const instanceUrl = encodeURIComponent(getBaseURL());
          const url = `${AWS_CF_BASE_URL}templateURL=${templateUrl}&stackName=${stackName}&param_3GITLABRunnerInstanceURL=${instanceUrl}`;

          expect(visitUrl).toHaveBeenCalledTimes(1);
          expect(visitUrl).toHaveBeenCalledWith(url, true);
        });

        it('should track an event when clicked', () => {
          expect(trackingSpy).toHaveBeenCalledTimes(1);
          expect(trackingSpy).toHaveBeenCalledWith(undefined, 'template_clicked', {
            label: stackName,
          });
        });
      });
    },
  );

  it('displays link with more information', () => {
    expect(findLink().attributes('href')).toBe(AWS_README_URL);
  });

  it('shows registration token and copy button', () => {
    const token = wrapper.findByText(mockRegistrationToken);

    expect(token.exists()).toBe(true);
    expect(token.element.tagName).toBe('PRE');

    expect(findModalCopyButton().props('text')).toBe(mockRegistrationToken);
  });

  it('does not show registration token and copy button when token is not present', () => {
    createComponent({ props: { registrationToken: null } });

    expect(wrapper.find('pre').exists()).toBe(false);
    expect(findModalCopyButton().exists()).toBe(false);
  });

  it('triggers the modal to close', () => {
    findCloseButton().vm.$emit('click');

    expect(wrapper.emitted('close')).toHaveLength(1);
  });
});