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

runner_aws_deployments_modal_spec.js « runner_aws_deployments « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a9ba4946358df58ffb86d93342b65993dc31e4d7 (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
import { GlModal, GlFormRadio } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { getBaseURL, visitUrl } from '~/lib/utils/url_utility';
import { mockTracking } from 'helpers/tracking_helper';
import {
  CF_BASE_URL,
  TEMPLATES_BASE_URL,
  EASY_BUTTONS,
} from '~/vue_shared/components/runner_aws_deployments/constants';
import RunnerAwsDeploymentsModal from '~/vue_shared/components/runner_aws_deployments/runner_aws_deployments_modal.vue';

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

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

  const findModal = () => wrapper.findComponent(GlModal);
  const findEasyButtons = () => wrapper.findAllComponents(GlFormRadio);

  const createComponent = () => {
    wrapper = shallowMount(RunnerAwsDeploymentsModal, {
      propsData: {
        modalId: 'runner-aws-deployments-modal',
      },
    });
  };

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

  afterEach(() => {
    wrapper.destroy();
  });

  it('renders the modal', () => {
    expect(wrapper.element).toMatchSnapshot();
  });

  it('should contain all easy buttons', () => {
    expect(findEasyButtons()).toHaveLength(EASY_BUTTONS.length);
  });

  describe('first easy button', () => {
    it('should contain the correct description', () => {
      expect(findEasyButtons().at(0).text()).toContain(EASY_BUTTONS[0].description);
    });

    it('should contain the correct link', () => {
      const templateUrl = encodeURIComponent(TEMPLATES_BASE_URL + EASY_BUTTONS[0].templateName);
      const { stackName } = EASY_BUTTONS[0];
      const instanceUrl = encodeURIComponent(getBaseURL());
      const url = `${CF_BASE_URL}templateURL=${templateUrl}&stackName=${stackName}&param_3GITLABRunnerInstanceURL=${instanceUrl}`;

      findModal().vm.$emit('primary');

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

    it('should track an event when clicked', () => {
      const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);

      findModal().vm.$emit('primary');

      expect(trackingSpy).toHaveBeenCalledTimes(1);
      expect(trackingSpy).toHaveBeenCalledWith(undefined, 'template_clicked', {
        label: EASY_BUTTONS[0].stackName,
      });
    });
  });
});