diff options
Diffstat (limited to 'spec/frontend/ide/services')
-rw-r--r-- | spec/frontend/ide/services/index_spec.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/spec/frontend/ide/services/index_spec.js b/spec/frontend/ide/services/index_spec.js index 55f174f4663..658ad37d7f2 100644 --- a/spec/frontend/ide/services/index_spec.js +++ b/spec/frontend/ide/services/index_spec.js @@ -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', () => { let file; let mock; |