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