2020-04-08 14:13:33 +05:30
|
|
|
import SketchLoader from '~/blob/sketch';
|
2023-06-20 00:43:36 +05:30
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2022-07-16 23:28:13 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2023-06-20 00:43:36 +05:30
|
|
|
import htmlSketchViewer from 'test_fixtures_static/sketch_viewer.html';
|
2022-07-16 23:28:13 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe('Sketch viewer', () => {
|
|
|
|
beforeEach(() => {
|
2023-06-20 00:43:36 +05:30
|
|
|
setHTMLFixture(htmlSketchViewer);
|
2022-07-16 23:28:13 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('with error message', () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
beforeEach(() => {
|
2022-10-11 01:57:18 +05:30
|
|
|
jest.spyOn(SketchLoader.prototype, 'getZipContents').mockImplementation(
|
2020-04-08 14:13:33 +05:30
|
|
|
() =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
reject();
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
return new SketchLoader(document.getElementById('js-sketch-viewer'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error message', () => {
|
|
|
|
expect(document.querySelector('#js-sketch-viewer p')).not.toBeNull();
|
|
|
|
|
|
|
|
expect(document.querySelector('#js-sketch-viewer p').textContent.trim()).toContain(
|
|
|
|
'Cannot show preview.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the loading icon', () => {
|
|
|
|
expect(document.querySelector('.js-loading-icon')).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success', () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
beforeEach(() => {
|
2022-10-11 01:57:18 +05:30
|
|
|
jest.spyOn(SketchLoader.prototype, 'getZipContents').mockResolvedValue({
|
|
|
|
files: {
|
|
|
|
'previews/preview.png': {
|
|
|
|
async: jest.fn().mockResolvedValue('foo'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-07-16 23:28:13 +05:30
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new SketchLoader(document.getElementById('js-sketch-viewer'));
|
|
|
|
|
|
|
|
return waitForPromises();
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render error message', () => {
|
|
|
|
expect(document.querySelector('#js-sketch-viewer p')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the loading icon', () => {
|
|
|
|
expect(document.querySelector('.js-loading-icon')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders preview img', () => {
|
|
|
|
const img = document.querySelector('#js-sketch-viewer img');
|
|
|
|
|
|
|
|
expect(img).not.toBeNull();
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(img.classList.contains('img-fluid')).toBe(true);
|
2020-04-08 14:13:33 +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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|