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);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders markdown buttons', () => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.js-md').length).toBe(7);
|
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', [
|
|
|
|
$('<form><textarea class="markdown-area"></textarea></textarea></form>'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|