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

delete_application_spec.js « components « applications « admin « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20119b64952c305c4a8db2e5f3dee38642205ab3 (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
import { GlModal, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import DeleteApplication from '~/admin/applications/components/delete_application.vue';

const path = 'application/path/1';
const name = 'Application name';

jest.mock('~/lib/utils/csrf', () => ({ token: 'mock-csrf-token' }));

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

  const createComponent = () => {
    wrapper = shallowMount(DeleteApplication, {
      stubs: {
        GlSprintf,
      },
    });
  };

  const findModal = () => wrapper.findComponent(GlModal);
  const findForm = () => wrapper.find('form');

  beforeEach(() => {
    setFixtures(`
      <button class="js-application-delete-button" data-path="${path}" data-name="${name}">Destroy</button>
    `);

    createComponent();
  });

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

  describe('the modal component', () => {
    beforeEach(() => {
      wrapper.vm.$refs.deleteModal.show = jest.fn();
      document.querySelector('.js-application-delete-button').click();
    });

    it('displays the modal component', () => {
      const modal = findModal();

      expect(modal.exists()).toBe(true);
      expect(modal.props('title')).toBe('Confirm destroy application');
      expect(modal.text()).toBe(`Are you sure that you want to destroy ${name}`);
    });

    describe('form', () => {
      it('matches the snapshot', () => {
        expect(findForm().element).toMatchSnapshot();
      });

      describe('form submission', () => {
        let formSubmitSpy;

        beforeEach(() => {
          formSubmitSpy = jest.spyOn(wrapper.vm.$refs.deleteForm, 'submit');
          findModal().vm.$emit('primary');
        });

        it('submits the form on the modal primary action', () => {
          expect(formSubmitSpy).toHaveBeenCalled();
        });
      });
    });
  });
});