debian-mirror-gitlab/spec/javascripts/notes/components/diff_with_note_spec.js

90 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-03-27 19:54:05 +05:30
import Vue from 'vue';
import DiffWithNote from '~/notes/components/diff_with_note.vue';
2018-12-13 13:39:08 +05:30
import { createStore } from '~/mr_notes/stores';
2018-11-08 19:23:39 +05:30
import { mountComponentWithStore } from 'spec/helpers';
2018-03-27 19:54:05 +05:30
const discussionFixture = 'merge_requests/diff_discussion.json';
const imageDiscussionFixture = 'merge_requests/image_diff_discussion.json';
describe('diff_with_note', () => {
2018-11-08 19:23:39 +05:30
let store;
2018-03-27 19:54:05 +05:30
let vm;
const diffDiscussionMock = getJSONFixture(discussionFixture)[0];
2019-02-15 15:39:39 +05:30
const diffDiscussion = diffDiscussionMock;
2018-03-27 19:54:05 +05:30
const Component = Vue.extend(DiffWithNote);
const props = {
discussion: diffDiscussion,
};
const selectors = {
get container() {
2019-02-15 15:39:39 +05:30
return vm.$el;
2018-03-27 19:54:05 +05:30
},
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');
},
};
2018-11-08 19:23:39 +05:30
beforeEach(() => {
store = createStore();
store.replaceState({
...store.state,
notes: {
noteableData: {
current_user: {},
},
},
});
});
2018-03-27 19:54:05 +05:30
describe('text diff', () => {
beforeEach(() => {
2018-11-08 19:23:39 +05:30
vm = mountComponentWithStore(Component, { props, store });
2018-03-27 19:54:05 +05:30
});
2019-09-30 21:07:59 +05:30
it('removes trailing "+" char', () => {
const richText = vm.$el.querySelectorAll('.line_holder')[4].querySelector('.line_content')
.textContent[0];
expect(richText).not.toEqual('+');
});
it('removes trailing "-" char', () => {
const richText = vm.$el.querySelector('#LC13').parentNode.textContent[0];
expect(richText).not.toEqual('-');
});
2018-03-27 19:54:05 +05:30
it('shows text diff', () => {
expect(selectors.container).toHaveClass('text-file');
expect(selectors.diffTable).toExist();
});
it('shows diff lines', () => {
expect(selectors.diffRows.length).toBe(12);
});
it('shows notes row', () => {
expect(selectors.noteRow).toExist();
});
});
describe('image diff', () => {
beforeEach(() => {
const imageDiffDiscussionMock = getJSONFixture(imageDiscussionFixture)[0];
2019-02-15 15:39:39 +05:30
props.discussion = imageDiffDiscussionMock;
2018-03-27 19:54:05 +05:30
});
it('shows image diff', () => {
2018-11-08 19:23:39 +05:30
vm = mountComponentWithStore(Component, { props, store });
2018-03-27 19:54:05 +05:30
expect(selectors.diffTable).not.toExist();
});
});
});