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', () => { ...@@ -9,40 +9,77 @@ describe('RepoBinaryViewer', () => {
return new RepoBinaryViewer().$mount(); return new RepoBinaryViewer().$mount();
} }
it('renders an img if its png', () => { function createActiveFile(type, activeFile = {}) {
const binaryTypes = { const file = activeFile;
png: true,
}; switch (type) {
const activeFile = { case 'svg':
name: 'name', 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'; const uri = 'uri';
Store.binary = true; Store.binary = true;
Store.binaryTypes = binaryTypes; Store.binaryTypes = binaryTypes;
Store.activeFile = activeFile; Store.activeFile = activeFile;
Store.pngBlobWithDataURI = uri; 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.src).toMatch(`/${uri}`);
expect(img.alt).toEqual(activeFile.name); 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', () => { it('renders an div with content if its markdown', () => {
const binaryTypes = { const { activeFile } = setActiveBinary('md');
md: true,
};
const activeFile = {
html: 'markdown',
};
Store.binary = true;
Store.binaryTypes = binaryTypes;
Store.activeFile = activeFile;
const vm = createComponent(); const vm = createComponent();
expect(vm.$el.querySelector(':scope > div').innerHTML).toEqual(activeFile.html); 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', () => { it('does not render if no binary', () => {
Store.binary = false; Store.binary = false;
const vm = createComponent(); const vm = createComponent();
......
...@@ -4,7 +4,7 @@ import RepoStore from '~/repo/repo_store'; ...@@ -4,7 +4,7 @@ import RepoStore from '~/repo/repo_store';
import RepoHelper from '~/repo/repo_helper'; import RepoHelper from '~/repo/repo_helper';
import Api from '~/api'; import Api from '~/api';
describe('RepoCommitSection', () => { fdescribe('RepoCommitSection', () => {
const openedFiles = [{ const openedFiles = [{
id: 0, id: 0,
changed: true, 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