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
|
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();
});
});
});
|