debian-mirror-gitlab/spec/frontend/projects/components/shared/delete_button_spec.js

118 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { GlModal } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2021-03-08 18:12:59 +05:30
import { stubComponent } from 'helpers/stub_component';
2020-10-24 23:57:45 +05:30
import SharedDeleteButton from '~/projects/components/shared/delete_button.vue';
jest.mock('~/lib/utils/csrf', () => ({ token: 'test-csrf-token' }));
describe('Project remove modal', () => {
let wrapper;
const findFormElement = () => wrapper.find('form');
const findConfirmButton = () => wrapper.find('.js-modal-action-primary');
const findAuthenticityTokenInput = () => findFormElement().find('input[name=authenticity_token]');
const findModal = () => wrapper.find(GlModal);
2022-04-04 11:22:00 +05:30
const findTitle = () => wrapper.find('[data-testid="delete-alert-title"]');
const findAlertBody = () => wrapper.find('[data-testid="delete-alert-body"]');
2020-10-24 23:57:45 +05:30
const defaultProps = {
confirmPhrase: 'foo',
formPath: 'some/path',
2022-04-04 11:22:00 +05:30
isFork: false,
issuesCount: 1,
mergeRequestsCount: 2,
forksCount: 3,
starsCount: 4,
2020-10-24 23:57:45 +05:30
};
2022-04-04 11:22:00 +05:30
const createComponent = (data = {}, stubs = {}, props = {}) => {
2020-10-24 23:57:45 +05:30
wrapper = shallowMount(SharedDeleteButton, {
2022-04-04 11:22:00 +05:30
propsData: {
...defaultProps,
...props,
},
2020-10-24 23:57:45 +05:30
data: () => data,
stubs: {
2021-03-08 18:12:59 +05:30
GlModal: stubComponent(GlModal, {
template: `
<div>
<slot name="modal-title"></slot>
<slot></slot>
</div>`,
}),
...stubs,
2020-10-24 23:57:45 +05:30
},
});
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('intialized', () => {
beforeEach(() => {
createComponent();
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
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.formPath);
});
});
describe('when the user input does not match the confirmPhrase', () => {
beforeEach(() => {
2021-03-08 18:12:59 +05:30
createComponent({ userInput: 'bar' }, { GlModal });
2020-10-24 23:57:45 +05:30
});
it('the confirm button is disabled', () => {
expect(findConfirmButton().attributes('disabled')).toBe('true');
});
});
describe('when the user input matches the confirmPhrase', () => {
beforeEach(() => {
2021-03-08 18:12:59 +05:30
createComponent({ userInput: defaultProps.confirmPhrase }, { GlModal });
2020-10-24 23:57:45 +05:30
});
it('the confirm button is not disabled', () => {
expect(findConfirmButton().attributes('disabled')).toBe(undefined);
});
});
describe('when the modal is confirmed', () => {
beforeEach(() => {
createComponent();
findModal().vm.$emit('ok');
});
it('submits the form element', () => {
expect(findFormElement().element.submit).toHaveBeenCalled();
});
});
2022-04-04 11:22:00 +05:30
describe('when project is a fork', () => {
beforeEach(() => {
createComponent({}, {}, { isFork: true });
});
it('matches the fork title', () => {
expect(findTitle().text()).toEqual('You are about to delete this forked project containing:');
});
it('matches the fork body', () => {
expect(findAlertBody().attributes().message).toEqual(
'This process deletes the project repository and all related resources.',
);
});
});
2020-10-24 23:57:45 +05:30
});