BigW Consortium Gitlab

description_spec.js 1.78 KB
Newer Older
1
import Vue from 'vue';
2
import eventHub from '~/issue_show/event_hub';
3 4
import Store from '~/issue_show/stores';
import descriptionField from '~/issue_show/components/fields/description.vue';
5
import { keyboardDownEvent } from '../../helpers';
6 7 8 9 10 11 12

describe('Description field component', () => {
  let vm;
  let store;

  beforeEach((done) => {
    const Component = Vue.extend(descriptionField);
13
    const el = document.createElement('div');
14 15 16 17 18 19 20
    store = new Store({
      titleHtml: '',
      descriptionHtml: '',
      issuableRef: '',
    });
    store.formState.description = 'test';

21 22
    document.body.appendChild(el);

23 24
    spyOn(eventHub, '$emit');

25
    vm = new Component({
26
      el,
27 28 29
      propsData: {
        markdownPreviewUrl: '/',
        markdownDocs: '/',
30
        formState: store.formState,
31 32 33 34 35 36 37 38 39 40 41
      },
    }).$mount();

    Vue.nextTick(done);
  });

  it('renders markdown field with description', () => {
    expect(
      vm.$el.querySelector('.md-area textarea').value,
    ).toBe('test');
  });
42 43 44 45 46 47 48 49 50 51 52 53

  it('renders markdown field with a markdown description', (done) => {
    store.formState.description = '**test**';

    Vue.nextTick(() => {
      expect(
        vm.$el.querySelector('.md-area textarea').value,
      ).toBe('**test**');

      done();
    });
  });
54

55 56 57 58 59
  it('focuses field when mounted', () => {
    expect(
      document.activeElement,
    ).toBe(vm.$refs.textarea);
  });
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

  it('triggers update with meta+enter', () => {
    vm.$el.querySelector('.md-area textarea').dispatchEvent(keyboardDownEvent(13, true));

    expect(
      eventHub.$emit,
    ).toHaveBeenCalled();
  });

  it('triggers update with ctrl+enter', () => {
    vm.$el.querySelector('.md-area textarea').dispatchEvent(keyboardDownEvent(13, false, true));

    expect(
      eventHub.$emit,
    ).toHaveBeenCalled();
  });
76
});