Welcome to mirror list, hosted at ThFree Co, Russian Federation.

content_editor_alert_spec.js « components « content_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ddcd8f024e7b1ed04ea9ef10b48673cfa7c4fcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { GlAlert } from '@gitlab/ui';
import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ContentEditorAlert from '~/content_editor/components/content_editor_alert.vue';
import EditorStateObserver from '~/content_editor/components/editor_state_observer.vue';
import { createTestEditor, emitEditorEvent } from '../test_utils';

describe('content_editor/components/content_editor_alert', () => {
  let wrapper;
  let tiptapEditor;

  const findErrorAlert = () => wrapper.findComponent(GlAlert);

  const createWrapper = async () => {
    tiptapEditor = createTestEditor();

    wrapper = shallowMountExtended(ContentEditorAlert, {
      provide: {
        tiptapEditor,
      },
      stubs: {
        EditorStateObserver,
      },
    });
  };

  afterEach(() => {
    wrapper.destroy();
  });

  it.each`
    variant      | message
    ${'danger'}  | ${'An error occurred'}
    ${'warning'} | ${'A warning'}
  `(
    'renders error when content editor emits an error event for variant: $variant',
    async ({ message, variant }) => {
      createWrapper();

      await emitEditorEvent({ tiptapEditor, event: 'alert', params: { message, variant } });

      expect(findErrorAlert().text()).toBe(message);
      expect(findErrorAlert().attributes().variant).toBe(variant);
    },
  );

  it('allows dismissing the error', async () => {
    const message = 'error message';

    createWrapper();

    await emitEditorEvent({ tiptapEditor, event: 'alert', params: { message } });

    findErrorAlert().vm.$emit('dismiss');

    await nextTick();

    expect(findErrorAlert().exists()).toBe(false);
  });
});