summaryrefslogtreecommitdiff
path: root/spec/frontend/issue_show/components/fields/description_spec.js
blob: 8ea326ad1ee41357accd538618ccd650ed71c8ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;

  beforeEach(done => {
    const Component = Vue.extend(descriptionField);
    const el = document.createElement('div');
    store = new Store({
      titleHtml: '',
      descriptionHtml: '',
      issuableRef: '',
    });
    store.formState.description = 'test';

    document.body.appendChild(el);

    jest.spyOn(eventHub, '$emit').mockImplementation(() => {});

    vm = new Component({
      el,
      propsData: {
        markdownPreviewPath: '/',
        markdownDocsPath: '/',
        formState: store.formState,
      },
    }).$mount();

    Vue.nextTick(done);
  });

  it('renders markdown field with description', () => {
    expect(vm.$el.querySelector('.md-area textarea').value).toBe('test');
  });

  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();
    });
  });

  it('focuses field when mounted', () => {
    expect(document.activeElement).toBe(vm.$refs.textarea);
  });

  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();
  });

  it('has a ref named `textarea`', () => {
    expect(vm.$refs.textarea).not.toBeNull();
  });
});