debian-mirror-gitlab/spec/frontend/blob/blob_file_dropzone_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import $ from 'jquery';
2022-07-16 23:28:13 +05:30
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2020-04-08 14:13:33 +05:30
import BlobFileDropzone from '~/blob/blob_file_dropzone';
describe('BlobFileDropzone', () => {
let dropzone;
let replaceFileButton;
beforeEach(() => {
2022-07-16 23:28:13 +05:30
loadHTMLFixture('blob/show.html');
2020-04-08 14:13:33 +05:30
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');
});
2022-07-16 23:28:13 +05:30
afterEach(() => {
resetHTMLFixture();
});
2020-04-08 14:13:33 +05:30
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-04-22 19:07:51 +05:30
expect(replaceFileButton.is(':disabled')).toEqual(true);
2020-04-08 14:13:33 +05:30
expect(dropzone.processQueue).toHaveBeenCalled();
});
});
});