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
|
import { GlButton, GlModal, GlLink } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { s__ } from '~/locale';
import PruneObjectsButton from '~/projects/prune_unreachable_objects_button.vue';
jest.mock('~/lib/utils/csrf', () => ({ token: 'test-csrf-token' }));
describe('Project remove modal', () => {
let wrapper;
const findFormElement = () => wrapper.find('form');
const findAuthenticityTokenInput = () => findFormElement().find('input[name=authenticity_token]');
const findModal = () => wrapper.findComponent(GlModal);
const findBtn = () => wrapper.findComponent(GlButton);
const defaultProps = {
pruneObjectsPath: 'prunepath',
pruneObjectsDocPath: 'prunedocspath',
};
const createComponent = () => {
wrapper = shallowMountExtended(PruneObjectsButton, {
propsData: defaultProps,
directives: {
GlModal: createMockDirective('gl-modal'),
},
});
};
describe('intialized', () => {
beforeEach(() => {
createComponent();
});
it('sets a csrf token on the authenticity form input', () => {
expect(findAuthenticityTokenInput().element.value).toEqual('test-csrf-token');
});
it('sets the form action to the provided path', () => {
expect(findFormElement().attributes('action')).toEqual(defaultProps.pruneObjectsPath);
});
it('sets the documentation link to the provided path', () => {
expect(findModal().findComponent(GlLink).attributes('href')).toEqual(
defaultProps.pruneObjectsDocPath,
);
});
it('button opens modal', () => {
const buttonModalDirective = getBinding(findBtn().element, 'gl-modal');
expect(findModal().props('modalId')).toBe(buttonModalDirective.value);
expect(findModal().text()).toContain(s__('UpdateProject|Are you sure you want to prune?'));
});
});
describe('when the modal is confirmed', () => {
beforeEach(() => {
createComponent();
findModal().vm.$emit('ok');
});
it('submits the form element', () => {
expect(findFormElement().element.submit).toHaveBeenCalled();
});
});
});
|