summaryrefslogtreecommitdiff
path: root/spec/frontend_integration/content_editor/content_editor_integration_spec.js
blob: 1b45c0d43a36da7f4e9b16132596025f07a95d44 (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
61
62
63
import { nextTick } from 'vue';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import { ContentEditor } from '~/content_editor';

/**
 * This spec exercises some workflows in the Content Editor without mocking
 * any component.
 *
 */
describe('content_editor', () => {
  let wrapper;
  let renderMarkdown;
  let contentEditorService;

  const buildWrapper = () => {
    renderMarkdown = jest.fn();
    wrapper = mountExtended(ContentEditor, {
      propsData: {
        renderMarkdown,
        uploadsPath: '/',
      },
      listeners: {
        initialized(contentEditor) {
          contentEditorService = contentEditor;
        },
      },
    });
  };

  describe('when loading initial content', () => {
    describe('when the initial content is empty', () => {
      it('still hides the loading indicator', async () => {
        buildWrapper();

        renderMarkdown.mockResolvedValue('');

        await contentEditorService.setSerializedContent('');
        await nextTick();

        expect(wrapper.findByTestId('content-editor-loading-indicator').exists()).toBe(false);
      });
    });

    describe('when the initial content is not empty', () => {
      const initialContent = '<p><strong>bold text</strong></p>';
      beforeEach(async () => {
        buildWrapper();

        renderMarkdown.mockResolvedValue(initialContent);

        await contentEditorService.setSerializedContent('**bold text**');
        await nextTick();
      });
      it('hides the loading indicator', async () => {
        expect(wrapper.findByTestId('content-editor-loading-indicator').exists()).toBe(false);
      });

      it('displays the initial content', async () => {
        expect(wrapper.html()).toContain(initialContent);
      });
    });
  });
});