Commit af13ffbc authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Dont emit toggle-markdown event if current target is already active and add specs

parent 9c3f094a
...@@ -16,12 +16,18 @@ ...@@ -16,12 +16,18 @@
toolbarButton, toolbarButton,
}, },
methods: { methods: {
isMarkdownForm(form) {
return form && !form.find('.js-vue-markdown-field').length;
},
isActiveTarget(target) {
return target.closest('li').classList.contains('active');
},
toggleMarkdownPreview(e, form) { toggleMarkdownPreview(e, form) {
if (form && !form.find('.js-vue-markdown-field').length) { if (e.target.blur) e.target.blur();
return;
} else if (e.target.blur) { if (this.isMarkdownForm(form) || this.isActiveTarget(e.target)) return;
e.target.blur();
}
this.$emit('toggle-markdown'); this.$emit('toggle-markdown');
}, },
......
...@@ -39,6 +39,7 @@ describe('Markdown field component', () => { ...@@ -39,6 +39,7 @@ describe('Markdown field component', () => {
describe('markdown preview', () => { describe('markdown preview', () => {
let previewLink; let previewLink;
let writeLink;
beforeEach(() => { beforeEach(() => {
spyOn(Vue.http, 'post').and.callFake(() => new Promise((resolve) => { spyOn(Vue.http, 'post').and.callFake(() => new Promise((resolve) => {
...@@ -52,6 +53,7 @@ describe('Markdown field component', () => { ...@@ -52,6 +53,7 @@ describe('Markdown field component', () => {
})); }));
previewLink = vm.$el.querySelector('.nav-links li:nth-child(2) a'); previewLink = vm.$el.querySelector('.nav-links li:nth-child(2) a');
writeLink = vm.$el.querySelector('.nav-links li:nth-child(1) a');
}); });
it('sets preview link as active', (done) => { it('sets preview link as active', (done) => {
...@@ -103,6 +105,40 @@ describe('Markdown field component', () => { ...@@ -103,6 +105,40 @@ describe('Markdown field component', () => {
done(); done();
}, 0); }, 0);
}); });
function assertLinks(isWrite) {
expect(writeLink.parentNode.classList.contains('active')).toEqual(isWrite);
expect(previewLink.parentNode.classList.contains('active')).toEqual(!isWrite);
expect(vm.$el.querySelector('.md-preview').style.display).toEqual(isWrite ? 'none' : '');
}
it('clicking already active write or preview link does nothing', (done) => {
writeLink.click();
setTimeout(() => {
assertLinks(true);
writeLink.click();
setTimeout(() => {
assertLinks(true);
previewLink.click();
setTimeout(() => {
assertLinks(false);
previewLink.click();
setTimeout(() => {
assertLinks(false);
done();
});
});
});
});
});
}); });
describe('markdown buttons', () => { describe('markdown buttons', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment