2020-03-12 05:09:55 -04:00
|
|
|
import $ from 'jquery';
|
|
|
|
import BlobFileDropzone from '~/blob/blob_file_dropzone';
|
|
|
|
|
|
|
|
describe('BlobFileDropzone', () => {
|
|
|
|
let dropzone;
|
|
|
|
let replaceFileButton;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('blob/show.html');
|
|
|
|
const form = $('.js-upload-blob-form');
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new BlobFileDropzone(form, 'POST');
|
|
|
|
dropzone = $('.js-upload-blob-form .dropzone').get(0).dropzone;
|
|
|
|
dropzone.processQueue = jest.fn();
|
|
|
|
replaceFileButton = $('#submit-all');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('submit button', () => {
|
|
|
|
it('requires file', () => {
|
|
|
|
jest.spyOn(window, 'alert').mockImplementation(() => {});
|
|
|
|
|
|
|
|
replaceFileButton.click();
|
|
|
|
|
|
|
|
expect(window.alert).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is disabled while uploading', () => {
|
|
|
|
jest.spyOn(window, 'alert').mockImplementation(() => {});
|
|
|
|
|
|
|
|
const file = new File([], 'some-file.jpg');
|
|
|
|
const fakeEvent = $.Event('drop', {
|
|
|
|
dataTransfer: { files: [file] },
|
|
|
|
});
|
|
|
|
|
|
|
|
dropzone.listeners[0].events.drop(fakeEvent);
|
|
|
|
|
|
|
|
replaceFileButton.click();
|
|
|
|
|
|
|
|
expect(window.alert).not.toHaveBeenCalled();
|
2020-03-24 17:07:54 -04:00
|
|
|
expect(replaceFileButton.is(':disabled')).toEqual(true);
|
2020-03-12 05:09:55 -04:00
|
|
|
expect(dropzone.processQueue).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|