Commit 985fc6db authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '328641-insert-images/display-errors-content-editor' into 'master'

Display errors in the Content Editor

See merge request gitlab-org/gitlab!65683
parents d73de719 60ea5a44
<script> <script>
import { GlAlert } from '@gitlab/ui';
import { EditorContent as TiptapEditorContent } from '@tiptap/vue-2'; import { EditorContent as TiptapEditorContent } from '@tiptap/vue-2';
import { ContentEditor } from '../services/content_editor'; import { ContentEditor } from '../services/content_editor';
import TopToolbar from './top_toolbar.vue'; import TopToolbar from './top_toolbar.vue';
export default { export default {
components: { components: {
GlAlert,
TiptapEditorContent, TiptapEditorContent,
TopToolbar, TopToolbar,
}, },
...@@ -14,15 +16,30 @@ export default { ...@@ -14,15 +16,30 @@ export default {
required: true, required: true,
}, },
}, },
data() {
return {
error: '',
};
},
mounted() {
this.contentEditor.tiptapEditor.on('error', (error) => {
this.error = error;
});
},
}; };
</script> </script>
<template> <template>
<div>
<gl-alert v-if="error" class="gl-mb-6" variant="danger" @dismiss="error = ''">
{{ error }}
</gl-alert>
<div <div
data-testid="content-editor" data-testid="content-editor"
class="md-area" class="md-area"
:class="{ 'is-focused': contentEditor.tiptapEditor.isFocused }" :class="{ 'is-focused': contentEditor.tiptapEditor.isFocused }"
> >
<top-toolbar class="gl-mb-4" :content-editor="contentEditor" /> <top-toolbar ref="toolbar" class="gl-mb-4" :content-editor="contentEditor" />
<tiptap-editor-content class="md" :editor="contentEditor.tiptapEditor" /> <tiptap-editor-content class="md" :editor="contentEditor.tiptapEditor" />
</div> </div>
</div>
</template> </template>
import { GlAlert } from '@gitlab/ui';
import { EditorContent } from '@tiptap/vue-2'; 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 ContentEditor from '~/content_editor/components/content_editor.vue';
import TopToolbar from '~/content_editor/components/top_toolbar.vue'; import TopToolbar from '~/content_editor/components/top_toolbar.vue';
import { createContentEditor } from '~/content_editor/services/create_content_editor'; import { createContentEditor } from '~/content_editor/services/create_content_editor';
...@@ -8,8 +10,11 @@ describe('ContentEditor', () => { ...@@ -8,8 +10,11 @@ describe('ContentEditor', () => {
let wrapper; let wrapper;
let editor; let editor;
const findEditorElement = () => wrapper.findByTestId('content-editor');
const findErrorAlert = () => wrapper.findComponent(GlAlert);
const createWrapper = async (contentEditor) => { const createWrapper = async (contentEditor) => {
wrapper = shallowMount(ContentEditor, { wrapper = shallowMountExtended(ContentEditor, {
propsData: { propsData: {
contentEditor, contentEditor,
}, },
...@@ -49,7 +54,7 @@ describe('ContentEditor', () => { ...@@ -49,7 +54,7 @@ describe('ContentEditor', () => {
editor.tiptapEditor.isFocused = isFocused; editor.tiptapEditor.isFocused = isFocused;
createWrapper(editor); createWrapper(editor);
expect(wrapper.classes()).toStrictEqual(classes); expect(findEditorElement().classes()).toStrictEqual(classes);
}, },
); );
...@@ -57,6 +62,30 @@ describe('ContentEditor', () => { ...@@ -57,6 +62,30 @@ describe('ContentEditor', () => {
editor.tiptapEditor.isFocused = true; editor.tiptapEditor.isFocused = true;
createWrapper(editor); 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);
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment