debian-mirror-gitlab/spec/javascripts/issue_show/components/fields/description_spec.js

71 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
import eventHub from '~/issue_show/event_hub';
import Store from '~/issue_show/stores';
import descriptionField from '~/issue_show/components/fields/description.vue';
import { keyboardDownEvent } from '../../helpers';
describe('Description field component', () => {
let vm;
let store;
2018-12-13 13:39:08 +05:30
beforeEach(done => {
2017-09-10 17:25:29 +05:30
const Component = Vue.extend(descriptionField);
const el = document.createElement('div');
store = new Store({
titleHtml: '',
descriptionHtml: '',
issuableRef: '',
});
store.formState.description = 'test';
document.body.appendChild(el);
spyOn(eventHub, '$emit');
vm = new Component({
el,
propsData: {
2018-03-17 18:26:18 +05:30
markdownPreviewPath: '/',
markdownDocsPath: '/',
2017-09-10 17:25:29 +05:30
formState: store.formState,
},
}).$mount();
Vue.nextTick(done);
});
it('renders markdown field with description', () => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.md-area textarea').value).toBe('test');
2017-09-10 17:25:29 +05:30
});
2018-12-13 13:39:08 +05:30
it('renders markdown field with a markdown description', done => {
2017-09-10 17:25:29 +05:30
store.formState.description = '**test**';
Vue.nextTick(() => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.md-area textarea').value).toBe('**test**');
2017-09-10 17:25:29 +05:30
done();
});
});
it('focuses field when mounted', () => {
2018-12-13 13:39:08 +05:30
expect(document.activeElement).toBe(vm.$refs.textarea);
2017-09-10 17:25:29 +05:30
});
it('triggers update with meta+enter', () => {
vm.$el.querySelector('.md-area textarea').dispatchEvent(keyboardDownEvent(13, true));
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalled();
2017-09-10 17:25:29 +05:30
});
it('triggers update with ctrl+enter', () => {
vm.$el.querySelector('.md-area textarea').dispatchEvent(keyboardDownEvent(13, false, true));
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalled();
2017-09-10 17:25:29 +05:30
});
2019-07-31 22:56:46 +05:30
it('has a ref named `textarea`', () => {
expect(vm.$refs.textarea).not.toBeNull();
});
2017-09-10 17:25:29 +05:30
});