2021-05-21 09:10:16 +00:00
|
|
|
import { GlButton, GlModal } from '@gitlab/ui';
|
2021-03-11 09:09:36 +00:00
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
2021-05-21 09:10:16 +00:00
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2021-03-11 09:09:36 +00:00
|
|
|
import CsvImportModal from '~/issuable/components/csv_import_modal.vue';
|
|
|
|
|
|
|
|
jest.mock('~/lib/utils/csrf', () => ({ token: 'mock-csrf-token' }));
|
|
|
|
|
|
|
|
describe('CsvImportModal', () => {
|
|
|
|
let wrapper;
|
|
|
|
let formSubmitSpy;
|
|
|
|
|
|
|
|
function createComponent(options = {}) {
|
|
|
|
const { injectedProperties = {}, props = {} } = options;
|
2021-05-21 09:10:16 +00:00
|
|
|
return mountExtended(CsvImportModal, {
|
|
|
|
propsData: {
|
|
|
|
modalId: 'csv-import-modal',
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
...injectedProperties,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
GlModal: stubComponent(GlModal, {
|
|
|
|
template: '<div><slot></slot><slot name="modal-footer"></slot></div>',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
});
|
2021-03-11 09:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
formSubmitSpy = jest.spyOn(HTMLFormElement.prototype, 'submit').mockImplementation();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
const findModal = () => wrapper.findComponent(GlModal);
|
2021-05-21 09:10:16 +00:00
|
|
|
const findPrimaryButton = () => wrapper.findComponent(GlButton);
|
|
|
|
const findForm = () => wrapper.find('form');
|
|
|
|
const findFileInput = () => wrapper.findByLabelText('Upload CSV file');
|
2021-03-11 09:09:36 +00:00
|
|
|
const findAuthenticityToken = () => new FormData(findForm().element).get('authenticity_token');
|
|
|
|
|
|
|
|
describe('template', () => {
|
2021-10-05 15:12:53 +00:00
|
|
|
it('passes correct title props to modal', () => {
|
2021-03-11 09:09:36 +00:00
|
|
|
wrapper = createComponent();
|
2021-10-05 15:12:53 +00:00
|
|
|
expect(findModal().props('title')).toContain('Import issues');
|
2021-03-11 09:09:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays a note about the maximum allowed file size', () => {
|
|
|
|
const maxAttachmentSize = 500;
|
|
|
|
wrapper = createComponent({ injectedProperties: { maxAttachmentSize } });
|
|
|
|
expect(findModal().text()).toContain(`The maximum file size allowed is ${maxAttachmentSize}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('form', () => {
|
|
|
|
const importCsvIssuesPath = 'gitlab-org/gitlab-test/-/issues/import_csv';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({ injectedProperties: { importCsvIssuesPath } });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the form with the correct action and inputs', () => {
|
|
|
|
expect(findForm().exists()).toBe(true);
|
|
|
|
expect(findForm().attributes('action')).toBe(importCsvIssuesPath);
|
|
|
|
expect(findAuthenticityToken()).toBe('mock-csrf-token');
|
|
|
|
expect(findFileInput()).toExist();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the correct primary button action text', () => {
|
|
|
|
expect(findPrimaryButton()).toExist();
|
|
|
|
});
|
|
|
|
|
2021-05-21 09:10:16 +00:00
|
|
|
it('submits the form when the primary action is clicked', () => {
|
2021-10-05 15:12:53 +00:00
|
|
|
findModal().vm.$emit('primary');
|
2021-03-11 09:09:36 +00:00
|
|
|
|
|
|
|
expect(formSubmitSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|