2018-11-09 14:48:41 -05:00
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2020-11-10 07:08:57 -05:00
|
|
|
import { getByText } from '@testing-library/dom';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
2020-11-10 07:08:57 -05:00
|
|
|
import { mapInline } from '~/diffs/components/diff_row_utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import InlineDiffView from '~/diffs/components/inline_diff_view.vue';
|
|
|
|
import { createStore } from '~/mr_notes/stores';
|
2018-06-21 08:22:40 -04:00
|
|
|
import discussionsMockData from '../mock_data/diff_discussions';
|
2021-02-14 13:09:20 -05:00
|
|
|
import diffFileMockData from '../mock_data/diff_file';
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
describe('InlineDiffView', () => {
|
2020-11-10 07:08:57 -05:00
|
|
|
let wrapper;
|
2020-05-07 17:09:26 -04:00
|
|
|
const getDiffFileMock = () => ({ ...diffFileMockData });
|
|
|
|
const getDiscussionsMockData = () => [{ ...discussionsMockData }];
|
2019-07-09 00:22:48 -04:00
|
|
|
const notesLength = getDiscussionsMockData()[0].notes.length;
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
const setup = (diffFile, diffLines) => {
|
|
|
|
const mockDiffContent = {
|
|
|
|
diffFile,
|
|
|
|
shouldRenderDraftRow: jest.fn(),
|
|
|
|
};
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2019-08-11 19:57:30 -04:00
|
|
|
const store = createStore();
|
|
|
|
|
2018-07-09 08:19:12 -04:00
|
|
|
store.dispatch('diffs/setInlineDiffViewType');
|
2020-11-10 07:08:57 -05:00
|
|
|
wrapper = mount(InlineDiffView, {
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
diffFile,
|
|
|
|
diffLines: diffLines.map(mapInline(mockDiffContent)),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should have rendered diff lines', () => {
|
2020-11-10 07:08:57 -05:00
|
|
|
const diffFile = getDiffFileMock();
|
|
|
|
setup(diffFile, diffFile.highlighted_diff_lines);
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
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-06-21 08:22:40 -04:00
|
|
|
});
|
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
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-06-21 08:22:40 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
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-06-21 08:22:40 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|