Skip to content

Commit

Permalink
tests refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-kotov-dx committed Apr 14, 2022
1 parent ad83c91 commit 0ff53cc
Showing 1 changed file with 25 additions and 51 deletions.
76 changes: 25 additions & 51 deletions test/unit/modules/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,63 +109,37 @@ describe('Uploader', function() {
expect(dropEvent.defaultPrevented).toBeTrue();
});

it('check preventImageUploading on', function() {
const testRange = new Range(0);
const file = {
name: 'test.png',
type: 'image/png',
};
let uploads = [];

const quillMock = {
root: {
addEventListener: () => {},
},
};

const uploaderInstance = new Uploader(quillMock, {
mimetypes: Uploader.DEFAULTS.mimetypes,
handler: (range, files) => {
uploads = files;
},
});

uploaderInstance.preventImageUploading(true);
[true, false].forEach(preventValue => {
it(`check preventImageUploading ${preventValue}`, function() {
const testRange = new Range(0);
const file = {
name: 'test.png',
type: 'image/png',
};
const expectedUploadsCount = preventValue ? 0 : 1;
let uploads = [];

uploaderInstance.upload(testRange, [file]);
const quillMock = {
root: {
addEventListener: () => {},
},
};

expect(uploaderInstance.preventImageUploading()).toBeTrue();
expect(uploads.length).toEqual(0);
});
const uploaderInstance = new Uploader(quillMock, {
mimetypes: Uploader.DEFAULTS.mimetypes,
handler: (range, files) => {
uploads = files;
},
});

it('check preventImageUploading off', function() {
const testRange = new Range(0);
const file = {
name: 'test.png',
type: 'image/png',
};
let uploads = [];
uploaderInstance.preventImageUploading(!preventValue);
uploaderInstance.preventImageUploading(preventValue);

const quillMock = {
root: {
addEventListener: () => {},
},
};
uploaderInstance.upload(testRange, [file]);

const uploaderInstance = new Uploader(quillMock, {
mimetypes: Uploader.DEFAULTS.mimetypes,
handler: (range, files) => {
uploads = files;
},
expect(uploaderInstance.preventImageUploading()).toEqual(preventValue);
expect(uploads.length).toEqual(expectedUploadsCount);
});

uploaderInstance.preventImageUploading(true);
uploaderInstance.preventImageUploading(false);

uploaderInstance.upload(testRange, [file]);

expect(uploaderInstance.preventImageUploading()).toBeFalse();
expect(uploads.length).toEqual(1);
});
});
});

0 comments on commit 0ff53cc

Please sign in to comment.