2020-01-01 13:55:28 +05:30
|
|
|
import { mount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
2021-11-18 22:05:49 +05:30
|
|
|
import getDiffWithCommit from 'test_fixtures/merge_request_diffs/with_commit.json';
|
2021-10-27 15:23:28 +05:30
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { trimText } from 'helpers/text_helper';
|
2020-01-01 13:55:28 +05:30
|
|
|
import CompareVersionsComponent from '~/diffs/components/compare_versions.vue';
|
|
|
|
import { createStore } from '~/mr_notes/stores';
|
2021-03-11 19:13:27 +05:30
|
|
|
import diffsMockData from '../mock_data/merge_request_diffs';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const NEXT_COMMIT_URL = `${TEST_HOST}/?commit_id=next`;
|
|
|
|
const PREV_COMMIT_URL = `${TEST_HOST}/?commit_id=prev`;
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
setWindowLocation(TEST_HOST);
|
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
describe('CompareVersions', () => {
|
|
|
|
let wrapper;
|
2021-03-08 18:12:59 +05:30
|
|
|
let store;
|
2020-04-22 19:07:51 +05:30
|
|
|
const targetBranchName = 'tmp-wine-dev';
|
2021-11-18 22:05:49 +05:30
|
|
|
const { commit } = getDiffWithCommit;
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const createWrapper = (props = {}, commitArgs = {}, createCommit = true) => {
|
|
|
|
if (createCommit) {
|
|
|
|
store.state.diffs.commit = { ...store.state.diffs.commit, ...commitArgs };
|
|
|
|
}
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
wrapper = mount(CompareVersionsComponent, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
mergeRequestDiffs: diffsMockData,
|
2021-03-08 18:12:59 +05:30
|
|
|
diffFilesCountText: '1',
|
2020-01-01 13:55:28 +05:30
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2021-03-08 18:12:59 +05:30
|
|
|
const findLimitedContainer = () => wrapper.find('.container-limited.limit-container-width');
|
|
|
|
const findCompareSourceDropdown = () => wrapper.find('.mr-version-dropdown');
|
|
|
|
const findCompareTargetDropdown = () => wrapper.find('.mr-version-compare-dropdown');
|
2021-04-29 21:17:54 +05:30
|
|
|
const getCommitNavButtonsElement = () => wrapper.find('.commit-nav-buttons');
|
|
|
|
const getNextCommitNavElement = () =>
|
|
|
|
getCommitNavButtonsElement().find('.btn-group > *:last-child');
|
|
|
|
const getPrevCommitNavElement = () =>
|
|
|
|
getCommitNavButtonsElement().find('.btn-group > *:first-child');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
store = createStore();
|
|
|
|
const mergeRequestDiff = diffsMockData[0];
|
|
|
|
|
|
|
|
store.state.diffs.addedLines = 10;
|
|
|
|
store.state.diffs.removedLines = 20;
|
|
|
|
store.state.diffs.diffFiles.push('test');
|
|
|
|
store.state.diffs.targetBranchName = targetBranchName;
|
|
|
|
store.state.diffs.mergeRequestDiff = mergeRequestDiff;
|
|
|
|
store.state.diffs.mergeRequestDiffs = diffsMockData;
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createWrapper({}, {}, false);
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it('should render Tree List toggle button with correct attribute values', () => {
|
|
|
|
const treeListBtn = wrapper.find('.js-toggle-tree-list');
|
|
|
|
|
|
|
|
expect(treeListBtn.exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(treeListBtn.attributes('title')).toBe('Hide file browser');
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(treeListBtn.props('icon')).toBe('file-tree');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render comparison dropdowns with correct values', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
const sourceDropdown = findCompareSourceDropdown();
|
|
|
|
const targetDropdown = findCompareTargetDropdown();
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
expect(sourceDropdown.exists()).toBe(true);
|
|
|
|
expect(targetDropdown.exists()).toBe(true);
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(sourceDropdown.find('a p').html()).toContain('latest version');
|
|
|
|
expect(targetDropdown.find('button').html()).toContain(targetBranchName);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render view types buttons with correct values', () => {
|
|
|
|
const inlineBtn = wrapper.find('#inline-diff-btn');
|
|
|
|
const parallelBtn = wrapper.find('#parallel-diff-btn');
|
|
|
|
|
|
|
|
expect(inlineBtn.exists()).toBe(true);
|
|
|
|
expect(parallelBtn.exists()).toBe(true);
|
|
|
|
expect(inlineBtn.attributes('data-view-type')).toEqual('inline');
|
|
|
|
expect(parallelBtn.attributes('data-view-type')).toEqual('parallel');
|
|
|
|
expect(inlineBtn.html()).toContain('Inline');
|
|
|
|
expect(parallelBtn.html()).toContain('Side-by-side');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds container-limiting classes when showFileTree is false with inline diffs', () => {
|
|
|
|
createWrapper({ isLimitedContainer: true });
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(findLimitedContainer().exists()).toBe(true);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add container-limiting classes when showFileTree is false with inline diffs', () => {
|
|
|
|
createWrapper({ isLimitedContainer: false });
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(findLimitedContainer().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
describe('noChangedFiles', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.state.diffs.diffFiles = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render Tree List toggle button when there are no changes', () => {
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
const treeListBtn = wrapper.find('.js-toggle-tree-list');
|
|
|
|
|
|
|
|
expect(treeListBtn.exists()).toBe(false);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setInlineDiffViewType', () => {
|
|
|
|
it('should persist the view type in the url', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
createWrapper();
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
const viewTypeBtn = wrapper.find('#inline-diff-btn');
|
|
|
|
viewTypeBtn.trigger('click');
|
|
|
|
|
|
|
|
expect(window.location.toString()).toContain('?view=inline');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setParallelDiffViewType', () => {
|
|
|
|
it('should persist the view type in the url', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
createWrapper();
|
2020-01-01 13:55:28 +05:30
|
|
|
const viewTypeBtn = wrapper.find('#parallel-diff-btn');
|
|
|
|
viewTypeBtn.trigger('click');
|
|
|
|
|
|
|
|
expect(window.location.toString()).toContain('?view=parallel');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('commit', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
beforeEach(() => {
|
2021-11-18 22:05:49 +05:30
|
|
|
store.state.diffs.commit = getDiffWithCommit.commit;
|
2021-03-08 18:12:59 +05:30
|
|
|
createWrapper();
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('does not render compare dropdowns', () => {
|
|
|
|
expect(findCompareSourceDropdown().exists()).toBe(false);
|
|
|
|
expect(findCompareTargetDropdown().exists()).toBe(false);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders latest version button', () => {
|
|
|
|
expect(trimText(wrapper.find('.js-latest-version').text())).toBe('Show latest version');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders short commit ID', () => {
|
|
|
|
expect(wrapper.text()).toContain('Viewing commit');
|
|
|
|
expect(wrapper.text()).toContain(wrapper.vm.commit.short_id);
|
|
|
|
});
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
describe('with no versions', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.state.diffs.mergeRequestDiffs = [];
|
|
|
|
createWrapper();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render compare dropdowns', () => {
|
|
|
|
expect(findCompareSourceDropdown().exists()).toBe(false);
|
|
|
|
expect(findCompareTargetDropdown().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
describe('without neighbor commits', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper({ commit: { ...commit, prev_commit_id: null, next_commit_id: null } });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render any navigation buttons', () => {
|
|
|
|
expect(getCommitNavButtonsElement().exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with neighbor commits', () => {
|
|
|
|
let mrCommit;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mrCommit = {
|
|
|
|
...commit,
|
|
|
|
next_commit_id: 'next',
|
|
|
|
prev_commit_id: 'prev',
|
|
|
|
};
|
|
|
|
|
|
|
|
createWrapper({}, mrCommit);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the commit navigation buttons', () => {
|
|
|
|
expect(getCommitNavButtonsElement().exists()).toEqual(true);
|
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
commit: { ...mrCommit, next_commit_id: null },
|
|
|
|
});
|
|
|
|
expect(getCommitNavButtonsElement().exists()).toEqual(true);
|
|
|
|
|
|
|
|
createWrapper({
|
|
|
|
commit: { ...mrCommit, prev_commit_id: null },
|
|
|
|
});
|
|
|
|
expect(getCommitNavButtonsElement().exists()).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('prev commit', () => {
|
|
|
|
beforeAll(() => {
|
2021-10-27 15:23:28 +05:30
|
|
|
setWindowLocation(`?commit_id=${mrCommit.id}`);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(wrapper.vm, 'moveToNeighboringCommit').mockImplementation(() => {});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses the correct href', () => {
|
|
|
|
const link = getPrevCommitNavElement();
|
|
|
|
|
|
|
|
expect(link.element.getAttribute('href')).toEqual(PREV_COMMIT_URL);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers the correct Vuex action on click', () => {
|
|
|
|
const link = getPrevCommitNavElement();
|
|
|
|
|
|
|
|
link.trigger('click');
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.moveToNeighboringCommit).toHaveBeenCalledWith({
|
|
|
|
direction: 'previous',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a disabled button when there is no prev commit', () => {
|
|
|
|
createWrapper({}, { ...mrCommit, prev_commit_id: null });
|
|
|
|
|
|
|
|
const button = getPrevCommitNavElement();
|
|
|
|
|
|
|
|
expect(button.element.hasAttribute('disabled')).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('next commit', () => {
|
|
|
|
beforeAll(() => {
|
2021-10-27 15:23:28 +05:30
|
|
|
setWindowLocation(`?commit_id=${mrCommit.id}`);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(wrapper.vm, 'moveToNeighboringCommit').mockImplementation(() => {});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses the correct href', () => {
|
|
|
|
const link = getNextCommitNavElement();
|
|
|
|
|
|
|
|
expect(link.element.getAttribute('href')).toEqual(NEXT_COMMIT_URL);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers the correct Vuex action on click', () => {
|
|
|
|
const link = getNextCommitNavElement();
|
|
|
|
|
|
|
|
link.trigger('click');
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.moveToNeighboringCommit).toHaveBeenCalledWith({ direction: 'next' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a disabled button when there is no next commit', () => {
|
|
|
|
createWrapper({}, { ...mrCommit, next_commit_id: null });
|
|
|
|
|
|
|
|
const button = getNextCommitNavElement();
|
|
|
|
|
|
|
|
expect(button.element.hasAttribute('disabled')).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|