diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 18:10:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 18:10:04 +0300 |
commit | f3b1e07903a7f509b11ad7cf188fac46d98f77f6 (patch) | |
tree | a6fa5e65d83d94334387952f1f526ed438604408 /spec/frontend | |
parent | ba174c982f40d71a87fd511b091753807174f7e7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/api_spec.js | 28 | ||||
-rw-r--r-- | spec/frontend/static_site_editor/mock_data.js | 18 | ||||
-rw-r--r-- | spec/frontend/static_site_editor/services/load_source_content_spec.js | 31 |
3 files changed, 77 insertions, 0 deletions
diff --git a/spec/frontend/api_spec.js b/spec/frontend/api_spec.js index 179aa3a49d7..fdefa16ac19 100644 --- a/spec/frontend/api_spec.js +++ b/spec/frontend/api_spec.js @@ -631,4 +631,32 @@ describe('Api', () => { }); }); }); + + describe('getRawFile', () => { + const dummyProjectPath = 'gitlab-org/gitlab'; + const dummyFilePath = 'doc/CONTRIBUTING.md'; + const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent( + dummyProjectPath, + )}/repository/files/${encodeURIComponent(dummyFilePath)}/raw`; + + describe('when the raw file is successfully fetched', () => { + it('resolves the Promise', () => { + mock.onGet(expectedUrl).replyOnce(200); + + return Api.getRawFile(dummyProjectPath, dummyFilePath).then(() => { + expect(mock.history.get).toHaveLength(1); + }); + }); + }); + + describe('when an error occurs while getting a raw file', () => { + it('rejects the Promise', () => { + mock.onDelete(expectedUrl).replyOnce(500); + + return Api.getRawFile(dummyProjectPath, dummyFilePath).catch(() => { + expect(mock.history.get).toHaveLength(1); + }); + }); + }); + }); }); diff --git a/spec/frontend/static_site_editor/mock_data.js b/spec/frontend/static_site_editor/mock_data.js new file mode 100644 index 00000000000..0b2a69420d8 --- /dev/null +++ b/spec/frontend/static_site_editor/mock_data.js @@ -0,0 +1,18 @@ +export const sourceContent = ` +--- +layout: handbook-page-toc +title: Handbook +twitter_image: '/images/tweets/handbook-gitlab.png' +--- + +## On this page +{:.no_toc .hidden-md .hidden-lg} + +- TOC +{:toc .hidden-md .hidden-lg} +`; + +export const sourceContentTitle = 'Handbook'; + +export const projectId = '123456'; +export const sourcePath = 'foobar.md.html'; diff --git a/spec/frontend/static_site_editor/services/load_source_content_spec.js b/spec/frontend/static_site_editor/services/load_source_content_spec.js new file mode 100644 index 00000000000..87893bb7a6e --- /dev/null +++ b/spec/frontend/static_site_editor/services/load_source_content_spec.js @@ -0,0 +1,31 @@ +import Api from '~/api'; + +import loadSourceContent from '~/static_site_editor/services/load_source_content'; + +import { sourceContent, sourceContentTitle, projectId, sourcePath } from '../mock_data'; + +describe('loadSourceContent', () => { + describe('requesting source content succeeds', () => { + let result; + + beforeEach(() => { + jest.spyOn(Api, 'getRawFile').mockResolvedValue({ data: sourceContent }); + + return loadSourceContent({ projectId, sourcePath }).then(_result => { + result = _result; + }); + }); + + it('calls getRawFile API with project id and source path', () => { + expect(Api.getRawFile).toHaveBeenCalledWith(projectId, sourcePath); + }); + + it('extracts page title from source content', () => { + expect(result.title).toBe(sourceContentTitle); + }); + + it('returns raw content', () => { + expect(result.content).toBe(sourceContent); + }); + }); +}); |