summaryrefslogtreecommitdiff
path: root/spec/frontend/jobs/components/job_retry_forward_deployment_modal_spec.js
blob: 08973223c086f11eea8a3dc62db2cb9b608f6181 (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
import { GlLink, GlModal } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import JobRetryForwardDeploymentModal from '~/jobs/components/job_retry_forward_deployment_modal.vue';
import { JOB_RETRY_FORWARD_DEPLOYMENT_MODAL } from '~/jobs/constants';
import createStore from '~/jobs/store';
import job from '../mock_data';

describe('Job Retry Forward Deployment Modal', () => {
  let store;
  let wrapper;

  const retryOutdatedJobDocsUrl = 'url-to-docs';
  const findLink = () => wrapper.find(GlLink);
  const findModal = () => wrapper.find(GlModal);

  const createWrapper = ({ props = {}, provide = {}, stubs = {} } = {}) => {
    store = createStore();
    wrapper = shallowMount(JobRetryForwardDeploymentModal, {
      propsData: {
        modalId: 'modal-id',
        href: job.retry_path,
        ...props,
      },
      provide,
      store,
      stubs,
    });
  };

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

  beforeEach(createWrapper);

  describe('Modal configuration', () => {
    it('should display the correct messages', () => {
      const modal = findModal();
      expect(modal.attributes('title')).toMatch(JOB_RETRY_FORWARD_DEPLOYMENT_MODAL.title);
      expect(modal.text()).toMatch(JOB_RETRY_FORWARD_DEPLOYMENT_MODAL.info);
      expect(modal.text()).toMatch(JOB_RETRY_FORWARD_DEPLOYMENT_MODAL.areYouSure);
    });
  });

  describe('Modal docs help link', () => {
    it('should not display an info link when none is provided', () => {
      createWrapper();

      expect(findLink().exists()).toBe(false);
    });

    it('should display an info link when one is provided', () => {
      createWrapper({ provide: { retryOutdatedJobDocsUrl } });

      expect(findLink().attributes('href')).toBe(retryOutdatedJobDocsUrl);
      expect(findLink().text()).toMatch(JOB_RETRY_FORWARD_DEPLOYMENT_MODAL.moreInfo);
    });
  });

  describe('Modal actions', () => {
    beforeEach(createWrapper);

    it('should correctly configure the primary action', () => {
      expect(findModal().props('actionPrimary').attributes).toMatchObject([
        {
          'data-method': 'post',
          href: job.retry_path,
          variant: 'danger',
        },
      ]);
    });
  });
});