debian-mirror-gitlab/spec/frontend/vue_shared/components/markdown/header_spec.js

108 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2018-10-15 14:42:47 +05:30
import $ from 'jquery';
2017-09-10 17:25:29 +05:30
import headerComponent from '~/vue_shared/components/markdown/header.vue';
describe('Markdown field header component', () => {
let vm;
2018-10-15 14:42:47 +05:30
beforeEach(done => {
2017-09-10 17:25:29 +05:30
const Component = Vue.extend(headerComponent);
vm = new Component({
propsData: {
previewMarkdown: false,
},
}).$mount();
Vue.nextTick(done);
});
2018-12-05 23:21:45 +05:30
it('renders markdown header buttons', () => {
2018-12-13 13:39:08 +05:30
const buttons = [
'Add bold text',
'Add italic text',
'Insert a quote',
2019-09-04 21:01:54 +05:30
'Insert suggestion',
2018-12-13 13:39:08 +05:30
'Insert code',
'Add a link',
'Add a bullet list',
'Add a numbered list',
'Add a task list',
'Add a table',
'Go full screen',
];
2018-12-05 23:21:45 +05:30
const elements = vm.$el.querySelectorAll('.toolbar-btn');
elements.forEach((buttonEl, index) => {
expect(buttonEl.getAttribute('data-original-title')).toBe(buttons[index]);
});
2017-09-10 17:25:29 +05:30
});
it('renders `write` link as active when previewMarkdown is false', () => {
2018-10-15 14:42:47 +05:30
expect(vm.$el.querySelector('li:nth-child(1)').classList.contains('active')).toBeTruthy();
2017-09-10 17:25:29 +05:30
});
2018-10-15 14:42:47 +05:30
it('renders `preview` link as active when previewMarkdown is true', done => {
2017-09-10 17:25:29 +05:30
vm.previewMarkdown = true;
Vue.nextTick(() => {
2018-10-15 14:42:47 +05:30
expect(vm.$el.querySelector('li:nth-child(2)').classList.contains('active')).toBeTruthy();
2017-09-10 17:25:29 +05:30
done();
});
});
it('emits toggle markdown event when clicking preview', () => {
2019-09-30 21:07:59 +05:30
jest.spyOn(vm, '$emit').mockImplementation();
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
vm.$el.querySelector('.js-preview-link').click();
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.$emit).toHaveBeenCalledWith('preview-markdown');
vm.$el.querySelector('.js-write-link').click();
expect(vm.$emit).toHaveBeenCalledWith('write-markdown');
2017-09-10 17:25:29 +05:30
});
2018-10-15 14:42:47 +05:30
it('does not emit toggle markdown event when triggered from another form', () => {
2019-09-30 21:07:59 +05:30
jest.spyOn(vm, '$emit').mockImplementation();
2018-10-15 14:42:47 +05:30
$(document).triggerHandler('markdown-preview:show', [
2018-12-13 13:39:08 +05:30
$(
'<form><div class="js-vue-markdown-field"><textarea class="markdown-area"></textarea></div></form>',
),
2018-10-15 14:42:47 +05:30
]);
expect(vm.$emit).not.toHaveBeenCalled();
});
2019-09-30 21:07:59 +05:30
it('blurs preview link after click', () => {
2018-12-13 13:39:08 +05:30
const link = vm.$el.querySelector('li:nth-child(2) button');
2019-09-30 21:07:59 +05:30
jest.spyOn(HTMLElement.prototype, 'blur').mockImplementation();
2017-09-10 17:25:29 +05:30
link.click();
2019-09-30 21:07:59 +05:30
expect(link.blur).toHaveBeenCalled();
2017-09-10 17:25:29 +05:30
});
2018-12-05 23:21:45 +05:30
it('renders markdown table template', () => {
2018-12-13 13:39:08 +05:30
expect(vm.mdTable).toEqual(
'| header | header |\n| ------ | ------ |\n| cell | cell |\n| cell | cell |',
);
2018-12-05 23:21:45 +05:30
});
2019-02-15 15:39:39 +05:30
it('renders suggestion template', () => {
vm.lineContent = 'Some content';
2019-07-07 11:18:12 +05:30
expect(vm.mdSuggestion).toEqual('```suggestion:-0+0\n{text}\n```');
2019-02-15 15:39:39 +05:30
});
it('does not render suggestion button if `canSuggest` is set to false', () => {
vm.canSuggest = false;
Vue.nextTick(() => {
2019-10-12 21:52:04 +05:30
expect(vm.$el.querySelector('.js-suggestion-btn')).toBe(null);
2019-02-15 15:39:39 +05:30
});
});
2017-09-10 17:25:29 +05:30
});