diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-06-29 16:25:06 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-06-29 16:25:06 +0300 |
commit | debc61264d05fcd7f152b1251d5a3fbeb44d9bfa (patch) | |
tree | 1ebe990dd44feb5ef1a66c57b34d2002b819ebcc /spec | |
parent | 00b03d9f9a9a7d2034fcdf202c4dbb6444f28799 (diff) | |
parent | 84630a5d8e4e9fa575636aa34eb00a7e210ad39c (diff) |
Merge branch 'issue-form-multiple-line-markdown-stable' into '9-3-stable-patch-3-mysql'
Issue form multiple line markdown stable
See merge request !12549
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/vue_shared/components/markdown/field_spec.js | 109 |
1 files changed, 75 insertions, 34 deletions
diff --git a/spec/javascripts/vue_shared/components/markdown/field_spec.js b/spec/javascripts/vue_shared/components/markdown/field_spec.js index 4bbaff561fc..52f7ae8b3b1 100644 --- a/spec/javascripts/vue_shared/components/markdown/field_spec.js +++ b/spec/javascripts/vue_shared/components/markdown/field_spec.js @@ -2,49 +2,43 @@ import Vue from 'vue'; import fieldComponent from '~/vue_shared/components/markdown/field.vue'; describe('Markdown field component', () => { + let el; let vm; - beforeEach(() => { + beforeEach((done) => { + el = document.createElement('div'); + document.body.appendChild(el); + vm = new Vue({ - render(createElement) { - return createElement( - fieldComponent, - { - props: { - markdownPreviewUrl: '/preview', - markdownDocs: '/docs', - }, - }, - [ - createElement('textarea', { - slot: 'textarea', - }), - ], - ); + data() { + return { + text: 'testing\n123', + }; }, - }); + components: { + fieldComponent, + }, + template: ` + <field-component + marodown-preview-url="/preview" + markdown-docs="/docs" + > + <textarea + slot="textarea" + v-model="text"> + </textarea> + </field-component> + `, + }).$mount(el); + + Vue.nextTick(done); }); - it('creates a new instance of GL form', (done) => { - spyOn(gl, 'GLForm'); - vm.$mount(); - - Vue.nextTick(() => { - expect( - gl.GLForm, - ).toHaveBeenCalled(); - - done(); - }); + afterEach(() => { + vm.$destroy(); }); describe('mounted', () => { - beforeEach((done) => { - vm.$mount(); - - Vue.nextTick(done); - }); - it('renders textarea inside backdrop', () => { expect( vm.$el.querySelector('.zen-backdrop textarea'), @@ -117,5 +111,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(); + }); + }); + }); }); }); |