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

FE review, replace timeout with nexttick and improve assertion helper. add changelog

parent 03445de8
---
title: Fix markdown form tabs toggling preview mode from double clicking write mode
button
merge_request: 15119
author:
type: fixed
import Vue from 'vue'; import Vue from 'vue';
import fieldComponent from '~/vue_shared/components/markdown/field.vue'; import fieldComponent from '~/vue_shared/components/markdown/field.vue';
import setTimeoutPromise from '../../../helpers/set_timeout_promise_helper';
function assertMarkdownTabs(isWrite, writeLink, previewLink, vm) {
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' : '');
}
describe('Markdown field component', () => { describe('Markdown field component', () => {
let vm; let vm;
...@@ -107,26 +112,19 @@ describe('Markdown field component', () => { ...@@ -107,26 +112,19 @@ describe('Markdown field component', () => {
}, 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) => { it('clicking already active write or preview link does nothing', (done) => {
writeLink.click(); writeLink.click();
Vue.nextTick()
setTimeoutPromise() .then(() => assertMarkdownTabs(true, writeLink, previewLink, vm))
.then(() => assertLinks(true))
.then(() => writeLink.click()) .then(() => writeLink.click())
.then(() => setTimeoutPromise()) .then(() => Vue.nextTick())
.then(() => assertLinks(true)) .then(() => assertMarkdownTabs(true, writeLink, previewLink, vm))
.then(() => previewLink.click()) .then(() => previewLink.click())
.then(() => setTimeoutPromise()) .then(() => Vue.nextTick())
.then(() => assertLinks(false)) .then(() => assertMarkdownTabs(false, writeLink, previewLink, vm))
.then(() => previewLink.click()) .then(() => previewLink.click())
.then(() => setTimeoutPromise()) .then(() => Vue.nextTick())
.then(() => assertLinks(false)) .then(() => assertMarkdownTabs(false, writeLink, previewLink, vm))
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
......
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