summaryrefslogtreecommitdiff
path: root/spec/javascripts/blob/blob_file_dropzone_spec.js
blob: 2c8183ff77b9858fa1172200c02b96fad43609e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'dropzone';
import BlobFileDropzone from '~/blob/blob_file_dropzone';

describe('BlobFileDropzone', () => {
  preloadFixtures('blob/show.html.raw');

  beforeEach(() => {
    loadFixtures('blob/show.html.raw');
    const form = $('.js-upload-blob-form');
    this.blobFileDropzone = new BlobFileDropzone(form, 'POST');
    this.dropzone = $('.js-upload-blob-form .dropzone').get(0).dropzone;
    this.replaceFileButton = $('#submit-all');
  });

  describe('submit button', () => {
    it('requires file', () => {
      spyOn(window, 'alert');

      this.replaceFileButton.click();

      expect(window.alert).toHaveBeenCalled();
    });

    it('is disabled while uploading', () => {
      spyOn(window, 'alert');

      const file = {
        name: 'some-file.jpg',
        type: 'jpg',
      };
      const fakeEvent = jQuery.Event('drop', {
        dataTransfer: { files: [file] },
      });

      this.dropzone.listeners[0].events.drop(fakeEvent);
      this.replaceFileButton.click();

      expect(window.alert).not.toHaveBeenCalled();
      expect(this.replaceFileButton.is(':disabled')).toEqual(true);
    });
  });
});