debian-mirror-gitlab/spec/frontend/diffs/components/inline_diff_view_spec.js

55 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import Vue from 'vue';
2019-02-15 15:39:39 +05:30
import '~/behaviors/markdown/render_gfm';
2020-04-22 19:07:51 +05:30
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
2020-10-24 23:57:45 +05:30
import { createStore } from '~/mr_notes/stores';
2020-01-01 13:55:28 +05:30
import InlineDiffView from '~/diffs/components/inline_diff_view.vue';
2018-11-08 19:23:39 +05:30
import diffFileMockData from '../mock_data/diff_file';
import discussionsMockData from '../mock_data/diff_discussions';
describe('InlineDiffView', () => {
let component;
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
2019-02-15 15:39:39 +05:30
beforeEach(done => {
2018-11-08 19:23:39 +05:30
const diffFile = getDiffFileMock();
2019-10-12 21:52:04 +05:30
const store = createStore();
2018-11-08 19:23:39 +05:30
store.dispatch('diffs/setInlineDiffViewType');
component = createComponentWithStore(Vue.extend(InlineDiffView), store, {
diffFile,
2019-02-15 15:39:39 +05:30
diffLines: diffFile.highlighted_diff_lines,
2018-11-08 19:23:39 +05:30
}).$mount();
2019-02-15 15:39:39 +05:30
Vue.nextTick(done);
2018-11-08 19:23:39 +05:30
});
describe('template', () => {
it('should have rendered diff lines', () => {
const el = component.$el;
2020-11-24 15:15:51 +05:30
expect(el.querySelectorAll('tr.line_holder').length).toEqual(8);
expect(el.querySelectorAll('tr.line_holder.new').length).toEqual(4);
2019-10-12 21:52:04 +05:30
expect(el.querySelectorAll('tr.line_expansion.match').length).toEqual(1);
2018-12-13 13:39:08 +05:30
expect(el.textContent.indexOf('Bad dates')).toBeGreaterThan(-1);
2018-11-08 19:23:39 +05:30
});
it('should render discussions', done => {
const el = component.$el;
2019-02-15 15:39:39 +05:30
component.diffLines[1].discussions = getDiscussionsMockData();
2019-09-30 21:07:59 +05:30
component.diffLines[1].discussionsExpanded = true;
2018-11-08 19:23:39 +05:30
Vue.nextTick(() => {
expect(el.querySelectorAll('.notes_holder').length).toEqual(1);
2019-09-30 21:07:59 +05:30
expect(el.querySelectorAll('.notes_holder .note').length).toEqual(notesLength + 1);
2018-12-13 13:39:08 +05:30
expect(el.innerText.indexOf('comment 5')).toBeGreaterThan(-1);
2018-11-08 19:23:39 +05:30
component.$store.dispatch('setInitialNotes', []);
done();
});
});
});
});