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

runner_delete_modal_spec.js « components « runner « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 606cc46c01851140ba575d903f9d56abde480afc (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
import { GlModal } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils';
import RunnerDeleteModal from '~/ci/runner/components/runner_delete_modal.vue';

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

  const findGlModal = () => wrapper.findComponent(GlModal);

  const createComponent = ({ props = {} } = {}, mountFn = shallowMount) => {
    wrapper = mountFn(RunnerDeleteModal, {
      attachTo: document.body,
      propsData: {
        runnerName: '#99 (AABBCCDD)',
        ...props,
      },
      attrs: {
        modalId: 'delete-runner-modal-99',
      },
    });
  };

  describe.each([null, 0, 1])('for %o runners', (managersCount) => {
    beforeEach(() => {
      createComponent({ props: { managersCount } });
    });

    it('Displays title', () => {
      expect(findGlModal().props('title')).toBe('Delete runner #99 (AABBCCDD)?');
    });

    it('Displays buttons', () => {
      expect(findGlModal().props('actionPrimary')).toMatchObject({
        text: 'Permanently delete runner',
      });
      expect(findGlModal().props('actionCancel')).toMatchObject({ text: 'Cancel' });
    });

    it('Displays contents', () => {
      expect(findGlModal().text()).toContain(
        'The runner will be permanently deleted and no longer available for projects or groups in the instance. Are you sure you want to continue?',
      );
    });
  });

  describe('for 2 runners', () => {
    beforeEach(() => {
      createComponent({ props: { managersCount: 2 } });
    });

    it('Displays title', () => {
      expect(findGlModal().props('title')).toBe('Delete 2 runners?');
    });

    it('Displays buttons', () => {
      expect(findGlModal().props('actionPrimary')).toMatchObject({
        text: 'Permanently delete 2 runners',
      });
      expect(findGlModal().props('actionCancel')).toMatchObject({ text: 'Cancel' });
    });

    it('Displays contents', () => {
      expect(findGlModal().text()).toContain(
        '2 runners will be permanently deleted and no longer available for projects or groups in the instance. Are you sure you want to continue?',
      );
    });
  });

  describe('When modal is confirmed by the user', () => {
    let hideModalSpy;

    beforeEach(() => {
      createComponent({}, mount);
      hideModalSpy = jest.spyOn(wrapper.vm.$refs.modal, 'hide').mockImplementation(() => {});
    });

    it('Modal gets hidden', () => {
      expect(hideModalSpy).toHaveBeenCalledTimes(0);

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

      expect(hideModalSpy).toHaveBeenCalledTimes(1);
    });
  });
});