Commit 10dcaea1 authored by Phil Hughes's avatar Phil Hughes

failing spec fixes

parent 389c852d
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
}, },
data() { data() {
return { return {
entryName: '', entryName: RepoStore.path !== '' ? `${RepoStore.path}/` : '',
}; };
}, },
components: { components: {
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
const dirNames = this.entryName.split('/'); const dirNames = this.entryName.split('/');
dirNames.forEach((dirName) => { dirNames.forEach((dirName) => {
if (dirName === '') return;
tree = RepoHelper.findOrCreateEntry('tree', tree, dirName).entry; tree = RepoHelper.findOrCreateEntry('tree', tree, dirName).entry;
}); });
} }
......
...@@ -16,35 +16,28 @@ const RepoEditor = { ...@@ -16,35 +16,28 @@ const RepoEditor = {
}, },
mounted() { mounted() {
if (!this.activeFile.tempFile) { Service.getRaw(this.activeFile)
Service.getRaw(this.activeFile.raw_path) .then((rawResponse) => {
.then((rawResponse) => { Store.blobRaw = rawResponse.data;
Store.blobRaw = rawResponse.data; Store.activeFile.plain = rawResponse.data;
Store.activeFile.plain = rawResponse.data;
const monacoInstance = Helper.monaco.editor.create(this.$el, {
this.createMonacoInstance(); model: null,
}) readOnly: false,
.catch(Helper.loadingError); contextmenu: true,
} else { scrollBeyondLastLine: false,
this.createMonacoInstance(); });
}
},
methods: { Helper.monacoInstance = monacoInstance;
createMonacoInstance() {
const monacoInstance = Helper.monaco.editor.create(this.$el, {
model: null,
readOnly: false,
contextmenu: true,
scrollBeyondLastLine: false,
});
Helper.monacoInstance = monacoInstance; this.addMonacoEvents();
this.addMonacoEvents(); this.setupEditor();
})
.catch(Helper.loadingError);
},
this.setupEditor(); methods: {
},
setupEditor() { setupEditor() {
this.showHide(); this.showHide();
......
...@@ -110,7 +110,7 @@ const RepoHelper = { ...@@ -110,7 +110,7 @@ const RepoHelper = {
RepoHelper.setBinaryDataAsBase64(data); RepoHelper.setBinaryDataAsBase64(data);
Store.setViewToPreview(); Store.setViewToPreview();
} else if (!Store.isPreviewView() && !data.render_error) { } else if (!Store.isPreviewView() && !data.render_error) {
Service.getRaw(data.raw_path) Service.getRaw(data)
.then((rawResponse) => { .then((rawResponse) => {
Store.blobRaw = rawResponse.data; Store.blobRaw = rawResponse.data;
data.plain = rawResponse.data; data.plain = rawResponse.data;
......
...@@ -12,8 +12,14 @@ const RepoService = { ...@@ -12,8 +12,14 @@ const RepoService = {
}, },
richExtensionRegExp: /md/, richExtensionRegExp: /md/,
getRaw(url) { getRaw(file) {
return axios.get(url, { if (file.tempFile) {
return Promise.resolve({
data: '',
});
}
return axios.get(file.raw_path, {
// Stop Axios from parsing a JSON file into a JS object // Stop Axios from parsing a JSON file into a JS object
transformResponse: [res => res], transformResponse: [res => res],
}); });
......
...@@ -77,7 +77,7 @@ const RepoStore = { ...@@ -77,7 +77,7 @@ const RepoStore = {
} else if (file.newContent || file.plain) { } else if (file.newContent || file.plain) {
RepoStore.blobRaw = file.newContent || file.plain; RepoStore.blobRaw = file.newContent || file.plain;
} else if (!file.tempFile) { } else if (!file.tempFile) {
Service.getRaw(file.raw_path) Service.getRaw(file)
.then((rawResponse) => { .then((rawResponse) => {
RepoStore.blobRaw = rawResponse.data; RepoStore.blobRaw = rawResponse.data;
Helper.findOpenedFileFromActive().plain = rawResponse.data; Helper.findOpenedFileFromActive().plain = rawResponse.data;
......
...@@ -2,7 +2,16 @@ import Vue from 'vue'; ...@@ -2,7 +2,16 @@ import Vue from 'vue';
import repoFileButtons from '~/repo/components/repo_file_buttons.vue'; import repoFileButtons from '~/repo/components/repo_file_buttons.vue';
import RepoStore from '~/repo/stores/repo_store'; import RepoStore from '~/repo/stores/repo_store';
describe('RepoFileButtons', () => { fdescribe('RepoFileButtons', () => {
const activeFile = {
extension: 'md',
url: 'url',
raw_path: 'raw_path',
blame_path: 'blame_path',
commits_path: 'commits_path',
permalink: 'permalink',
};
function createComponent() { function createComponent() {
const RepoFileButtons = Vue.extend(repoFileButtons); const RepoFileButtons = Vue.extend(repoFileButtons);
...@@ -14,14 +23,6 @@ describe('RepoFileButtons', () => { ...@@ -14,14 +23,6 @@ describe('RepoFileButtons', () => {
}); });
it('renders Raw, Blame, History, Permalink and Preview toggle', () => { it('renders Raw, Blame, History, Permalink and Preview toggle', () => {
const activeFile = {
extension: 'md',
url: 'url',
raw_path: 'raw_path',
blame_path: 'blame_path',
commits_path: 'commits_path',
permalink: 'permalink',
};
const activeFileLabel = 'activeFileLabel'; const activeFileLabel = 'activeFileLabel';
RepoStore.openedFiles = new Array(1); RepoStore.openedFiles = new Array(1);
RepoStore.activeFile = activeFile; RepoStore.activeFile = activeFile;
...@@ -46,10 +47,6 @@ describe('RepoFileButtons', () => { ...@@ -46,10 +47,6 @@ describe('RepoFileButtons', () => {
}); });
it('triggers rawPreviewToggle on preview click', () => { it('triggers rawPreviewToggle on preview click', () => {
const activeFile = {
extension: 'md',
url: 'url',
};
RepoStore.openedFiles = new Array(1); RepoStore.openedFiles = new Array(1);
RepoStore.activeFile = activeFile; RepoStore.activeFile = activeFile;
RepoStore.editMode = true; RepoStore.editMode = true;
...@@ -65,10 +62,7 @@ describe('RepoFileButtons', () => { ...@@ -65,10 +62,7 @@ describe('RepoFileButtons', () => {
}); });
it('does not render preview toggle if not canPreview', () => { it('does not render preview toggle if not canPreview', () => {
const activeFile = { activeFile.extension = 'js';
extension: 'abcd',
url: 'url',
};
RepoStore.openedFiles = new Array(1); RepoStore.openedFiles = new Array(1);
RepoStore.activeFile = activeFile; RepoStore.activeFile = activeFile;
......
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