Commit 3efe1703 authored by Fatih Acet's avatar Fatih Acet

Merge branch '44697-prevue' into 'master'

Resolve "When editing a comment in an issue, the preview mode is toggled in the main textarea"

Closes #44697

See merge request gitlab-org/gitlab-ce!18303
parents 2a7d011a 242820e2
......@@ -27,20 +27,22 @@
$(document).off('markdown-preview:hide.vue', this.writeMarkdownTab);
},
methods: {
isMarkdownForm(form) {
return form && !form.find('.js-vue-markdown-field').length;
isValid(form) {
return !form ||
form.find('.js-vue-markdown-field').length ||
$(this.$el).closest('form') === form[0];
},
previewMarkdownTab(event, form) {
if (event.target.blur) event.target.blur();
if (this.isMarkdownForm(form)) return;
if (!this.isValid(form)) return;
this.$emit('preview-markdown');
},
writeMarkdownTab(event, form) {
if (event.target.blur) event.target.blur();
if (this.isMarkdownForm(form)) return;
if (!this.isValid(form)) return;
this.$emit('write-markdown');
},
......
---
title: Make toggle markdown preview shortcut only toggle selected field
merge_request:
author:
type: fixed
import Vue from 'vue';
import $ from 'jquery';
import headerComponent from '~/vue_shared/components/markdown/header.vue';
describe('Markdown field header component', () => {
let vm;
beforeEach((done) => {
beforeEach(done => {
const Component = Vue.extend(headerComponent);
vm = new Component({
......@@ -17,24 +18,18 @@ describe('Markdown field header component', () => {
});
it('renders markdown buttons', () => {
expect(
vm.$el.querySelectorAll('.js-md').length,
).toBe(7);
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();
expect(vm.$el.querySelector('li:nth-child(1)').classList.contains('active')).toBeTruthy();
});
it('renders `preview` link as active when previewMarkdown is true', (done) => {
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();
expect(vm.$el.querySelector('li:nth-child(2)').classList.contains('active')).toBeTruthy();
done();
});
......@@ -52,16 +47,24 @@ describe('Markdown field header component', () => {
expect(vm.$emit).toHaveBeenCalledWith('write-markdown');
});
it('blurs preview link after click', (done) => {
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 => {
const link = vm.$el.querySelector('li:nth-child(2) a');
spyOn(HTMLElement.prototype, 'blur');
link.click();
setTimeout(() => {
expect(
link.blur,
).toHaveBeenCalled();
expect(link.blur).toHaveBeenCalled();
done();
});
......
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