2017-08-17 22:00:37 +05:30
|
|
|
/* eslint-disable no-new, promise/catch-or-return */
|
|
|
|
import JSZip from 'jszip';
|
|
|
|
import SketchLoader from '~/blob/sketch';
|
|
|
|
|
|
|
|
describe('Sketch viewer', () => {
|
|
|
|
const generateZipFileArrayBuffer = (zipFile, resolve, done) => {
|
2018-12-13 13:39:08 +05:30
|
|
|
zipFile.generateAsync({ type: 'arrayBuffer' }).then(content => {
|
|
|
|
resolve(content);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
}, 100);
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
preloadFixtures('static/sketch_viewer.html.raw');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('static/sketch_viewer.html.raw');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with error message', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
|
|
|
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(
|
|
|
|
() =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
reject();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
new SketchLoader(document.getElementById('js-sketch-viewer'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error message', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('#js-sketch-viewer p')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('#js-sketch-viewer p').textContent.trim()).toContain(
|
|
|
|
'Cannot show preview.',
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('removes render the loading icon', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.js-loading-icon')).toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
|
|
|
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(
|
|
|
|
() =>
|
|
|
|
new Promise(resolve => {
|
|
|
|
const zipFile = new JSZip();
|
|
|
|
zipFile
|
|
|
|
.folder('previews')
|
|
|
|
.file(
|
|
|
|
'preview.png',
|
|
|
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA1JREFUeNoBAgD9/wAAAAIAAVMrnDAAAAAASUVORK5CYII=',
|
|
|
|
{
|
|
|
|
base64: true,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
generateZipFileArrayBuffer(zipFile, resolve, done);
|
|
|
|
}),
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
new SketchLoader(document.getElementById('js-sketch-viewer'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render error message', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('#js-sketch-viewer p')).toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('removes render the loading icon', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('.js-loading-icon')).toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders preview img', () => {
|
|
|
|
const img = document.querySelector('#js-sketch-viewer img');
|
|
|
|
|
|
|
|
expect(img).not.toBeNull();
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(img.classList.contains('img-fluid')).toBeTruthy();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders link to image', () => {
|
|
|
|
const img = document.querySelector('#js-sketch-viewer img');
|
|
|
|
const link = document.querySelector('#js-sketch-viewer a');
|
|
|
|
|
|
|
|
expect(link.href).toBe(img.src);
|
|
|
|
expect(link.target).toBe('_blank');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('incorrect file', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
|
|
|
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(
|
|
|
|
() =>
|
|
|
|
new Promise(resolve => {
|
|
|
|
const zipFile = new JSZip();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
generateZipFileArrayBuffer(zipFile, resolve, done);
|
|
|
|
}),
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
new SketchLoader(document.getElementById('js-sketch-viewer'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error message', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('#js-sketch-viewer p')).not.toBeNull();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(document.querySelector('#js-sketch-viewer p').textContent.trim()).toContain(
|
|
|
|
'Cannot show preview.',
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|