diff options
Diffstat (limited to 'spec/frontend/content_editor/components/content_editor_spec.js')
-rw-r--r-- | spec/frontend/content_editor/components/content_editor_spec.js | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/spec/frontend/content_editor/components/content_editor_spec.js b/spec/frontend/content_editor/components/content_editor_spec.js index 59c4190ad3a..563e80e04c1 100644 --- a/spec/frontend/content_editor/components/content_editor_spec.js +++ b/spec/frontend/content_editor/components/content_editor_spec.js @@ -1,5 +1,7 @@ +import { GlAlert } from '@gitlab/ui'; import { EditorContent } from '@tiptap/vue-2'; -import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import ContentEditor from '~/content_editor/components/content_editor.vue'; import TopToolbar from '~/content_editor/components/top_toolbar.vue'; import { createContentEditor } from '~/content_editor/services/create_content_editor'; @@ -8,8 +10,11 @@ describe('ContentEditor', () => { let wrapper; let editor; + const findEditorElement = () => wrapper.findByTestId('content-editor'); + const findErrorAlert = () => wrapper.findComponent(GlAlert); + const createWrapper = async (contentEditor) => { - wrapper = shallowMount(ContentEditor, { + wrapper = shallowMountExtended(ContentEditor, { propsData: { contentEditor, }, @@ -49,7 +54,7 @@ describe('ContentEditor', () => { editor.tiptapEditor.isFocused = isFocused; createWrapper(editor); - expect(wrapper.classes()).toStrictEqual(classes); + expect(findEditorElement().classes()).toStrictEqual(classes); }, ); @@ -57,6 +62,30 @@ describe('ContentEditor', () => { editor.tiptapEditor.isFocused = true; createWrapper(editor); - expect(wrapper.classes()).toContain('is-focused'); + expect(findEditorElement().classes()).toContain('is-focused'); + }); + + describe('displaying error', () => { + const error = 'Content Editor error'; + + beforeEach(async () => { + createWrapper(editor); + + editor.tiptapEditor.emit('error', error); + + await nextTick(); + }); + + it('displays error notifications from the tiptap editor', () => { + expect(findErrorAlert().text()).toBe(error); + }); + + it('allows dismissing an error alert', async () => { + findErrorAlert().vm.$emit('dismiss'); + + await nextTick(); + + expect(findErrorAlert().exists()).toBe(false); + }); }); }); |