diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-12 15:09:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-12 15:09:39 +0300 |
commit | f81141c25d0dd79de8c07559bf268cb6e0d287d3 (patch) | |
tree | a0f700b90845f738cc2037cbbfb7a980c36137ac /spec/frontend/content_editor | |
parent | 12de063de4663766a43d6c3e0883a686d66ab401 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/content_editor')
-rw-r--r-- | spec/frontend/content_editor/services/upload_file_spec.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/frontend/content_editor/services/upload_file_spec.js b/spec/frontend/content_editor/services/upload_file_spec.js new file mode 100644 index 00000000000..87c5298079e --- /dev/null +++ b/spec/frontend/content_editor/services/upload_file_spec.js @@ -0,0 +1,46 @@ +import axios from 'axios'; +import MockAdapter from 'axios-mock-adapter'; +import { uploadFile } from '~/content_editor/services/upload_file'; +import httpStatus from '~/lib/utils/http_status'; + +describe('content_editor/services/upload_file', () => { + const uploadsPath = '/uploads'; + const file = new File(['content'], 'file.txt'); + // TODO: Replace with automated fixture + const renderedAttachmentLinkFixture = + '<a href="/group1/project1/-/wikis/test-file.png" data-canonical-src="test-file.png"><img data-src="/group1/project1/-/wikis/test-file.png" data-canonical-src="test-file.png"></a></p>'; + const successResponse = { + link: { + markdown: '[GitLab](https://gitlab.com)', + }, + }; + const parseHTML = (html) => new DOMParser().parseFromString(html, 'text/html'); + let mock; + let renderMarkdown; + let renderedMarkdown; + + beforeEach(() => { + const formData = new FormData(); + formData.append('file', file); + + renderedMarkdown = parseHTML(renderedAttachmentLinkFixture); + + mock = new MockAdapter(axios); + mock.onPost(uploadsPath, formData).reply(httpStatus.OK, successResponse); + renderMarkdown = jest.fn().mockResolvedValue(renderedAttachmentLinkFixture); + }); + + afterEach(() => { + mock.restore(); + }); + + it('returns src and canonicalSrc of uploaded file', async () => { + const response = await uploadFile({ uploadsPath, renderMarkdown, file }); + + expect(renderMarkdown).toHaveBeenCalledWith(successResponse.link.markdown); + expect(response).toEqual({ + src: renderedMarkdown.querySelector('a').getAttribute('href'), + canonicalSrc: renderedMarkdown.querySelector('a').dataset.canonicalSrc, + }); + }); +}); |