summaryrefslogtreecommitdiff
path: root/spec/frontend/notes/components/diff_with_note_spec.js
blob: 6480af015db9a7f385d32099bd11f1a1f782f8e8 (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
import { shallowMount } from '@vue/test-utils';
import DiffWithNote from '~/notes/components/diff_with_note.vue';
import { createStore } from '~/mr_notes/stores';

const discussionFixture = 'merge_requests/diff_discussion.json';
const imageDiscussionFixture = 'merge_requests/image_diff_discussion.json';

describe('diff_with_note', () => {
  let store;
  let wrapper;

  const selectors = {
    get diffTable() {
      return wrapper.find('.diff-content table');
    },
    get diffRows() {
      return wrapper.findAll('.diff-content .line_holder');
    },
    get noteRow() {
      return wrapper.find('.diff-content .notes_holder');
    },
  };

  beforeEach(() => {
    store = createStore();
    store.replaceState({
      ...store.state,
      notes: {
        noteableData: {
          current_user: {},
        },
      },
    });
  });

  describe('text diff', () => {
    beforeEach(() => {
      const diffDiscussion = getJSONFixture(discussionFixture)[0];

      wrapper = shallowMount(DiffWithNote, {
        propsData: {
          discussion: diffDiscussion,
        },
        store,
      });
    });

    it('removes trailing "+" char', () => {
      const richText = wrapper.vm.$el
        .querySelectorAll('.line_holder')[4]
        .querySelector('.line_content').textContent[0];

      expect(richText).not.toEqual('+');
    });

    it('removes trailing "-" char', () => {
      const richText = wrapper.vm.$el.querySelector('#LC13').parentNode.textContent[0];

      expect(richText).not.toEqual('-');
    });

    it('shows text diff', () => {
      expect(wrapper.classes('text-file')).toBe(true);
      expect(selectors.diffTable.exists()).toBe(true);
    });

    it('shows diff lines', () => {
      expect(selectors.diffRows.length).toBe(12);
    });

    it('shows notes row', () => {
      expect(selectors.noteRow.exists()).toBe(true);
    });
  });

  describe('image diff', () => {
    beforeEach(() => {
      const imageDiscussion = getJSONFixture(imageDiscussionFixture)[0];
      wrapper = shallowMount(DiffWithNote, {
        propsData: { discussion: imageDiscussion, diffFile: {} },
        store,
      });
    });

    it('shows image diff', () => {
      expect(selectors.diffTable.exists()).toBe(false);
    });
  });
});