2019-02-15 15:39:39 +05:30
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { getByText } from '@testing-library/dom';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { mapInline } from '~/diffs/components/diff_row_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import InlineDiffView from '~/diffs/components/inline_diff_view.vue';
|
|
|
|
import { createStore } from '~/mr_notes/stores';
|
2018-11-08 19:23:39 +05:30
|
|
|
import discussionsMockData from '../mock_data/diff_discussions';
|
2021-03-11 19:13:27 +05:30
|
|
|
import diffFileMockData from '../mock_data/diff_file';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
describe('InlineDiffView', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
let wrapper;
|
2020-05-24 23:13:21 +05:30
|
|
|
const getDiffFileMock = () => ({ ...diffFileMockData });
|
|
|
|
const getDiscussionsMockData = () => [{ ...discussionsMockData }];
|
2019-09-30 21:07:59 +05:30
|
|
|
const notesLength = getDiscussionsMockData()[0].notes.length;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
const setup = (diffFile, diffLines) => {
|
|
|
|
const mockDiffContent = {
|
|
|
|
diffFile,
|
|
|
|
shouldRenderDraftRow: jest.fn(),
|
|
|
|
};
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
const store = createStore();
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
store.dispatch('diffs/setInlineDiffViewType');
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mount(InlineDiffView, {
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
diffFile,
|
|
|
|
diffLines: diffLines.map(mapInline(mockDiffContent)),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should have rendered diff lines', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
const diffFile = getDiffFileMock();
|
|
|
|
setup(diffFile, diffFile.highlighted_diff_lines);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.findAll('tr.line_holder').length).toEqual(8);
|
|
|
|
expect(wrapper.findAll('tr.line_holder.new').length).toEqual(4);
|
|
|
|
expect(wrapper.findAll('tr.line_expansion.match').length).toEqual(1);
|
|
|
|
getByText(wrapper.element, /Bad dates/i);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('should render discussions', () => {
|
|
|
|
const diffFile = getDiffFileMock();
|
|
|
|
diffFile.highlighted_diff_lines[1].discussions = getDiscussionsMockData();
|
|
|
|
diffFile.highlighted_diff_lines[1].discussionsExpanded = true;
|
|
|
|
setup(diffFile, diffFile.highlighted_diff_lines);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.findAll('.notes_holder').length).toEqual(1);
|
|
|
|
expect(wrapper.findAll('.notes_holder .note').length).toEqual(notesLength + 1);
|
|
|
|
getByText(wrapper.element, 'comment 5');
|
|
|
|
wrapper.vm.$store.dispatch('setInitialNotes', []);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|