failing spec fixes

This commit is contained in:
Phil Hughes 2017-10-19 11:55:27 +01:00
parent 389c852d12
commit 10dcaea1c3
No known key found for this signature in database
GPG key ID: 32245528C52E0F9F
6 changed files with 42 additions and 47 deletions

View file

@ -13,7 +13,7 @@
},
data() {
return {
entryName: '',
entryName: RepoStore.path !== '' ? `${RepoStore.path}/` : '',
};
},
components: {
@ -30,6 +30,8 @@
const dirNames = this.entryName.split('/');
dirNames.forEach((dirName) => {
if (dirName === '') return;
tree = RepoHelper.findOrCreateEntry('tree', tree, dirName).entry;
});
}

View file

@ -16,22 +16,11 @@ const RepoEditor = {
},
mounted() {
if (!this.activeFile.tempFile) {
Service.getRaw(this.activeFile.raw_path)
Service.getRaw(this.activeFile)
.then((rawResponse) => {
Store.blobRaw = rawResponse.data;
Store.activeFile.plain = rawResponse.data;
this.createMonacoInstance();
})
.catch(Helper.loadingError);
} else {
this.createMonacoInstance();
}
},
methods: {
createMonacoInstance() {
const monacoInstance = Helper.monaco.editor.create(this.$el, {
model: null,
readOnly: false,
@ -44,7 +33,11 @@ const RepoEditor = {
this.addMonacoEvents();
this.setupEditor();
})
.catch(Helper.loadingError);
},
methods: {
setupEditor() {
this.showHide();

View file

@ -110,7 +110,7 @@ const RepoHelper = {
RepoHelper.setBinaryDataAsBase64(data);
Store.setViewToPreview();
} else if (!Store.isPreviewView() && !data.render_error) {
Service.getRaw(data.raw_path)
Service.getRaw(data)
.then((rawResponse) => {
Store.blobRaw = rawResponse.data;
data.plain = rawResponse.data;

View file

@ -12,8 +12,14 @@ const RepoService = {
},
richExtensionRegExp: /md/,
getRaw(url) {
return axios.get(url, {
getRaw(file) {
if (file.tempFile) {
return Promise.resolve({
data: '',
});
}
return axios.get(file.raw_path, {
// Stop Axios from parsing a JSON file into a JS object
transformResponse: [res => res],
});

View file

@ -77,7 +77,7 @@ const RepoStore = {
} else if (file.newContent || file.plain) {
RepoStore.blobRaw = file.newContent || file.plain;
} else if (!file.tempFile) {
Service.getRaw(file.raw_path)
Service.getRaw(file)
.then((rawResponse) => {
RepoStore.blobRaw = rawResponse.data;
Helper.findOpenedFileFromActive().plain = rawResponse.data;

View file

@ -2,7 +2,16 @@ import Vue from 'vue';
import repoFileButtons from '~/repo/components/repo_file_buttons.vue';
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() {
const RepoFileButtons = Vue.extend(repoFileButtons);
@ -14,14 +23,6 @@ describe('RepoFileButtons', () => {
});
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';
RepoStore.openedFiles = new Array(1);
RepoStore.activeFile = activeFile;
@ -46,10 +47,6 @@ describe('RepoFileButtons', () => {
});
it('triggers rawPreviewToggle on preview click', () => {
const activeFile = {
extension: 'md',
url: 'url',
};
RepoStore.openedFiles = new Array(1);
RepoStore.activeFile = activeFile;
RepoStore.editMode = true;
@ -65,10 +62,7 @@ describe('RepoFileButtons', () => {
});
it('does not render preview toggle if not canPreview', () => {
const activeFile = {
extension: 'abcd',
url: 'url',
};
activeFile.extension = 'js';
RepoStore.openedFiles = new Array(1);
RepoStore.activeFile = activeFile;