2022-04-04 11:22:00 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Vue, { nextTick } from 'vue';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { cloneDeep } from 'lodash';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Vuex from 'vuex';
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
import DiffFileHeader from '~/diffs/components/diff_file_header.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { DIFF_FILE_AUTOMATIC_COLLAPSE, DIFF_FILE_MANUAL_COLLAPSE } from '~/diffs/constants';
|
|
|
|
import { reviewFile } from '~/diffs/store/actions';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { SET_DIFF_FILE_VIEWED, SET_MR_FILE_REVIEWS } from '~/diffs/store/mutation_types';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { diffViewerModes } from '~/ide/constants';
|
|
|
|
import { scrollToElement } from '~/lib/utils/common_utils';
|
|
|
|
import { truncateSha } from '~/lib/utils/text_utility';
|
|
|
|
import { __, sprintf } from '~/locale';
|
2019-12-04 20:38:33 +05:30
|
|
|
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
import testAction from '../../__helpers__/vuex_action_helper';
|
2019-12-04 20:38:33 +05:30
|
|
|
import diffDiscussionsMockData from '../mock_data/diff_discussions';
|
|
|
|
|
|
|
|
jest.mock('~/lib/utils/common_utils');
|
|
|
|
|
|
|
|
const diffFile = Object.freeze(
|
|
|
|
Object.assign(diffDiscussionsMockData.diff_file, {
|
2021-03-11 19:13:27 +05:30
|
|
|
id: '123',
|
2021-12-11 22:18:48 +05:30
|
|
|
file_hash: 'xyz',
|
2021-03-11 19:13:27 +05:30
|
|
|
file_identifier_hash: 'abc',
|
2019-12-04 20:38:33 +05:30
|
|
|
edit_path: 'link:/to/edit/path',
|
|
|
|
blob: {
|
|
|
|
id: '848ed9407c6730ff16edb3dd24485a0eea24292a',
|
|
|
|
path: 'lib/base.js',
|
|
|
|
name: 'base.js',
|
|
|
|
mode: '100644',
|
|
|
|
readable_text: true,
|
2021-01-03 14:25:43 +05:30
|
|
|
icon: 'doc-text',
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(Vuex);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe('DiffFileHeader component', () => {
|
|
|
|
let wrapper;
|
2020-11-24 15:15:51 +05:30
|
|
|
let mockStoreConfig;
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
const diffHasExpandedDiscussionsResultMock = jest.fn();
|
|
|
|
const diffHasDiscussionsResultMock = jest.fn();
|
2020-11-24 15:15:51 +05:30
|
|
|
const defaultMockStoreConfig = {
|
2019-12-04 20:38:33 +05:30
|
|
|
state: {},
|
|
|
|
modules: {
|
|
|
|
diffs: {
|
|
|
|
namespaced: true,
|
|
|
|
getters: {
|
|
|
|
diffHasExpandedDiscussions: () => diffHasExpandedDiscussionsResultMock,
|
|
|
|
diffHasDiscussions: () => diffHasDiscussionsResultMock,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
toggleFileDiscussions: jest.fn(),
|
|
|
|
toggleFileDiscussionWrappers: jest.fn(),
|
|
|
|
toggleFullDiff: jest.fn(),
|
2021-12-11 22:18:48 +05:30
|
|
|
setCurrentFileHash: jest.fn(),
|
2021-03-11 19:13:27 +05:30
|
|
|
setFileCollapsedByUser: jest.fn(),
|
|
|
|
reviewFile: jest.fn(),
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
[
|
|
|
|
diffHasDiscussionsResultMock,
|
|
|
|
diffHasExpandedDiscussionsResultMock,
|
|
|
|
...Object.values(mockStoreConfig.modules.diffs.actions),
|
2021-03-08 18:12:59 +05:30
|
|
|
].forEach((mock) => mock.mockReset());
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
wrapper.destroy();
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findHeader = () => wrapper.findComponent({ ref: 'header' });
|
|
|
|
const findTitleLink = () => wrapper.findComponent({ ref: 'titleWrapper' });
|
|
|
|
const findExpandButton = () => wrapper.findComponent({ ref: 'expandDiffToFullFileButton' });
|
2019-12-04 20:38:33 +05:30
|
|
|
const findFileActions = () => wrapper.find('.file-actions');
|
2022-10-11 01:57:18 +05:30
|
|
|
const findModeChangedLine = () => wrapper.findComponent({ ref: 'fileMode' });
|
2022-04-04 11:22:00 +05:30
|
|
|
const findLfsLabel = () => wrapper.find('[data-testid="label-lfs"]');
|
2022-10-11 01:57:18 +05:30
|
|
|
const findToggleDiscussionsButton = () =>
|
|
|
|
wrapper.findComponent({ ref: 'toggleDiscussionsButton' });
|
|
|
|
const findExternalLink = () => wrapper.findComponent({ ref: 'externalLink' });
|
|
|
|
const findReplacedFileButton = () => wrapper.findComponent({ ref: 'replacedFileButton' });
|
|
|
|
const findViewFileButton = () => wrapper.findComponent({ ref: 'viewButton' });
|
|
|
|
const findCollapseIcon = () => wrapper.findComponent({ ref: 'collapseIcon' });
|
|
|
|
const findEditButton = () => wrapper.findComponent({ ref: 'editButton' });
|
2021-03-11 19:13:27 +05:30
|
|
|
const findReviewFileCheckbox = () => wrapper.find("[data-testid='fileReviewCheckbox']");
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
const createComponent = ({ props, options = {} } = {}) => {
|
2020-11-24 15:15:51 +05:30
|
|
|
mockStoreConfig = cloneDeep(defaultMockStoreConfig);
|
2021-03-11 19:13:27 +05:30
|
|
|
const store = new Vuex.Store({ ...mockStoreConfig, ...(options.store || {}) });
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
wrapper = shallowMount(DiffFileHeader, {
|
|
|
|
propsData: {
|
|
|
|
diffFile,
|
|
|
|
canCurrentUserFork: false,
|
2020-07-28 23:09:34 +05:30
|
|
|
viewDiffsFileByFile: false,
|
2019-12-04 20:38:33 +05:30
|
|
|
...props,
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
...options,
|
2019-12-04 20:38:33 +05:30
|
|
|
store,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
visibility | collapsible
|
|
|
|
${'visible'} | ${true}
|
|
|
|
${'hidden'} | ${false}
|
|
|
|
`('collapse toggle is $visibility if collapsible is $collapsible', ({ collapsible }) => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { collapsible } });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findCollapseIcon().exists()).toBe(collapsible);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
expanded | icon
|
|
|
|
${true} | ${'chevron-down'}
|
|
|
|
${false} | ${'chevron-right'}
|
|
|
|
`('collapse icon is $icon if expanded is $expanded', ({ icon, expanded }) => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { expanded, collapsible: true } });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findCollapseIcon().props('name')).toBe(icon);
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('when header is clicked emits toggleFile', async () => {
|
2019-12-04 20:38:33 +05:30
|
|
|
createComponent();
|
|
|
|
findHeader().trigger('click');
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.emitted().toggleFile).toBeDefined();
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('when collapseIcon is clicked emits toggleFile', async () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { collapsible: true } });
|
2019-12-04 20:38:33 +05:30
|
|
|
findCollapseIcon().vm.$emit('click', new Event('click'));
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.emitted().toggleFile).toBeDefined();
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('when other element in header is clicked does not emits toggleFile', async () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { collapsible: true } });
|
2019-12-04 20:38:33 +05:30
|
|
|
findTitleLink().trigger('click');
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.emitted().toggleFile).not.toBeDefined();
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('copy to clipboard', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays a copy to clipboard button', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(ClipboardButton).exists()).toBe(true);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers the copy to clipboard tracking event', () => {
|
|
|
|
const trackingSpy = mockTracking('_category_', wrapper.vm.$el, jest.spyOn);
|
|
|
|
|
|
|
|
triggerEvent('[data-testid="diff-file-copy-clipboard"]');
|
|
|
|
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_copy_file_button', {
|
|
|
|
label: 'diff_copy_file_path_button',
|
|
|
|
property: 'diff_copy_file',
|
|
|
|
});
|
|
|
|
});
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('for submodule', () => {
|
|
|
|
const submoduleDiffFile = {
|
|
|
|
...diffFile,
|
|
|
|
submodule: true,
|
|
|
|
submodule_link: 'link://to/submodule',
|
|
|
|
};
|
|
|
|
|
|
|
|
it('prefers submodule_tree_url over submodule_link for href', () => {
|
|
|
|
const submoduleTreeUrl = 'some://tree/url';
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
discussionLink: 'discussionLink',
|
|
|
|
diffFile: {
|
|
|
|
...submoduleDiffFile,
|
|
|
|
submodule_tree_url: 'some://tree/url',
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findTitleLink().attributes('href')).toBe(submoduleTreeUrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses submodule_link for href if submodule_tree_url does not exists', () => {
|
|
|
|
const submoduleLink = 'link://to/submodule';
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
discussionLink: 'discussionLink',
|
|
|
|
diffFile: submoduleDiffFile,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expect(findTitleLink().attributes('href')).toBe(submoduleLink);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses file_path + SHA as link text', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: submoduleDiffFile,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expect(findTitleLink().text()).toContain(
|
|
|
|
`${diffFile.file_path} @ ${truncateSha(diffFile.blob.id)}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render file actions', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: submoduleDiffFile,
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
expect(findFileActions().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for any file', () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
const allModes = Object.keys(diffViewerModes).map((m) => [m]);
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it.each(allModes)('for %s file mode displays mode changes', (mode) => {
|
2019-12-04 20:38:33 +05:30
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
2021-12-11 22:18:48 +05:30
|
|
|
mode_changed: true,
|
2021-03-11 19:13:27 +05:30
|
|
|
a_mode: 'old-mode',
|
|
|
|
b_mode: 'new-mode',
|
|
|
|
viewer: {
|
|
|
|
...diffFile.viewer,
|
2021-12-11 22:18:48 +05:30
|
|
|
name: diffViewerModes[mode],
|
2021-03-11 19:13:27 +05:30
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(findModeChangedLine().text()).toMatch(/old-mode.+new-mode/);
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it.each(allModes.filter((m) => m[0] !== 'mode_changed'))(
|
2021-03-08 18:12:59 +05:30
|
|
|
'for %s file mode does not display mode changes',
|
|
|
|
(mode) => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
2021-12-11 22:18:48 +05:30
|
|
|
mode_changed: false,
|
2021-03-11 19:13:27 +05:30
|
|
|
a_mode: 'old-mode',
|
|
|
|
b_mode: 'new-mode',
|
|
|
|
viewer: {
|
|
|
|
...diffFile.viewer,
|
|
|
|
name: diffViewerModes[mode],
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(findModeChangedLine().exists()).toBe(false);
|
2021-03-08 18:12:59 +05:30
|
|
|
},
|
|
|
|
);
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
it('displays the LFS label for files stored in LFS', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: { ...diffFile, stored_externally: true, external_storage: 'lfs' },
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
expect(findLfsLabel().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not display the LFS label for files stored in repository', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: { ...diffFile, stored_externally: false },
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
expect(findLfsLabel().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render view replaced file button if no replaced view path is present', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: { ...diffFile, replaced_view_path: null },
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
expect(findReplacedFileButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when addMergeRequestButtons is false', () => {
|
|
|
|
it('does not render file actions', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { addMergeRequestButtons: false } });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findFileActions().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
it('should not render edit button', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { addMergeRequestButtons: false } });
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findEditButton().exists()).toBe(false);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when addMergeRequestButtons is true', () => {
|
|
|
|
describe('without discussions', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
it('does not render a toggle discussions button', () => {
|
2019-12-04 20:38:33 +05:30
|
|
|
diffHasDiscussionsResultMock.mockReturnValue(false);
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { addMergeRequestButtons: true } });
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findToggleDiscussionsButton().exists()).toBe(false);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with discussions', () => {
|
|
|
|
it('dispatches toggleFileDiscussionWrappers when user clicks on toggle discussions button', () => {
|
|
|
|
diffHasDiscussionsResultMock.mockReturnValue(true);
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { addMergeRequestButtons: true } });
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findToggleDiscussionsButton().exists()).toBe(true);
|
2019-12-04 20:38:33 +05:30
|
|
|
findToggleDiscussionsButton().vm.$emit('click');
|
|
|
|
expect(
|
|
|
|
mockStoreConfig.modules.diffs.actions.toggleFileDiscussionWrappers,
|
2020-11-24 15:15:51 +05:30
|
|
|
).toHaveBeenCalledWith(expect.any(Object), diffFile);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show edit button', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findEditButton().exists()).toBe(true);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('view on environment button', () => {
|
|
|
|
it('is displayed when external url is provided', () => {
|
|
|
|
const externalUrl = 'link://to/external';
|
|
|
|
const formattedExternalUrl = 'link://formatted';
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
external_url: externalUrl,
|
|
|
|
formatted_external_url: formattedExternalUrl,
|
|
|
|
},
|
|
|
|
addMergeRequestButtons: true,
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(findExternalLink().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is hidden by default', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { addMergeRequestButtons: true } });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findExternalLink().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without file blob', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { diffFile: { ...diffFile, blob: false } } });
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render toggle discussions button', () => {
|
|
|
|
expect(findToggleDiscussionsButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render edit button', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findEditButton().exists()).toBe(false);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('with file blob', () => {
|
|
|
|
it('should render correct file view button', () => {
|
|
|
|
const viewPath = 'link://view-path';
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: { ...diffFile, view_path: viewPath },
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
expect(findViewFileButton().attributes('href')).toBe(viewPath);
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findViewFileButton().text()).toEqual(
|
2019-12-04 20:38:33 +05:30
|
|
|
`View file @ ${diffFile.content_sha.substr(0, 8)}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('expand full file button', () => {
|
|
|
|
describe('when diff is fully expanded', () => {
|
|
|
|
it('is not rendered', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
is_fully_expanded: true,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(findExpandButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('when diff is not fully expanded', () => {
|
|
|
|
const fullyNotExpandedFileProps = {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
is_fully_expanded: false,
|
|
|
|
edit_path: 'link/to/edit/path.txt',
|
|
|
|
isShowingFullFile: false,
|
|
|
|
},
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('renders expand to full file button if not showing full file already', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: fullyNotExpandedFileProps });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findExpandButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loading icon when loading full file', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: fullyNotExpandedFileProps });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findExpandButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles full diff on click', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: fullyNotExpandedFileProps });
|
2019-12-04 20:38:33 +05:30
|
|
|
findExpandButton().vm.$emit('click');
|
|
|
|
expect(mockStoreConfig.modules.diffs.actions.toggleFullDiff).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses discussionPath for link if it is defined', () => {
|
|
|
|
const discussionPath = 'link://to/discussion';
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
discussionPath,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
expect(findTitleLink().attributes('href')).toBe(discussionPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses local anchor for link as last resort', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(findTitleLink().attributes('href')).toMatch(/^#diff-content/);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when local anchor for link is clicked', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('scrolls to target', () => {
|
|
|
|
findTitleLink().trigger('click');
|
|
|
|
expect(scrollToElement).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates anchor in URL', () => {
|
|
|
|
findTitleLink().trigger('click');
|
|
|
|
expect(window.location.href).toMatch(/#diff-content/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for new file', () => {
|
|
|
|
it('displays the path', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { diffFile: { ...diffFile, new_file: true } } });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findTitleLink().text()).toBe(diffFile.file_path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for deleted file', () => {
|
|
|
|
it('displays the path', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { diffFile: { ...diffFile, deleted_file: true } } });
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(findTitleLink().text()).toBe(
|
|
|
|
sprintf(__('%{filePath} deleted'), { filePath: diffFile.file_path }, false),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show edit button', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ props: { diffFile: { ...diffFile, deleted_file: true } } });
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findEditButton().exists()).toBe(false);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for renamed file', () => {
|
|
|
|
it('displays old and new path if the file was renamed', () => {
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
renamed_file: true,
|
|
|
|
old_path_html: 'old',
|
|
|
|
new_path_html: 'new',
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(findTitleLink().text()).toMatch(/^old.+new/s);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for replaced file', () => {
|
|
|
|
it('renders view replaced file button', () => {
|
|
|
|
const replacedViewPath = 'some/path';
|
|
|
|
createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
replaced_view_path: replacedViewPath,
|
|
|
|
},
|
|
|
|
addMergeRequestButtons: true,
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(findReplacedFileButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
describe('file reviews', () => {
|
|
|
|
it('calls the action to set the new review', () => {
|
|
|
|
createComponent({
|
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
viewer: {
|
|
|
|
...diffFile.viewer,
|
|
|
|
automaticallyCollapsed: false,
|
|
|
|
manuallyCollapsed: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
showLocalFileReviews: true,
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const file = wrapper.vm.diffFile;
|
|
|
|
|
|
|
|
findReviewFileCheckbox().vm.$emit('change', true);
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
reviewFile,
|
|
|
|
{ file, reviewed: true },
|
|
|
|
{},
|
2021-12-11 22:18:48 +05:30
|
|
|
[
|
|
|
|
{ type: SET_DIFF_FILE_VIEWED, payload: { id: file.file_hash, seen: true } },
|
|
|
|
{
|
|
|
|
type: SET_MR_FILE_REVIEWS,
|
|
|
|
payload: { [file.file_identifier_hash]: [file.id, `hash:${file.file_hash}`] },
|
|
|
|
},
|
|
|
|
],
|
2021-03-11 19:13:27 +05:30
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
description | newReviewedStatus | collapseType | aCollapse | mCollapse | callAction
|
|
|
|
${'does nothing'} | ${true} | ${DIFF_FILE_MANUAL_COLLAPSE} | ${false} | ${true} | ${false}
|
|
|
|
${'does nothing'} | ${false} | ${DIFF_FILE_AUTOMATIC_COLLAPSE} | ${true} | ${null} | ${false}
|
|
|
|
${'does nothing'} | ${true} | ${'not collapsed'} | ${false} | ${null} | ${false}
|
|
|
|
${'does nothing'} | ${false} | ${'not collapsed'} | ${false} | ${null} | ${false}
|
|
|
|
${'collapses the file'} | ${true} | ${DIFF_FILE_AUTOMATIC_COLLAPSE} | ${true} | ${null} | ${true}
|
|
|
|
`(
|
|
|
|
"$description if the new review status is reviewed = $newReviewedStatus and the file's collapse type is collapse = $collapseType",
|
|
|
|
({ newReviewedStatus, aCollapse, mCollapse, callAction }) => {
|
|
|
|
createComponent({
|
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
viewer: {
|
|
|
|
...diffFile.viewer,
|
|
|
|
automaticallyCollapsed: aCollapse,
|
|
|
|
manuallyCollapsed: mCollapse,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
showLocalFileReviews: true,
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
findReviewFileCheckbox().vm.$emit('change', newReviewedStatus);
|
|
|
|
|
|
|
|
if (callAction) {
|
|
|
|
expect(mockStoreConfig.modules.diffs.actions.setFileCollapsedByUser).toHaveBeenCalled();
|
|
|
|
} else {
|
|
|
|
expect(
|
|
|
|
mockStoreConfig.modules.diffs.actions.setFileCollapsedByUser,
|
|
|
|
).not.toHaveBeenCalled();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
description | show | visible
|
|
|
|
${'shows'} | ${true} | ${true}
|
|
|
|
${'hides'} | ${false} | ${false}
|
|
|
|
`(
|
|
|
|
'$description the file review feature given { showLocalFileReviewsProp: $show }',
|
|
|
|
({ show, visible }) => {
|
|
|
|
createComponent({
|
|
|
|
props: {
|
|
|
|
showLocalFileReviews: show,
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findReviewFileCheckbox().exists()).toEqual(visible);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
open | status | fires
|
|
|
|
${true} | ${true} | ${true}
|
|
|
|
${false} | ${false} | ${true}
|
|
|
|
${true} | ${false} | ${false}
|
|
|
|
${false} | ${true} | ${false}
|
|
|
|
`(
|
|
|
|
'toggles appropriately when { fileExpanded: $open, newReviewStatus: $status }',
|
|
|
|
({ open, status, fires }) => {
|
|
|
|
createComponent({
|
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
...diffFile,
|
|
|
|
viewer: {
|
|
|
|
...diffFile.viewer,
|
|
|
|
automaticallyCollapsed: false,
|
|
|
|
manuallyCollapsed: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
showLocalFileReviews: true,
|
|
|
|
addMergeRequestButtons: true,
|
|
|
|
expanded: open,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
findReviewFileCheckbox().vm.$emit('change', status);
|
|
|
|
|
|
|
|
expect(Boolean(wrapper.emitted().toggleFile)).toBe(fires);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|