2018-11-08 19:23:39 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import DiffFileComponent from '~/diffs/components/diff_file.vue';
|
2019-05-18 00:54:41 +05:30
|
|
|
import { diffViewerModes, diffViewerErrors } from '~/ide/constants';
|
|
|
|
import store from 'ee_else_ce/mr_notes/stores';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import diffFileMockData from '../mock_data/diff_file';
|
|
|
|
|
|
|
|
describe('DiffFile', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = createComponentWithStore(Vue.extend(DiffFileComponent), store, {
|
2018-12-05 23:21:45 +05:30
|
|
|
file: JSON.parse(JSON.stringify(diffFileMockData)),
|
2018-11-08 19:23:39 +05:30
|
|
|
canCurrentUserFork: false,
|
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should render component with file header, file content components', () => {
|
|
|
|
const el = vm.$el;
|
2019-02-15 15:39:39 +05:30
|
|
|
const { file_hash, file_path } = vm.file;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(el.id).toEqual(file_hash);
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(el.classList.contains('diff-file')).toEqual(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(el.querySelectorAll('.diff-content.hidden').length).toEqual(0);
|
|
|
|
expect(el.querySelector('.js-file-title')).toBeDefined();
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(el.querySelector('.file-title-name').innerText.indexOf(file_path)).toBeGreaterThan(-1);
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(el.querySelector('.js-syntax-highlight')).toBeDefined();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
vm.file.renderIt = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(el.querySelectorAll('.line_content').length).toBeGreaterThan(5);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('collapsed', () => {
|
|
|
|
it('should not have file content', done => {
|
|
|
|
expect(vm.$el.querySelectorAll('.diff-content').length).toEqual(1);
|
2019-05-18 00:54:41 +05:30
|
|
|
expect(vm.isCollapsed).toEqual(false);
|
|
|
|
vm.isCollapsed = true;
|
2018-11-20 20:47:30 +05:30
|
|
|
vm.file.renderIt = true;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelectorAll('.diff-content').length).toEqual(0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have collapsed text and link', done => {
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.renderIt = true;
|
|
|
|
vm.isCollapsed = true;
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.innerText).toContain('This diff is collapsed');
|
|
|
|
expect(vm.$el.querySelectorAll('.js-click-to-expand').length).toEqual(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have collapsed text and link even before rendered', done => {
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.renderIt = false;
|
|
|
|
vm.isCollapsed = true;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.innerText).toContain('This diff is collapsed');
|
|
|
|
expect(vm.$el.querySelectorAll('.js-click-to-expand').length).toEqual(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it('should be collapsed for renamed files', done => {
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.renderIt = true;
|
|
|
|
vm.isCollapsed = false;
|
2019-02-15 15:39:39 +05:30
|
|
|
vm.file.highlighted_diff_lines = null;
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.file.viewer.name = diffViewerModes.renamed;
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.innerText).not.toContain('This diff is collapsed');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be collapsed for mode changed files', done => {
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.renderIt = true;
|
|
|
|
vm.isCollapsed = false;
|
2019-02-15 15:39:39 +05:30
|
|
|
vm.file.highlighted_diff_lines = null;
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.file.viewer.name = diffViewerModes.mode_changed;
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.innerText).not.toContain('This diff is collapsed');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('should have loading icon while loading a collapsed diffs', done => {
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.isCollapsed = true;
|
2018-11-08 19:23:39 +05:30
|
|
|
vm.isLoadingCollapsedDiff = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelectorAll('.diff-content.loading').length).toEqual(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-05-18 00:54:41 +05:30
|
|
|
|
|
|
|
it('should update store state', done => {
|
|
|
|
spyOn(vm.$store, 'dispatch');
|
|
|
|
|
|
|
|
vm.isCollapsed = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$store.dispatch).toHaveBeenCalledWith('diffs/setFileCollapsed', {
|
|
|
|
filePath: vm.file.file_path,
|
|
|
|
collapsed: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates local state when changing file state', done => {
|
|
|
|
vm.file.viewer.collapsed = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.isCollapsed).toBe(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('too large diff', () => {
|
|
|
|
it('should have too large warning and blob link', done => {
|
|
|
|
const BLOB_LINK = '/file/view/path';
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.file.viewer.error = diffViewerErrors.too_large;
|
|
|
|
vm.file.viewer.error_message =
|
|
|
|
'This source diff could not be displayed because it is too large';
|
2019-02-15 15:39:39 +05:30
|
|
|
vm.file.view_path = BLOB_LINK;
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.file.renderIt = true;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.innerText).toContain(
|
|
|
|
'This source diff could not be displayed because it is too large',
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
describe('watch collapsed', () => {
|
|
|
|
it('calls handleLoadCollapsedDiff if collapsed changed & file has no lines', done => {
|
|
|
|
spyOn(vm, 'handleLoadCollapsedDiff');
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
vm.file.highlighted_diff_lines = undefined;
|
|
|
|
vm.file.parallel_diff_lines = [];
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.isCollapsed = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
2019-05-18 00:54:41 +05:30
|
|
|
vm.isCollapsed = false;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.handleLoadCollapsedDiff).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|