Welcome to mirror list, hosted at ThFree Co, Russian Federation.

description_spec.js « components « issue_show « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3fdbff01a6070d8bac360933b6a16b4d8fe72d6 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import Vue from 'vue';
import descriptionComponent from '~/issue_show/components/description.vue';

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

  beforeEach(() => {
    const Component = Vue.extend(descriptionComponent);

    if (!document.querySelector('.issuable-meta')) {
      const metaData = document.createElement('div');
      metaData.classList.add('issuable-meta');
      metaData.innerHTML = '<span id="task_status"></span><span id="task_status_short"></span>';

      document.body.appendChild(metaData);
    }

    vm = new Component({
      propsData: {
        canUpdate: true,
        descriptionHtml: 'test',
        descriptionText: 'test',
        updatedAt: new Date().toString(),
        taskStatus: '',
      },
    }).$mount();
  });

  it('animates description changes', (done) => {
    vm.descriptionHtml = 'changed';

    Vue.nextTick(() => {
      expect(
        vm.$el.querySelector('.wiki').classList.contains('issue-realtime-pre-pulse'),
      ).toBeTruthy();

      setTimeout(() => {
        expect(
          vm.$el.querySelector('.wiki').classList.contains('issue-realtime-trigger-pulse'),
        ).toBeTruthy();

        done();
      });
    });
  });

  it('re-inits the TaskList when description changed', (done) => {
    spyOn(gl, 'TaskList');
    vm.descriptionHtml = 'changed';

    setTimeout(() => {
      expect(
        gl.TaskList,
      ).toHaveBeenCalled();

      done();
    });
  });

  it('does not re-init the TaskList when canUpdate is false', (done) => {
    spyOn(gl, 'TaskList');
    vm.canUpdate = false;
    vm.descriptionHtml = 'changed';

    setTimeout(() => {
      expect(
        gl.TaskList,
      ).not.toHaveBeenCalled();

      done();
    });
  });

  describe('taskStatus', () => {
    it('adds full taskStatus', (done) => {
      vm.taskStatus = '1 of 1';

      setTimeout(() => {
        expect(
          document.querySelector('.issuable-meta #task_status').textContent.trim(),
        ).toBe('1 of 1');

        done();
      });
    });

    it('adds short taskStatus', (done) => {
      vm.taskStatus = '1 of 1';

      setTimeout(() => {
        expect(
          document.querySelector('.issuable-meta #task_status_short').textContent.trim(),
        ).toBe('1/1 task');

        done();
      });
    });

    it('clears task status text when no tasks are present', (done) => {
      vm.taskStatus = '0 of 0';

      setTimeout(() => {
        expect(
          document.querySelector('.issuable-meta #task_status').textContent.trim(),
        ).toBe('');

        done();
      });
    });
  });

  it('applies syntax highlighting and math when description changed', (done) => {
    spyOn(vm, 'renderGFM').and.callThrough();
    spyOn($.prototype, 'renderGFM').and.callThrough();
    vm.descriptionHtml = 'changed';

    Vue.nextTick(() => {
      setTimeout(() => {
        expect(vm.$refs['gfm-content']).toBeDefined();
        expect(vm.renderGFM).toHaveBeenCalled();
        expect($.prototype.renderGFM).toHaveBeenCalled();

        done();
      });
    });
  });
});