diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 15:44:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 15:44:42 +0000 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/frontend/content_editor/components/top_toolbar_spec.js | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) | |
download | gitlab-ce-4555e1b21c365ed8303ffb7a3325d773c9b8bf31.tar.gz |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/frontend/content_editor/components/top_toolbar_spec.js')
-rw-r--r-- | spec/frontend/content_editor/components/top_toolbar_spec.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/frontend/content_editor/components/top_toolbar_spec.js b/spec/frontend/content_editor/components/top_toolbar_spec.js new file mode 100644 index 00000000000..8f47be3f489 --- /dev/null +++ b/spec/frontend/content_editor/components/top_toolbar_spec.js @@ -0,0 +1,76 @@ +import { shallowMount } from '@vue/test-utils'; +import { mockTracking } from 'helpers/tracking_helper'; +import { extendedWrapper } from 'helpers/vue_test_utils_helper'; +import TopToolbar from '~/content_editor/components/top_toolbar.vue'; +import { + TOOLBAR_CONTROL_TRACKING_ACTION, + CONTENT_EDITOR_TRACKING_LABEL, +} from '~/content_editor/constants'; +import { createContentEditor } from '~/content_editor/services/create_content_editor'; + +describe('content_editor/components/top_toolbar', () => { + let wrapper; + let contentEditor; + let trackingSpy; + const buildEditor = () => { + contentEditor = createContentEditor({ renderMarkdown: () => true }); + }; + + const buildWrapper = () => { + wrapper = extendedWrapper( + shallowMount(TopToolbar, { + propsData: { + contentEditor, + }, + }), + ); + }; + + beforeEach(() => { + trackingSpy = mockTracking(undefined, null, jest.spyOn); + }); + + beforeEach(() => { + buildEditor(); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + describe.each` + testId | buttonProps + ${'bold'} | ${{ contentType: 'bold', iconName: 'bold', label: 'Bold text', editorCommand: 'toggleBold' }} + ${'italic'} | ${{ contentType: 'italic', iconName: 'italic', label: 'Italic text', editorCommand: 'toggleItalic' }} + ${'code'} | ${{ contentType: 'code', iconName: 'code', label: 'Code', editorCommand: 'toggleCode' }} + ${'blockquote'} | ${{ contentType: 'blockquote', iconName: 'quote', label: 'Insert a quote', editorCommand: 'toggleBlockquote' }} + ${'bullet-list'} | ${{ contentType: 'bulletList', iconName: 'list-bulleted', label: 'Add a bullet list', editorCommand: 'toggleBulletList' }} + ${'ordered-list'} | ${{ contentType: 'orderedList', iconName: 'list-numbered', label: 'Add a numbered list', editorCommand: 'toggleOrderedList' }} + `('given a $testId toolbar control', ({ testId, buttonProps }) => { + beforeEach(() => { + buildWrapper(); + }); + + it('renders the toolbar control with the provided properties', () => { + expect(wrapper.findByTestId(testId).props()).toEqual({ + ...buttonProps, + tiptapEditor: contentEditor.tiptapEditor, + }); + }); + + it.each` + control | eventData + ${'bold'} | ${{ contentType: 'bold' }} + ${'blockquote'} | ${{ contentType: 'blockquote', value: 1 }} + `('tracks the execution of toolbar controls', ({ control, eventData }) => { + const { contentType, value } = eventData; + wrapper.findByTestId(control).vm.$emit('execute', eventData); + + expect(trackingSpy).toHaveBeenCalledWith(undefined, TOOLBAR_CONTROL_TRACKING_ACTION, { + label: CONTENT_EDITOR_TRACKING_LABEL, + property: contentType, + value, + }); + }); + }); +}); |