diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 15:09:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 15:09:36 +0300 |
commit | c6a33b298229f9e04933be43d6176c476ef03012 (patch) | |
tree | 66b336ef374b813d6e9c7f6a19264060a1f23f91 /spec/frontend/ide | |
parent | c52b81f45762cb7f05a950689dfc6d51b197ea73 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r-- | spec/frontend/ide/services/index_spec.js | 81 | ||||
-rw-r--r-- | spec/frontend/ide/stores/actions/file_spec.js | 2 |
2 files changed, 82 insertions, 1 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; diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js index 6df963b0d55..43cb06f5d92 100644 --- a/spec/frontend/ide/stores/actions/file_spec.js +++ b/spec/frontend/ide/stores/actions/file_spec.js @@ -408,7 +408,7 @@ describe('IDE store file actions', () => { beforeEach(() => { jest.spyOn(service, 'getRawFileData'); - tmpFile = file('tmpFile'); + tmpFile = { ...file('tmpFile'), rawPath: 'raw_path' }; store.state.entries[tmpFile.path] = tmpFile; }); |