Commit 855dd632 authored by Phil Hughes's avatar Phil Hughes

Merge branch...

Merge branch '211602-add-and-commit-empty-file-started-with-dot-in-web-ide-opens-gitlab-s-web-ide-internal-html' into 'master'

WebIDE: Fix incorrect content returned on empty dotfile

See merge request gitlab-org/gitlab!28144
parents 0c387f34 4c66a5eb
...@@ -25,7 +25,7 @@ export default { ...@@ -25,7 +25,7 @@ export default {
return Promise.resolve(file.content); return Promise.resolve(file.content);
} }
if (file.raw) { if (file.raw || !file.rawPath) {
return Promise.resolve(file.raw); return Promise.resolve(file.raw);
} }
......
---
title: Fix incorrect content returned on empty dotfile
merge_request: 28144
author:
type: fixed
...@@ -42,6 +42,87 @@ describe('IDE services', () => { ...@@ -42,6 +42,87 @@ describe('IDE services', () => {
}); });
}); });
describe('getRawFileData', () => {
it("resolves with a file's content if its a tempfile and it isn't renamed", () => {
const file = {
path: 'file',
tempFile: true,
content: 'content',
raw: 'raw content',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('content');
});
});
it('resolves with file.raw if the file is renamed', () => {
const file = {
path: 'file',
tempFile: true,
content: 'content',
prevPath: 'old_path',
raw: 'raw content',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('raw content');
});
});
it('returns file.raw if it exists', () => {
const file = {
path: 'file',
content: 'content',
raw: 'raw content',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('raw content');
});
});
it("returns file.raw if file.raw is empty but file.rawPath doesn't exist", () => {
const file = {
path: 'file',
content: 'content',
raw: '',
};
return services.getRawFileData(file).then(raw => {
expect(raw).toBe('');
});
});
describe("if file.rawPath exists but file.raw doesn't exist", () => {
let file;
let mock;
beforeEach(() => {
file = {
path: 'file',
content: 'content',
raw: '',
rawPath: 'some_raw_path',
};
mock = new MockAdapter(axios);
mock.onGet(file.rawPath).reply(200, 'raw content');
jest.spyOn(axios, 'get');
});
afterEach(() => {
mock.restore();
});
it('sends a request to file.rawPath', () => {
return services.getRawFileData(file).then(raw => {
expect(raw).toEqual('raw content');
});
});
});
});
describe('getBaseRawFileData', () => { describe('getBaseRawFileData', () => {
let file; let file;
let mock; let mock;
......
...@@ -408,7 +408,7 @@ describe('IDE store file actions', () => { ...@@ -408,7 +408,7 @@ describe('IDE store file actions', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(service, 'getRawFileData'); jest.spyOn(service, 'getRawFileData');
tmpFile = file('tmpFile'); tmpFile = { ...file('tmpFile'), rawPath: 'raw_path' };
store.state.entries[tmpFile.path] = tmpFile; store.state.entries[tmpFile.path] = tmpFile;
}); });
......
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