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

toolbar_spec.js « markdown « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5bf11ff2b2678e9cd45720aefb3ff8573102f457 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { mount } from '@vue/test-utils';
import Toolbar from '~/vue_shared/components/markdown/toolbar.vue';
import EditorModeSwitcher from '~/vue_shared/components/markdown/editor_mode_switcher.vue';
import { updateText } from '~/lib/utils/text_markdown';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';

jest.mock('~/lib/utils/text_markdown');

describe('toolbar', () => {
  let wrapper;

  const createWrapper = (props = {}, attachTo = document.body) => {
    wrapper = mount(Toolbar, {
      attachTo,
      propsData: { markdownDocsPath: '', ...props },
      mocks: {
        $apollo: {
          queries: {
            currentUser: {
              loading: false,
            },
          },
        },
      },
    });
  };

  describe('user can attach file', () => {
    beforeEach(() => {
      createWrapper();
    });

    it('should render uploading-container', () => {
      expect(wrapper.vm.$el.querySelector('.uploading-container')).not.toBeNull();
    });
  });

  describe('user cannot attach file', () => {
    beforeEach(() => {
      createWrapper({ canAttachFile: false });
    });

    it('should not render uploading-container', () => {
      expect(wrapper.vm.$el.querySelector('.uploading-container')).toBeNull();
    });
  });

  describe('comment tool bar settings', () => {
    it('does not show comment tool bar div', () => {
      createWrapper({ showCommentToolBar: false });

      expect(wrapper.find('.comment-toolbar').exists()).toBe(false);
    });

    it('shows comment tool bar by default', () => {
      createWrapper();

      expect(wrapper.find('.comment-toolbar').exists()).toBe(true);
    });
  });

  describe('with content editor switcher', () => {
    beforeEach(() => {
      setHTMLFixture(
        '<div class="md-area"><textarea>some value</textarea><div id="root"></div></div>',
      );
      createWrapper(
        {
          showContentEditorSwitcher: true,
        },
        '#root',
      );
    });

    afterEach(() => {
      resetHTMLFixture();
    });

    it('re-emits event from switcher', () => {
      wrapper.findComponent(EditorModeSwitcher).vm.$emit('switch');

      expect(wrapper.emitted('enableContentEditor')).toEqual([[]]);
      expect(updateText).not.toHaveBeenCalled();
    });

    it('does not insert a template text if textarea has some value', () => {
      wrapper.findComponent(EditorModeSwitcher).vm.$emit('switch', true);

      expect(updateText).not.toHaveBeenCalled();
    });

    it('inserts a "getting started with rich text" template when switched for the first time', () => {
      document.querySelector('textarea').value = '';

      wrapper.findComponent(EditorModeSwitcher).vm.$emit('switch', true);

      expect(updateText).toHaveBeenCalledWith(
        expect.objectContaining({
          tag: `### Rich text editor

Try out **styling** _your_ content right here or read the [direction](https://about.gitlab.com/direction/plan/knowledge/content_editor/).`,
          textArea: document.querySelector('textarea'),
          cursorOffset: 0,
          wrap: false,
        }),
      );
    });
  });
});