summaryrefslogtreecommitdiff
path: root/spec/javascripts/notes/components/diff_with_note_spec.js
blob: cd59d705cde7e891ccc67258a19f89e9f2aa3439 (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
import Vue from 'vue';
import DiffWithNote from '~/notes/components/diff_with_note.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
import { diffDiscussionMock, imageDiffDiscussionMock } from '../mock_data';

describe('diff_with_note', () => {
  let vm;
  const Component = Vue.extend(DiffWithNote);
  const props = {
    discussion: diffDiscussionMock,
  };
  const selectors = {
    get container() {
      return vm.$refs.fileHolder;
    },
    get diffTable() {
      return this.container.querySelector('.diff-content table');
    },
    get diffRows() {
      return this.container.querySelectorAll('.diff-content .line_holder');
    },
    get noteRow() {
      return this.container.querySelector('.diff-content .notes_holder');
    },
  };

  describe('text diff', () => {
    beforeEach(() => {
      vm = mountComponent(Component, props);
    });

    it('shows text diff', () => {
      expect(selectors.container).toHaveClass('text-file');
      expect(selectors.diffTable).toExist();
    });

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

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

  describe('image diff', () => {
    beforeEach(() => {
      props.discussion = imageDiffDiscussionMock;
    });

    it('shows image diff', () => {
      vm = mountComponent(Component, props);

      expect(selectors.container).toHaveClass('js-image-file');
      expect(selectors.diffTable).not.toExist();
    });
  });
});