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

user_operation_confirmation_modal_spec.js « components « users « admin « pages « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3a37a255cd4ea6107a4de03f94dc89981cd436b (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
import { shallowMount } from '@vue/test-utils';
import { GlModal } from '@gitlab/ui';
import UserOperationConfirmationModal from '~/pages/admin/users/components/user_operation_confirmation_modal.vue';

describe('User Operation confirmation modal', () => {
  let wrapper;

  const createComponent = (props = {}) => {
    wrapper = shallowMount(UserOperationConfirmationModal, {
      propsData: {
        title: 'title',
        content: 'content',
        action: 'action',
        url: '/url',
        username: 'username',
        csrfToken: 'csrf',
        method: 'method',
        ...props,
      },
    });
  };

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

  it('renders modal with form included', () => {
    createComponent();
    expect(wrapper.element).toMatchSnapshot();
  });

  it('closing modal with ok button triggers form submit', () => {
    createComponent();
    const form = wrapper.find('form');
    jest.spyOn(form.element, 'submit').mockReturnValue();
    wrapper.find(GlModal).vm.$emit('ok');
    return wrapper.vm.$nextTick().then(() => {
      expect(form.element.submit).toHaveBeenCalled();
      expect(form.element.action).toContain(wrapper.props('url'));
      expect(new FormData(form.element).get('authenticity_token')).toEqual(
        wrapper.props('csrfToken'),
      );
    });
  });
});