diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-14 15:09:57 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-14 15:09:57 +0000 |
commit | b689f371350fbf1b71f266764ee018befc9b91f7 (patch) | |
tree | 7de1d3ab26d3cae0ac2a7a8ccd8302fcdaac5534 /spec/frontend/content_editor/components | |
parent | 0b194c4854f312e36616fccf7c610cb2b0ec6957 (diff) | |
download | gitlab-ce-b689f371350fbf1b71f266764ee018befc9b91f7.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/content_editor/components')
3 files changed, 86 insertions, 3 deletions
diff --git a/spec/frontend/content_editor/components/toolbar_image_button_spec.js b/spec/frontend/content_editor/components/toolbar_image_button_spec.js new file mode 100644 index 00000000000..701dcf83476 --- /dev/null +++ b/spec/frontend/content_editor/components/toolbar_image_button_spec.js @@ -0,0 +1,78 @@ +import { GlButton, GlFormInputGroup } from '@gitlab/ui'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import ToolbarImageButton from '~/content_editor/components/toolbar_image_button.vue'; +import { configure as configureImageExtension } from '~/content_editor/extensions/image'; +import { createTestEditor, mockChainedCommands } from '../test_utils'; + +describe('content_editor/components/toolbar_image_button', () => { + let wrapper; + let editor; + + const buildWrapper = () => { + wrapper = mountExtended(ToolbarImageButton, { + propsData: { + tiptapEditor: editor, + }, + }); + }; + + const findImageURLInput = () => + wrapper.findComponent(GlFormInputGroup).find('input[type="text"]'); + const findApplyImageButton = () => wrapper.findComponent(GlButton); + + const selectFile = async (file) => { + const input = wrapper.find({ ref: 'fileSelector' }); + + // override the property definition because `input.files` isn't directly modifyable + Object.defineProperty(input.element, 'files', { value: [file], writable: true }); + await input.trigger('change'); + }; + + beforeEach(() => { + const { tiptapExtension: Image } = configureImageExtension({ + renderMarkdown: jest.fn(), + uploadsPath: '/uploads/', + }); + + editor = createTestEditor({ + extensions: [Image], + }); + + buildWrapper(); + }); + + afterEach(() => { + editor.destroy(); + wrapper.destroy(); + }); + + it('sets the image to the value in the URL input when "Insert" button is clicked', async () => { + const commands = mockChainedCommands(editor, ['focus', 'setImage', 'run']); + + await findImageURLInput().setValue('https://example.com/img.jpg'); + await findApplyImageButton().trigger('click'); + + expect(commands.focus).toHaveBeenCalled(); + expect(commands.setImage).toHaveBeenCalledWith({ + alt: 'img', + src: 'https://example.com/img.jpg', + canonicalSrc: 'https://example.com/img.jpg', + }); + expect(commands.run).toHaveBeenCalled(); + + expect(wrapper.emitted().execute[0]).toEqual([{ contentType: 'image', value: 'url' }]); + }); + + it('uploads the selected image when file input changes', async () => { + const commands = mockChainedCommands(editor, ['focus', 'uploadImage', 'run']); + const file = new File(['foo'], 'foo.png', { type: 'image/png' }); + + await selectFile(file); + + expect(commands.focus).toHaveBeenCalled(); + expect(commands.uploadImage).toHaveBeenCalledWith({ file }); + expect(commands.run).toHaveBeenCalled(); + + expect(wrapper.emitted().execute[0]).toEqual([{ contentType: 'image', value: 'upload' }]); + }); +}); diff --git a/spec/frontend/content_editor/components/toolbar_link_button_spec.js b/spec/frontend/content_editor/components/toolbar_link_button_spec.js index 7dcf3ac659b..576a2912f72 100644 --- a/spec/frontend/content_editor/components/toolbar_link_button_spec.js +++ b/spec/frontend/content_editor/components/toolbar_link_button_spec.js @@ -76,15 +76,17 @@ describe('content_editor/components/toolbar_link_button', () => { expect(commands.unsetLink).toHaveBeenCalled(); expect(commands.setLink).toHaveBeenCalledWith({ href: 'https://example', - 'data-canonical-src': 'https://example', + canonicalSrc: 'https://example', }); expect(commands.run).toHaveBeenCalled(); + + expect(wrapper.emitted().execute[0]).toEqual([{ contentType: 'link' }]); }); describe('on selection update', () => { it('updates link input box with canonical-src if present', async () => { jest.spyOn(editor, 'getAttributes').mockReturnValueOnce({ - 'data-canonical-src': 'uploads/my-file.zip', + canonicalSrc: 'uploads/my-file.zip', href: '/username/my-project/uploads/abcdefgh133535/my-file.zip', }); @@ -130,9 +132,11 @@ describe('content_editor/components/toolbar_link_button', () => { expect(commands.focus).toHaveBeenCalled(); expect(commands.setLink).toHaveBeenCalledWith({ href: 'https://example', - 'data-canonical-src': 'https://example', + canonicalSrc: 'https://example', }); expect(commands.run).toHaveBeenCalled(); + + expect(wrapper.emitted().execute[0]).toEqual([{ contentType: 'link' }]); }); }); diff --git a/spec/frontend/content_editor/components/top_toolbar_spec.js b/spec/frontend/content_editor/components/top_toolbar_spec.js index a5d9a626a04..5411793cd5e 100644 --- a/spec/frontend/content_editor/components/top_toolbar_spec.js +++ b/spec/frontend/content_editor/components/top_toolbar_spec.js @@ -51,6 +51,7 @@ describe('content_editor/components/top_toolbar', () => { ${'code-block'} | ${{ contentType: 'codeBlock', iconName: 'doc-code', label: 'Insert a code block', editorCommand: 'toggleCodeBlock' }} ${'text-styles'} | ${{}} ${'link'} | ${{}} + ${'image'} | ${{}} `('given a $testId toolbar control', ({ testId, controlProps }) => { beforeEach(() => { buildWrapper(); |