Commit 99bdfd18 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'issue-form-multiple-line-markdown' into 'master'

Fixed multi-line markdown in issue edit form

Closes #34318

See merge request !12458
parents c00e5bfa 2c954117
...@@ -94,8 +94,8 @@ gl.text.insertText = function(textArea, text, tag, blockTag, selected, wrap) { ...@@ -94,8 +94,8 @@ gl.text.insertText = function(textArea, text, tag, blockTag, selected, wrap) {
startChar = !wrap && !currentLineEmpty && textArea.selectionStart > 0 ? '\n' : ''; startChar = !wrap && !currentLineEmpty && textArea.selectionStart > 0 ? '\n' : '';
if (selectedSplit.length > 1 && (!wrap || (blockTag != null))) { if (selectedSplit.length > 1 && (!wrap || (blockTag != null && blockTag !== ''))) {
if (blockTag != null) { if (blockTag != null && blockTag !== '') {
insertText = this.blockTagText(text, textArea, blockTag, selected); insertText = this.blockTagText(text, textArea, blockTag, selected);
} else { } else {
insertText = selectedSplit.map(function(val) { insertText = selectedSplit.map(function(val) {
......
---
title: Fixed multi-line markdown tooltip buttons in issue edit form
merge_request:
author:
...@@ -4,47 +4,33 @@ import fieldComponent from '~/vue_shared/components/markdown/field.vue'; ...@@ -4,47 +4,33 @@ import fieldComponent from '~/vue_shared/components/markdown/field.vue';
describe('Markdown field component', () => { describe('Markdown field component', () => {
let vm; let vm;
beforeEach(() => { beforeEach((done) => {
vm = new Vue({ vm = new Vue({
render(createElement) { data() {
return createElement( return {
fieldComponent, text: 'testing\n123',
{ };
props: {
markdownPreviewUrl: '/preview',
markdownDocs: '/docs',
},
}, },
[ components: {
createElement('textarea', { fieldComponent,
slot: 'textarea',
}),
],
);
}, },
}); template: `
}); <field-component
marodown-preview-url="/preview"
it('creates a new instance of GL form', (done) => { markdown-docs="/docs"
spyOn(gl, 'GLForm'); >
vm.$mount(); <textarea
slot="textarea"
Vue.nextTick(() => { v-model="text">
expect( </textarea>
gl.GLForm, </field-component>
).toHaveBeenCalled(); `,
}).$mount();
done();
});
});
describe('mounted', () => {
beforeEach((done) => {
vm.$mount();
Vue.nextTick(done); Vue.nextTick(done);
}); });
describe('mounted', () => {
it('renders textarea inside backdrop', () => { it('renders textarea inside backdrop', () => {
expect( expect(
vm.$el.querySelector('.zen-backdrop textarea'), vm.$el.querySelector('.zen-backdrop textarea'),
...@@ -117,5 +103,52 @@ describe('Markdown field component', () => { ...@@ -117,5 +103,52 @@ describe('Markdown field component', () => {
}); });
}); });
}); });
describe('markdown buttons', () => {
it('converts single words', (done) => {
const textarea = vm.$el.querySelector('textarea');
textarea.setSelectionRange(0, 7);
vm.$el.querySelector('.js-md').click();
Vue.nextTick(() => {
expect(
textarea.value,
).toContain('**testing**');
done();
});
});
it('converts a line', (done) => {
const textarea = vm.$el.querySelector('textarea');
textarea.setSelectionRange(0, 0);
vm.$el.querySelectorAll('.js-md')[4].click();
Vue.nextTick(() => {
expect(
textarea.value,
).toContain('* testing');
done();
});
});
it('converts multiple lines', (done) => {
const textarea = vm.$el.querySelector('textarea');
textarea.setSelectionRange(0, 50);
vm.$el.querySelectorAll('.js-md')[4].click();
Vue.nextTick(() => {
expect(
textarea.value,
).toContain('* testing\n* 123');
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