Commit 1606a8b8 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '194207-migrate-blob-file-dropzone-to-jest' into 'master'

Migrate blob_file_dropzone to jest

See merge request gitlab-org/gitlab!26776
parents bac64392 395f899b
import $ from 'jquery'; import $ from 'jquery';
import BlobFileDropzone from '~/blob/blob_file_dropzone'; import BlobFileDropzone from '~/blob/blob_file_dropzone';
describe('BlobFileDropzone', function() { describe('BlobFileDropzone', () => {
preloadFixtures('blob/show.html'); preloadFixtures('blob/show.html');
let dropzone;
let replaceFileButton;
const jQueryMock = {
enable: jest.fn(),
disable: jest.fn(),
};
beforeEach(() => { beforeEach(() => {
loadFixtures('blob/show.html'); loadFixtures('blob/show.html');
const form = $('.js-upload-blob-form'); const form = $('.js-upload-blob-form');
this.blobFileDropzone = new BlobFileDropzone(form, 'POST'); // eslint-disable-next-line no-new
this.dropzone = $('.js-upload-blob-form .dropzone').get(0).dropzone; new BlobFileDropzone(form, 'POST');
this.replaceFileButton = $('#submit-all'); dropzone = $('.js-upload-blob-form .dropzone').get(0).dropzone;
dropzone.processQueue = jest.fn();
replaceFileButton = $('#submit-all');
$.fn.extend(jQueryMock);
}); });
describe('submit button', () => { describe('submit button', () => {
it('requires file', () => { it('requires file', () => {
spyOn(window, 'alert'); jest.spyOn(window, 'alert').mockImplementation(() => {});
this.replaceFileButton.click(); replaceFileButton.click();
expect(window.alert).toHaveBeenCalled(); expect(window.alert).toHaveBeenCalled();
}); });
it('is disabled while uploading', () => { it('is disabled while uploading', () => {
spyOn(window, 'alert'); jest.spyOn(window, 'alert').mockImplementation(() => {});
const file = new File([], 'some-file.jpg'); const file = new File([], 'some-file.jpg');
const fakeEvent = $.Event('drop', { const fakeEvent = $.Event('drop', {
dataTransfer: { files: [file] }, dataTransfer: { files: [file] },
}); });
this.dropzone.listeners[0].events.drop(fakeEvent); dropzone.listeners[0].events.drop(fakeEvent);
this.replaceFileButton.click();
replaceFileButton.click();
expect(window.alert).not.toHaveBeenCalled(); expect(window.alert).not.toHaveBeenCalled();
expect(this.replaceFileButton.is(':disabled')).toEqual(true); expect(jQueryMock.enable).toHaveBeenCalled();
expect(dropzone.processQueue).toHaveBeenCalled();
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment