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

70 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
import headerComponent from '~/vue_shared/components/markdown/header.vue';
describe('Markdown field header component', () => {
let vm;
beforeEach((done) => {
const Component = Vue.extend(headerComponent);
vm = new Component({
propsData: {
previewMarkdown: false,
},
}).$mount();
Vue.nextTick(done);
});
it('renders markdown buttons', () => {
expect(
vm.$el.querySelectorAll('.js-md').length,
).toBe(7);
});
it('renders `write` link as active when previewMarkdown is false', () => {
expect(
vm.$el.querySelector('li:nth-child(1)').classList.contains('active'),
).toBeTruthy();
});
it('renders `preview` link as active when previewMarkdown is true', (done) => {
vm.previewMarkdown = true;
Vue.nextTick(() => {
expect(
vm.$el.querySelector('li:nth-child(2)').classList.contains('active'),
).toBeTruthy();
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
});
it('blurs preview link after click', (done) => {
const link = vm.$el.querySelector('li:nth-child(2) a');
spyOn(HTMLElement.prototype, 'blur');
link.click();
setTimeout(() => {
expect(
link.blur,
).toHaveBeenCalled();
done();
});
});
});