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

82 lines
2.3 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', () => {
const buttons = ['Add bold text', 'Add italic text', 'Insert a quote', 'Insert code', 'Add a link', 'Add a bullet list', 'Add a numbered list', 'Add a task list', 'Add a table', 'Go full screen'];
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', () => {
spyOn(vm, '$emit');
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', () => {
spyOn(vm, '$emit');
$(document).triggerHandler('markdown-preview:show', [
2018-11-08 19:23:39 +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();
});
it('blurs preview link after click', done => {
2017-09-10 17:25:29 +05:30
const link = vm.$el.querySelector('li:nth-child(2) a');
spyOn(HTMLElement.prototype, 'blur');
link.click();
setTimeout(() => {
2018-10-15 14:42:47 +05:30
expect(link.blur).toHaveBeenCalled();
2017-09-10 17:25:29 +05:30
done();
});
});
2018-12-05 23:21:45 +05:30
it('renders markdown table template', () => {
expect(vm.mdTable).toEqual('| header | header |\n| ------ | ------ |\n| cell | cell |\n| cell | cell |');
});
2017-09-10 17:25:29 +05:30
});