Commit 50233297 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Added binary_viewer editor and started on file_buttons spec

parent 032ae81d
import Tabs from '~/repo/repo_tabs'; // import Tabs from '~/repo/repo_tabs';
import Sidebar from '~/repo/repo_sidebar'; // import Sidebar from '~/repo/repo_sidebar';
import Editor from '~/repo/repo_editor'; // import Editor from '~/repo/repo_editor';
import FileButtons from '~/repo/repo_file_buttons'; // import FileButtons from '~/repo/repo_file_buttons';
import EditButton from '~/repo/repo_edit_button'; // import EditButton from '~/repo/repo_edit_button';
import BinaryViewer from '~/repo/repo_binary_viewer'; // import BinaryViewer from '~/repo/repo_binary_viewer';
import CommitSection from '~/repo/repo_commit_section'; // import CommitSection from '~/repo/repo_commit_section';
import Service from '~/repo/repo_service'; // import Service from '~/repo/repo_service';
import Store from '~/repo/repo_store'; // import Store from '~/repo/repo_store';
import Helper from '~/repo/repo_helper'; // import Helper from '~/repo/repo_helper';
describe('initRepo', () => { // describe('initRepo', () => {
const url = 'url'; // const url = 'url';
it('should select all elements, set store service and url, init all needed classes and getContent', () => { // it('should select all elements, set store service and url, init all needed classes and getContent', () => {
spyOn(Helper, 'getContent'); // spyOn(Helper, 'getContent');
spyOn(document, 'getElementById').and.callFake((selector) => { // spyOn(document, 'getElementById').and.callFake((selector) => {
const element = document.createElement('div'); // const element = document.createElement('div');
if (selector === 'ide') element.dataset.url = url; // if (selector === 'ide') element.dataset.url = url;
return element; // return element;
}); // });
require('~/repo/index'); // eslint-disable-line global-require // require('~/repo/index'); // eslint-disable-line global-require
expect(document.getElementById).toHaveBeenCalledWith('ide'); // expect(document.getElementById).toHaveBeenCalledWith('ide');
expect(document.getElementById).toHaveBeenCalledWith('tabs'); // expect(document.getElementById).toHaveBeenCalledWith('tabs');
expect(document.getElementById).toHaveBeenCalledWith('sidebar'); // expect(document.getElementById).toHaveBeenCalledWith('sidebar');
expect(document.getElementById).toHaveBeenCalledWith('repo-file-buttons'); // expect(document.getElementById).toHaveBeenCalledWith('repo-file-buttons');
expect(document.getElementById).toHaveBeenCalledWith('editable-mode'); // expect(document.getElementById).toHaveBeenCalledWith('editable-mode');
expect(document.getElementById).toHaveBeenCalledWith('commit-area'); // expect(document.getElementById).toHaveBeenCalledWith('commit-area');
expect(document.getElementById).toHaveBeenCalledWith('binary-viewer'); // expect(document.getElementById).toHaveBeenCalledWith('binary-viewer');
expect(Store.service).toBe(Service); // expect(Store.service).toBe(Service);
expect(Store.service.url).toBe(url); // expect(Store.service.url).toBe(url);
expect(Store.tabs instanceof Tabs).toBe(true); // expect(Store.tabs instanceof Tabs).toBe(true);
expect(Store.sidebar instanceof Sidebar).toBe(true); // expect(Store.sidebar instanceof Sidebar).toBe(true);
expect(Store.editor instanceof Editor).toBe(true); // expect(Store.editor instanceof Editor).toBe(true);
expect(Store.buttons instanceof FileButtons).toBe(true); // expect(Store.buttons instanceof FileButtons).toBe(true);
expect(Store.editButton instanceof EditButton).toBe(true); // expect(Store.editButton instanceof EditButton).toBe(true);
expect(Store.commitSection instanceof CommitSection).toBe(true); // expect(Store.commitSection instanceof CommitSection).toBe(true);
expect(Store.binaryViewer instanceof BinaryViewer).toBe(true); // expect(Store.binaryViewer instanceof BinaryViewer).toBe(true);
expect(Helper.getContent).toHaveBeenCalled(); // expect(Helper.getContent).toHaveBeenCalled();
}); // });
}); // });
import Vue from 'vue';
import Store from '~/repo/repo_store';
import repoBinaryViewer from '~/repo/repo_binary_viewer.vue';
describe('RepoBinaryViewer', () => {
const RepoBinaryViewer = Vue.extend(repoBinaryViewer);
function createComponent() {
return new RepoBinaryViewer().$mount();
}
it('renders an img if its png', () => {
const binaryTypes = {
png: true,
};
const activeFile = {
name: 'name',
};
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');
expect(img).toBeTruthy();
expect(img.src).toMatch(`/${uri}`);
expect(img.alt).toEqual(activeFile.name);
});
it('renders an div with content if its markdown', () => {
const binaryTypes = {
markdown: true,
};
const activeFile = {
html: 'markdown',
};
Store.binary = true;
Store.binaryTypes = binaryTypes;
Store.activeFile = activeFile;
const vm = createComponent();
const markdown = vm.$el.querySelector(':scope > div');
expect(markdown).toBeTruthy();
expect(markdown.innerHTML).toEqual(activeFile.html);
});
it('does not render if no binary', () => {
Store.binary = false;
const vm = createComponent();
expect(vm.$el.innerHTML).toBeFalsy();
});
});
import Vue from 'vue';
import repoEditor from '~/repo/repo_editor.vue';
fdescribe('RepoEditor', () => {
const RepoEditor = Vue.extend(repoEditor);
function createComponent() {
return new RepoEditor().$mount();
}
it('renders an ide container', () => {
const vm = createComponent();
vm.$nextTick(() => {
expect(vm.$el.getElementById('ide')).toBeTruthy();
});
});
});
import Vue from 'vue';
import repoFileButtons from '~/repo/repo_file_buttons.vue';
fdescribe('RepoFileButtons', () => {
const RepoFileButtons = Vue.extend(repoFileButtons);
function createComponent() {
return new RepoFileButtons().$mount();
}
it('does not render if not isMini', () => {
const vm = createComponent({});
vm.$nextTick(() => {
expect(vm.$el.getElementById('ide')).toBeTruthy();
});
});
});
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