Commit 4402eefa authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

[ci skip] Improve repo_binary_viewer_spec

parent e216a90b
......@@ -9,40 +9,77 @@ describe('RepoBinaryViewer', () => {
return new RepoBinaryViewer().$mount();
}
it('renders an img if its png', () => {
const binaryTypes = {
png: true,
};
const activeFile = {
name: 'name',
};
function createActiveFile(type, activeFile = {}) {
const file = activeFile;
switch (type) {
case 'svg':
case 'png':
file.name = 'name';
break;
case 'md':
file.html = 'html';
break;
default:
break;
}
return file;
}
function setActiveBinary(type) {
const binaryTypes = {};
binaryTypes[type] = true;
const activeFile = createActiveFile(type);
const uri = 'uri';
Store.binary = true;
Store.binaryTypes = binaryTypes;
Store.activeFile = activeFile;
Store.pngBlobWithDataURI = uri;
const vm = createComponent();
const img = vm.$el.querySelector(':scope > img');
return {
activeFile,
uri,
};
}
function assertBinaryImg(img, activeFile, uri) {
expect(img.src).toMatch(`/${uri}`);
expect(img.alt).toEqual(activeFile.name);
}
it('renders an img if its png', () => {
const { activeFile, uri } = setActiveBinary('png');
const vm = createComponent();
const img = vm.$el.querySelector(':scope > img');
assertBinaryImg(img, activeFile, uri);
});
it('renders an img if its svg', () => {
const { activeFile, uri } = setActiveBinary('svg');
const vm = createComponent();
const img = vm.$el.querySelector(':scope > img');
assertBinaryImg(img, activeFile, uri);
});
it('renders an div with content if its markdown', () => {
const binaryTypes = {
md: true,
};
const activeFile = {
html: 'markdown',
};
Store.binary = true;
Store.binaryTypes = binaryTypes;
Store.activeFile = activeFile;
const { activeFile } = setActiveBinary('md');
const vm = createComponent();
expect(vm.$el.querySelector(':scope > div').innerHTML).toEqual(activeFile.html);
});
it('renders no preview message if its unknown', () => {
setActiveBinary('unknown');
const vm = createComponent();
expect(vm.$el.querySelector('.binary-unknown').textContent).toMatch('Binary file. No preview available.');
});
it('does not render if no binary', () => {
Store.binary = false;
const vm = createComponent();
......
......@@ -4,7 +4,7 @@ import RepoStore from '~/repo/repo_store';
import RepoHelper from '~/repo/repo_helper';
import Api from '~/api';
describe('RepoCommitSection', () => {
fdescribe('RepoCommitSection', () => {
const openedFiles = [{
id: 0,
changed: true,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment