2018-11-08 19:23:39 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import DiffContentComponent from '~/diffs/components/diff_content.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/vue_mount_component_helper';
|
|
|
|
import { GREEN_BOX_IMAGE_URL, RED_BOX_IMAGE_URL } from 'spec/test_constants';
|
2018-12-13 13:39:08 +05:30
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2018-11-08 19:23:39 +05:30
|
|
|
import diffFileMockData from '../mock_data/diff_file';
|
2018-12-13 13:39:08 +05:30
|
|
|
import discussionsMockData from '../mock_data/diff_discussions';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
describe('DiffContent', () => {
|
|
|
|
const Component = Vue.extend(DiffContentComponent);
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
const store = createStore();
|
|
|
|
store.state.notes.noteableData = {
|
|
|
|
current_user: {
|
|
|
|
can_create_note: false,
|
|
|
|
},
|
2018-12-23 12:14:25 +05:30
|
|
|
preview_note_path: 'path/to/preview',
|
2018-12-13 13:39:08 +05:30
|
|
|
};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
vm = mountComponentWithStore(Component, {
|
|
|
|
store,
|
|
|
|
props: {
|
2018-12-05 23:21:45 +05:30
|
|
|
diffFile: JSON.parse(JSON.stringify(diffFileMockData)),
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('text based files', () => {
|
|
|
|
it('should render diff inline view', done => {
|
|
|
|
vm.$store.state.diffs.diffViewType = 'inline';
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelectorAll('.js-diff-inline-view').length).toEqual(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render diff parallel view', done => {
|
|
|
|
vm.$store.state.diffs.diffViewType = 'parallel';
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelectorAll('.parallel').length).toEqual(18);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Non-Text diffs', () => {
|
|
|
|
beforeEach(() => {
|
2018-12-05 23:21:45 +05:30
|
|
|
vm.diffFile.viewer.name = 'image';
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('image diff', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-12-23 12:14:25 +05:30
|
|
|
vm.diffFile.new_path = GREEN_BOX_IMAGE_URL;
|
|
|
|
vm.diffFile.new_sha = 'DEF';
|
|
|
|
vm.diffFile.old_path = RED_BOX_IMAGE_URL;
|
|
|
|
vm.diffFile.old_sha = 'ABC';
|
|
|
|
vm.diffFile.view_path = '';
|
2018-12-13 13:39:08 +05:30
|
|
|
vm.diffFile.discussions = [{ ...discussionsMockData }];
|
|
|
|
vm.$store.state.diffs.commentForms.push({
|
2018-12-23 12:14:25 +05:30
|
|
|
fileHash: vm.diffFile.file_hash,
|
2018-12-13 13:39:08 +05:30
|
|
|
x: 10,
|
|
|
|
y: 20,
|
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.$nextTick(done);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should have image diff view in place', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.js-diff-inline-view').length).toEqual(0);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.diff-viewer .image').length).toEqual(1);
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('renders image diff overlay', () => {
|
|
|
|
expect(vm.$el.querySelector('.image-diff-overlay')).not.toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders diff file discussions', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.discussion .note.timeline-entry').length).toEqual(5);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('handleSaveNote', () => {
|
|
|
|
it('dispatches handleSaveNote', () => {
|
|
|
|
spyOn(vm.$store, 'dispatch').and.stub();
|
|
|
|
|
|
|
|
vm.handleSaveNote('test');
|
|
|
|
|
|
|
|
expect(vm.$store.dispatch).toHaveBeenCalledWith('diffs/saveDiffDiscussion', {
|
|
|
|
note: 'test',
|
|
|
|
formData: {
|
|
|
|
noteableData: jasmine.anything(),
|
|
|
|
noteableType: jasmine.anything(),
|
|
|
|
diffFile: vm.diffFile,
|
|
|
|
positionType: 'image',
|
|
|
|
x: 10,
|
|
|
|
y: 20,
|
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
},
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('file diff', () => {
|
|
|
|
it('should have download buttons in place', done => {
|
|
|
|
const el = vm.$el;
|
2018-12-23 12:14:25 +05:30
|
|
|
vm.diffFile.new_path = 'test.abc';
|
|
|
|
vm.diffFile.new_sha = 'DEF';
|
|
|
|
vm.diffFile.old_path = 'test.abc';
|
|
|
|
vm.diffFile.old_sha = 'ABC';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(el.querySelectorAll('.js-diff-inline-view').length).toEqual(0);
|
|
|
|
|
|
|
|
expect(el.querySelector('.deleted .file-info').textContent.trim()).toContain('test.abc');
|
|
|
|
expect(el.querySelector('.deleted .btn.btn-default').textContent.trim()).toContain(
|
|
|
|
'Download',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(el.querySelector('.added .file-info').textContent.trim()).toContain('test.abc');
|
|
|
|
expect(el.querySelector('.added .btn.btn-default').textContent.trim()).toContain(
|
|
|
|
'Download',
|
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|