Commit 87b0c6c9 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'ph/241188/removeUnifiedDiffLinesFeatureFlag' into 'master'

Remove the unified diff lines feature flag

See merge request gitlab-org/gitlab!46024
parents eb4dd716 aa84c42f
...@@ -230,9 +230,6 @@ export default { ...@@ -230,9 +230,6 @@ export default {
} }
}, },
diffViewType() { diffViewType() {
if (!this.glFeatures.unifiedDiffLines && (this.needsReload() || this.needsFirstLoad())) {
this.refetchDiffData();
}
this.adjustView(); this.adjustView();
}, },
shouldShow() { shouldShow() {
......
...@@ -87,7 +87,7 @@ export default { ...@@ -87,7 +87,7 @@ export default {
return this.getUserData; return this.getUserData;
}, },
mappedLines() { mappedLines() {
if (this.glFeatures.unifiedDiffLines && this.glFeatures.unifiedDiffComponents) { if (this.glFeatures.unifiedDiffComponents) {
return this.diffLines(this.diffFile, true).map(mapParallel(this)) || []; return this.diffLines(this.diffFile, true).map(mapParallel(this)) || [];
} }
...@@ -95,9 +95,7 @@ export default { ...@@ -95,9 +95,7 @@ export default {
if (this.isInlineView) { if (this.isInlineView) {
return this.diffFile.highlighted_diff_lines.map(mapInline(this)); return this.diffFile.highlighted_diff_lines.map(mapInline(this));
} }
return this.glFeatures.unifiedDiffLines return this.diffLines(this.diffFile).map(mapParallel(this));
? this.diffLines(this.diffFile).map(mapParallel(this))
: this.diffFile.parallel_diff_lines.map(mapParallel(this)) || [];
}, },
}, },
updated() { updated() {
...@@ -129,9 +127,7 @@ export default { ...@@ -129,9 +127,7 @@ export default {
<template> <template>
<div class="diff-content"> <div class="diff-content">
<div class="diff-viewer"> <div class="diff-viewer">
<template <template v-if="isTextFile && glFeatures.unifiedDiffComponents">
v-if="isTextFile && glFeatures.unifiedDiffLines && glFeatures.unifiedDiffComponents"
>
<diff-view <diff-view
:diff-file="diffFile" :diff-file="diffFile"
:diff-lines="mappedLines" :diff-lines="mappedLines"
......
...@@ -4,7 +4,7 @@ import { GlIcon } from '@gitlab/ui'; ...@@ -4,7 +4,7 @@ import { GlIcon } from '@gitlab/ui';
import { deprecatedCreateFlash as createFlash } from '~/flash'; import { deprecatedCreateFlash as createFlash } from '~/flash';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { UNFOLD_COUNT, INLINE_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '../constants'; import { UNFOLD_COUNT, INLINE_DIFF_VIEW_TYPE, INLINE_DIFF_LINES_KEY } from '../constants';
import * as utils from '../store/utils'; import * as utils from '../store/utils';
const EXPAND_ALL = 0; const EXPAND_ALL = 0;
...@@ -14,7 +14,6 @@ const EXPAND_DOWN = 2; ...@@ -14,7 +14,6 @@ const EXPAND_DOWN = 2;
const lineNumberByViewType = (viewType, diffLine) => { const lineNumberByViewType = (viewType, diffLine) => {
const numberGetters = { const numberGetters = {
[INLINE_DIFF_VIEW_TYPE]: line => line?.new_line, [INLINE_DIFF_VIEW_TYPE]: line => line?.new_line,
[PARALLEL_DIFF_VIEW_TYPE]: line => (line?.right || line?.left)?.new_line,
}; };
const numberGetter = numberGetters[viewType]; const numberGetter = numberGetters[viewType];
return numberGetter && numberGetter(diffLine); return numberGetter && numberGetter(diffLine);
...@@ -57,9 +56,6 @@ export default { ...@@ -57,9 +56,6 @@ export default {
}, },
computed: { computed: {
...mapState({ ...mapState({
diffViewType(state) {
return this.glFeatures.unifiedDiffLines ? INLINE_DIFF_VIEW_TYPE : state.diffs.diffViewType;
},
diffFiles: state => state.diffs.diffFiles, diffFiles: state => state.diffs.diffFiles,
}), }),
canExpandUp() { canExpandUp() {
...@@ -77,16 +73,14 @@ export default { ...@@ -77,16 +73,14 @@ export default {
...mapActions('diffs', ['loadMoreLines']), ...mapActions('diffs', ['loadMoreLines']),
getPrevLineNumber(oldLineNumber, newLineNumber) { getPrevLineNumber(oldLineNumber, newLineNumber) {
const diffFile = utils.findDiffFile(this.diffFiles, this.fileHash); const diffFile = utils.findDiffFile(this.diffFiles, this.fileHash);
const lines = { const index = utils.getPreviousLineIndex(INLINE_DIFF_VIEW_TYPE, diffFile, {
[INLINE_DIFF_VIEW_TYPE]: diffFile.highlighted_diff_lines,
[PARALLEL_DIFF_VIEW_TYPE]: diffFile.parallel_diff_lines,
};
const index = utils.getPreviousLineIndex(this.diffViewType, diffFile, {
oldLineNumber, oldLineNumber,
newLineNumber, newLineNumber,
}); });
return lineNumberByViewType(this.diffViewType, lines[this.diffViewType][index - 2]) || 0; return (
lineNumberByViewType(INLINE_DIFF_VIEW_TYPE, diffFile[INLINE_DIFF_LINES_KEY][index - 2]) || 0
);
}, },
callLoadMoreLines( callLoadMoreLines(
endpoint, endpoint,
...@@ -113,7 +107,7 @@ export default { ...@@ -113,7 +107,7 @@ export default {
this.isRequesting = true; this.isRequesting = true;
const endpoint = this.contextLinesPath; const endpoint = this.contextLinesPath;
const { fileHash } = this; const { fileHash } = this;
const view = this.diffViewType; const view = INLINE_DIFF_VIEW_TYPE;
const oldLineNumber = this.line.meta_data.old_pos || 0; const oldLineNumber = this.line.meta_data.old_pos || 0;
const newLineNumber = this.line.meta_data.new_pos || 0; const newLineNumber = this.line.meta_data.new_pos || 0;
const offset = newLineNumber - oldLineNumber; const offset = newLineNumber - oldLineNumber;
......
...@@ -7,7 +7,7 @@ import noteForm from '../../notes/components/note_form.vue'; ...@@ -7,7 +7,7 @@ import noteForm from '../../notes/components/note_form.vue';
import MultilineCommentForm from '../../notes/components/multiline_comment_form.vue'; import MultilineCommentForm from '../../notes/components/multiline_comment_form.vue';
import autosave from '../../notes/mixins/autosave'; import autosave from '../../notes/mixins/autosave';
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import { DIFF_NOTE_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '../constants'; import { DIFF_NOTE_TYPE, INLINE_DIFF_LINES_KEY, PARALLEL_DIFF_VIEW_TYPE } from '../constants';
import { import {
commentLineOptions, commentLineOptions,
formatLineRange, formatLineRange,
...@@ -102,13 +102,13 @@ export default { ...@@ -102,13 +102,13 @@ export default {
}; };
const getDiffLines = () => { const getDiffLines = () => {
if (this.diffViewType === PARALLEL_DIFF_VIEW_TYPE) { if (this.diffViewType === PARALLEL_DIFF_VIEW_TYPE) {
return (this.glFeatures.unifiedDiffLines return this.diffLines(this.diffFile, this.glFeatures.unifiedDiffComponents).reduce(
? this.diffLines(this.diffFile) combineSides,
: this.diffFile.parallel_diff_lines [],
).reduce(combineSides, []); );
} }
return this.diffFile.highlighted_diff_lines; return this.diffFile[INLINE_DIFF_LINES_KEY];
}; };
const side = this.line.type === 'new' ? 'right' : 'left'; const side = this.line.type === 'new' ? 'right' : 'left';
const lines = getDiffLines(); const lines = getDiffLines();
......
...@@ -30,13 +30,11 @@ import { ...@@ -30,13 +30,11 @@ import {
OLD_LINE_KEY, OLD_LINE_KEY,
NEW_LINE_KEY, NEW_LINE_KEY,
TYPE_KEY, TYPE_KEY,
LEFT_LINE_KEY,
MAX_RENDERING_DIFF_LINES, MAX_RENDERING_DIFF_LINES,
MAX_RENDERING_BULK_ROWS, MAX_RENDERING_BULK_ROWS,
MIN_RENDERING_MS, MIN_RENDERING_MS,
START_RENDERING_INDEX, START_RENDERING_INDEX,
INLINE_DIFF_LINES_KEY, INLINE_DIFF_LINES_KEY,
PARALLEL_DIFF_LINES_KEY,
DIFFS_PER_PAGE, DIFFS_PER_PAGE,
DIFF_WHITESPACE_COOKIE_NAME, DIFF_WHITESPACE_COOKIE_NAME,
SHOW_WHITESPACE, SHOW_WHITESPACE,
...@@ -77,7 +75,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { ...@@ -77,7 +75,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
const urlParams = { const urlParams = {
per_page: DIFFS_PER_PAGE, per_page: DIFFS_PER_PAGE,
w: state.showWhitespace ? '0' : '1', w: state.showWhitespace ? '0' : '1',
view: window.gon?.features?.unifiedDiffLines ? 'inline' : state.diffViewType, view: 'inline',
}; };
commit(types.SET_BATCH_LOADING, true); commit(types.SET_BATCH_LOADING, true);
...@@ -140,7 +138,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { ...@@ -140,7 +138,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
export const fetchDiffFilesMeta = ({ commit, state }) => { export const fetchDiffFilesMeta = ({ commit, state }) => {
const worker = new TreeWorker(); const worker = new TreeWorker();
const urlParams = { const urlParams = {
view: window.gon?.features?.unifiedDiffLines ? 'inline' : state.diffViewType, view: 'inline',
}; };
commit(types.SET_LOADING, true); commit(types.SET_LOADING, true);
...@@ -401,15 +399,10 @@ export const toggleFileDiscussions = ({ getters, dispatch }, diff) => { ...@@ -401,15 +399,10 @@ export const toggleFileDiscussions = ({ getters, dispatch }, diff) => {
export const toggleFileDiscussionWrappers = ({ commit }, diff) => { export const toggleFileDiscussionWrappers = ({ commit }, diff) => {
const discussionWrappersExpanded = allDiscussionWrappersExpanded(diff); const discussionWrappersExpanded = allDiscussionWrappersExpanded(diff);
const lineCodesWithDiscussions = new Set(); const lineCodesWithDiscussions = new Set();
const { parallel_diff_lines: parallelLines, highlighted_diff_lines: inlineLines } = diff;
const allLines = inlineLines.concat(
parallelLines.map(line => line.left),
parallelLines.map(line => line.right),
);
const lineHasDiscussion = line => Boolean(line?.discussions.length); const lineHasDiscussion = line => Boolean(line?.discussions.length);
const registerDiscussionLine = line => lineCodesWithDiscussions.add(line.line_code); const registerDiscussionLine = line => lineCodesWithDiscussions.add(line.line_code);
allLines.filter(lineHasDiscussion).forEach(registerDiscussionLine); diff[INLINE_DIFF_LINES_KEY].filter(lineHasDiscussion).forEach(registerDiscussionLine);
if (lineCodesWithDiscussions.size) { if (lineCodesWithDiscussions.size) {
Array.from(lineCodesWithDiscussions).forEach(lineCode => { Array.from(lineCodesWithDiscussions).forEach(lineCode => {
...@@ -508,10 +501,9 @@ export const receiveFullDiffError = ({ commit }, filePath) => { ...@@ -508,10 +501,9 @@ export const receiveFullDiffError = ({ commit }, filePath) => {
createFlash(s__('MergeRequest|Error loading full diff. Please try again.')); createFlash(s__('MergeRequest|Error loading full diff. Please try again.'));
}; };
export const setExpandedDiffLines = ({ commit, state }, { file, data }) => { export const setExpandedDiffLines = ({ commit }, { file, data }) => {
const expandedDiffLines = { const expandedDiffLines = convertExpandLines({
highlighted_diff_lines: convertExpandLines({ diffLines: file[INLINE_DIFF_LINES_KEY],
diffLines: file.highlighted_diff_lines,
typeKey: TYPE_KEY, typeKey: TYPE_KEY,
oldLineKey: OLD_LINE_KEY, oldLineKey: OLD_LINE_KEY,
newLineKey: NEW_LINE_KEY, newLineKey: NEW_LINE_KEY,
...@@ -522,47 +514,13 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => { ...@@ -522,47 +514,13 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => {
new_line: newLine, new_line: newLine,
line_code: `${file.file_hash}_${oldLine}_${newLine}`, line_code: `${file.file_hash}_${oldLine}_${newLine}`,
}), }),
}),
parallel_diff_lines: convertExpandLines({
diffLines: file.parallel_diff_lines,
typeKey: [LEFT_LINE_KEY, TYPE_KEY],
oldLineKey: [LEFT_LINE_KEY, OLD_LINE_KEY],
newLineKey: [LEFT_LINE_KEY, NEW_LINE_KEY],
data,
mapLine: ({ line, oldLine, newLine }) => ({
left: {
...line,
old_line: oldLine,
line_code: `${file.file_hash}_${oldLine}_${newLine}`,
},
right: {
...line,
new_line: newLine,
line_code: `${file.file_hash}_${newLine}_${oldLine}`,
},
}),
}),
};
const unifiedDiffLinesEnabled = window.gon?.features?.unifiedDiffLines;
const currentDiffLinesKey =
state.diffViewType === INLINE_DIFF_VIEW_TYPE || unifiedDiffLinesEnabled
? INLINE_DIFF_LINES_KEY
: PARALLEL_DIFF_LINES_KEY;
const hiddenDiffLinesKey =
state.diffViewType === INLINE_DIFF_VIEW_TYPE ? PARALLEL_DIFF_LINES_KEY : INLINE_DIFF_LINES_KEY;
if (!unifiedDiffLinesEnabled) {
commit(types.SET_HIDDEN_VIEW_DIFF_FILE_LINES, {
filePath: file.file_path,
lines: expandedDiffLines[hiddenDiffLinesKey],
}); });
}
if (expandedDiffLines[currentDiffLinesKey].length > MAX_RENDERING_DIFF_LINES) { if (expandedDiffLines.length > MAX_RENDERING_DIFF_LINES) {
let index = START_RENDERING_INDEX; let index = START_RENDERING_INDEX;
commit(types.SET_CURRENT_VIEW_DIFF_FILE_LINES, { commit(types.SET_CURRENT_VIEW_DIFF_FILE_LINES, {
filePath: file.file_path, filePath: file.file_path,
lines: expandedDiffLines[currentDiffLinesKey].slice(0, index), lines: expandedDiffLines.slice(0, index),
}); });
commit(types.TOGGLE_DIFF_FILE_RENDERING_MORE, file.file_path); commit(types.TOGGLE_DIFF_FILE_RENDERING_MORE, file.file_path);
...@@ -571,10 +529,10 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => { ...@@ -571,10 +529,10 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => {
while ( while (
t.timeRemaining() >= MIN_RENDERING_MS && t.timeRemaining() >= MIN_RENDERING_MS &&
index !== expandedDiffLines[currentDiffLinesKey].length && index !== expandedDiffLines.length &&
index - startIndex !== MAX_RENDERING_BULK_ROWS index - startIndex !== MAX_RENDERING_BULK_ROWS
) { ) {
const line = expandedDiffLines[currentDiffLinesKey][index]; const line = expandedDiffLines[index];
if (line) { if (line) {
commit(types.ADD_CURRENT_VIEW_DIFF_FILE_LINES, { filePath: file.file_path, line }); commit(types.ADD_CURRENT_VIEW_DIFF_FILE_LINES, { filePath: file.file_path, line });
...@@ -582,7 +540,7 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => { ...@@ -582,7 +540,7 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => {
} }
} }
if (index !== expandedDiffLines[currentDiffLinesKey].length) { if (index !== expandedDiffLines.length) {
idleCallback(idleCb); idleCallback(idleCb);
} else { } else {
commit(types.TOGGLE_DIFF_FILE_RENDERING_MORE, file.file_path); commit(types.TOGGLE_DIFF_FILE_RENDERING_MORE, file.file_path);
...@@ -593,7 +551,7 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => { ...@@ -593,7 +551,7 @@ export const setExpandedDiffLines = ({ commit, state }, { file, data }) => {
} else { } else {
commit(types.SET_CURRENT_VIEW_DIFF_FILE_LINES, { commit(types.SET_CURRENT_VIEW_DIFF_FILE_LINES, {
filePath: file.file_path, filePath: file.file_path,
lines: expandedDiffLines[currentDiffLinesKey], lines: expandedDiffLines,
}); });
} }
}; };
...@@ -627,7 +585,7 @@ export const toggleFullDiff = ({ dispatch, commit, getters, state }, filePath) = ...@@ -627,7 +585,7 @@ export const toggleFullDiff = ({ dispatch, commit, getters, state }, filePath) =
} }
}; };
export function switchToFullDiffFromRenamedFile({ commit, dispatch, state }, { diffFile }) { export function switchToFullDiffFromRenamedFile({ commit, dispatch }, { diffFile }) {
return axios return axios
.get(diffFile.context_lines_path, { .get(diffFile.context_lines_path, {
params: { params: {
...@@ -638,7 +596,7 @@ export function switchToFullDiffFromRenamedFile({ commit, dispatch, state }, { d ...@@ -638,7 +596,7 @@ export function switchToFullDiffFromRenamedFile({ commit, dispatch, state }, { d
.then(({ data }) => { .then(({ data }) => {
const lines = data.map((line, index) => const lines = data.map((line, index) =>
prepareLineForRenamedFile({ prepareLineForRenamedFile({
diffViewType: window.gon?.features?.unifiedDiffLines ? 'inline' : state.diffViewType, diffViewType: 'inline',
line, line,
diffFile, diffFile,
index, index,
......
import { __, n__ } from '~/locale'; import { __, n__ } from '~/locale';
import { parallelizeDiffLines } from './utils'; import { parallelizeDiffLines } from './utils';
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants'; import {
PARALLEL_DIFF_VIEW_TYPE,
INLINE_DIFF_VIEW_TYPE,
INLINE_DIFF_LINES_KEY,
} from '../constants';
export * from './getters_versions_dropdowns'; export * from './getters_versions_dropdowns';
...@@ -54,24 +58,10 @@ export const diffHasAllCollapsedDiscussions = (state, getters) => diff => { ...@@ -54,24 +58,10 @@ export const diffHasAllCollapsedDiscussions = (state, getters) => diff => {
* @param {Object} diff * @param {Object} diff
* @returns {Boolean} * @returns {Boolean}
*/ */
export const diffHasExpandedDiscussions = state => diff => { export const diffHasExpandedDiscussions = () => diff => {
const lines = { return diff[INLINE_DIFF_LINES_KEY].filter(l => l.discussions.length >= 1).some(
[INLINE_DIFF_VIEW_TYPE]: diff.highlighted_diff_lines || [], l => l.discussionsExpanded,
[PARALLEL_DIFF_VIEW_TYPE]: (diff.parallel_diff_lines || []).reduce((acc, line) => { );
if (line.left) {
acc.push(line.left);
}
if (line.right) {
acc.push(line.right);
}
return acc;
}, []),
};
return lines[window.gon?.features?.unifiedDiffLines ? 'inline' : state.diffViewType]
.filter(l => l.discussions.length >= 1)
.some(l => l.discussionsExpanded);
}; };
/** /**
...@@ -79,24 +69,8 @@ export const diffHasExpandedDiscussions = state => diff => { ...@@ -79,24 +69,8 @@ export const diffHasExpandedDiscussions = state => diff => {
* @param {Boolean} diff * @param {Boolean} diff
* @returns {Boolean} * @returns {Boolean}
*/ */
export const diffHasDiscussions = state => diff => { export const diffHasDiscussions = () => diff => {
const lines = { return diff[INLINE_DIFF_LINES_KEY].some(l => l.discussions.length >= 1);
[INLINE_DIFF_VIEW_TYPE]: diff.highlighted_diff_lines || [],
[PARALLEL_DIFF_VIEW_TYPE]: (diff.parallel_diff_lines || []).reduce((acc, line) => {
if (line.left) {
acc.push(line.left);
}
if (line.right) {
acc.push(line.right);
}
return acc;
}, []),
};
return lines[window.gon?.features?.unifiedDiffLines ? 'inline' : state.diffViewType].some(
l => l.discussions.length >= 1,
);
}; };
/** /**
......
...@@ -35,7 +35,6 @@ export const RECEIVE_FULL_DIFF_SUCCESS = 'RECEIVE_FULL_DIFF_SUCCESS'; ...@@ -35,7 +35,6 @@ export const RECEIVE_FULL_DIFF_SUCCESS = 'RECEIVE_FULL_DIFF_SUCCESS';
export const RECEIVE_FULL_DIFF_ERROR = 'RECEIVE_FULL_DIFF_ERROR'; export const RECEIVE_FULL_DIFF_ERROR = 'RECEIVE_FULL_DIFF_ERROR';
export const SET_FILE_COLLAPSED = 'SET_FILE_COLLAPSED'; export const SET_FILE_COLLAPSED = 'SET_FILE_COLLAPSED';
export const SET_HIDDEN_VIEW_DIFF_FILE_LINES = 'SET_HIDDEN_VIEW_DIFF_FILE_LINES';
export const SET_CURRENT_VIEW_DIFF_FILE_LINES = 'SET_CURRENT_VIEW_DIFF_FILE_LINES'; export const SET_CURRENT_VIEW_DIFF_FILE_LINES = 'SET_CURRENT_VIEW_DIFF_FILE_LINES';
export const ADD_CURRENT_VIEW_DIFF_FILE_LINES = 'ADD_CURRENT_VIEW_DIFF_FILE_LINES'; export const ADD_CURRENT_VIEW_DIFF_FILE_LINES = 'ADD_CURRENT_VIEW_DIFF_FILE_LINES';
export const TOGGLE_DIFF_FILE_RENDERING_MORE = 'TOGGLE_DIFF_FILE_RENDERING_MORE'; export const TOGGLE_DIFF_FILE_RENDERING_MORE = 'TOGGLE_DIFF_FILE_RENDERING_MORE';
......
import Vue from 'vue'; import Vue from 'vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import {
DIFF_FILE_MANUAL_COLLAPSE,
DIFF_FILE_AUTOMATIC_COLLAPSE,
INLINE_DIFF_VIEW_TYPE,
} from '../constants';
import { import {
findDiffFile, findDiffFile,
addLineReferences, addLineReferences,
...@@ -14,6 +9,11 @@ import { ...@@ -14,6 +9,11 @@ import {
isDiscussionApplicableToLine, isDiscussionApplicableToLine,
updateLineInFile, updateLineInFile,
} from './utils'; } from './utils';
import {
DIFF_FILE_MANUAL_COLLAPSE,
DIFF_FILE_AUTOMATIC_COLLAPSE,
INLINE_DIFF_LINES_KEY,
} from '../constants';
import * as types from './mutation_types'; import * as types from './mutation_types';
function updateDiffFilesInState(state, files) { function updateDiffFilesInState(state, files) {
...@@ -109,25 +109,7 @@ export default { ...@@ -109,25 +109,7 @@ export default {
if (!diffFile) return; if (!diffFile) return;
if (diffFile.highlighted_diff_lines.length) { diffFile[INLINE_DIFF_LINES_KEY].find(l => l.line_code === lineCode).hasForm = hasForm;
diffFile.highlighted_diff_lines.find(l => l.line_code === lineCode).hasForm = hasForm;
}
if (diffFile.parallel_diff_lines.length) {
const line = diffFile.parallel_diff_lines.find(l => {
const { left, right } = l;
return (left && left.line_code === lineCode) || (right && right.line_code === lineCode);
});
if (line.left && line.left.line_code === lineCode) {
line.left.hasForm = hasForm;
}
if (line.right && line.right.line_code === lineCode) {
line.right.hasForm = hasForm;
}
}
}, },
[types.ADD_CONTEXT_LINES](state, options) { [types.ADD_CONTEXT_LINES](state, options) {
...@@ -157,11 +139,7 @@ export default { ...@@ -157,11 +139,7 @@ export default {
}); });
addContextLines({ addContextLines({
inlineLines: diffFile.highlighted_diff_lines, inlineLines: diffFile[INLINE_DIFF_LINES_KEY],
parallelLines: diffFile.parallel_diff_lines,
diffViewType: window.gon?.features?.unifiedDiffLines
? INLINE_DIFF_VIEW_TYPE
: state.diffViewType,
contextLines: lines, contextLines: lines,
bottom, bottom,
lineNumbers, lineNumbers,
...@@ -219,8 +197,8 @@ export default { ...@@ -219,8 +197,8 @@ export default {
state.diffFiles.forEach(file => { state.diffFiles.forEach(file => {
if (file.file_hash === fileHash) { if (file.file_hash === fileHash) {
if (file.highlighted_diff_lines.length) { if (file[INLINE_DIFF_LINES_KEY].length) {
file.highlighted_diff_lines.forEach(line => { file[INLINE_DIFF_LINES_KEY].forEach(line => {
Object.assign( Object.assign(
line, line,
setDiscussionsExpanded(lineCheck(line) ? mapDiscussions(line) : line), setDiscussionsExpanded(lineCheck(line) ? mapDiscussions(line) : line),
...@@ -228,25 +206,7 @@ export default { ...@@ -228,25 +206,7 @@ export default {
}); });
} }
if (file.parallel_diff_lines.length) { if (!file[INLINE_DIFF_LINES_KEY].length) {
file.parallel_diff_lines.forEach(line => {
const left = line.left && lineCheck(line.left);
const right = line.right && lineCheck(line.right);
if (left || right) {
Object.assign(line, {
left: line.left ? setDiscussionsExpanded(mapDiscussions(line.left)) : null,
right: line.right
? setDiscussionsExpanded(mapDiscussions(line.right, () => !left))
: null,
});
}
return line;
});
}
if (!file.parallel_diff_lines.length || !file.highlighted_diff_lines.length) {
const newDiscussions = (file.discussions || []) const newDiscussions = (file.discussions || [])
.filter(d => d.id !== discussion.id) .filter(d => d.id !== discussion.id)
.concat(discussion); .concat(discussion);
...@@ -369,31 +329,15 @@ export default { ...@@ -369,31 +329,15 @@ export default {
renderFile(file); renderFile(file);
} }
}, },
[types.SET_HIDDEN_VIEW_DIFF_FILE_LINES](state, { filePath, lines }) {
const file = state.diffFiles.find(f => f.file_path === filePath);
const hiddenDiffLinesKey =
state.diffViewType === 'inline' ? 'parallel_diff_lines' : 'highlighted_diff_lines';
file[hiddenDiffLinesKey] = lines;
},
[types.SET_CURRENT_VIEW_DIFF_FILE_LINES](state, { filePath, lines }) { [types.SET_CURRENT_VIEW_DIFF_FILE_LINES](state, { filePath, lines }) {
const file = state.diffFiles.find(f => f.file_path === filePath); const file = state.diffFiles.find(f => f.file_path === filePath);
let currentDiffLinesKey;
if (window.gon?.features?.unifiedDiffLines || state.diffViewType === 'inline') {
currentDiffLinesKey = 'highlighted_diff_lines';
} else {
currentDiffLinesKey = 'parallel_diff_lines';
}
file[currentDiffLinesKey] = lines; file[INLINE_DIFF_LINES_KEY] = lines;
}, },
[types.ADD_CURRENT_VIEW_DIFF_FILE_LINES](state, { filePath, line }) { [types.ADD_CURRENT_VIEW_DIFF_FILE_LINES](state, { filePath, line }) {
const file = state.diffFiles.find(f => f.file_path === filePath); const file = state.diffFiles.find(f => f.file_path === filePath);
const currentDiffLinesKey =
state.diffViewType === 'inline' ? 'highlighted_diff_lines' : 'parallel_diff_lines';
file[currentDiffLinesKey].push(line); file[INLINE_DIFF_LINES_KEY].push(line);
}, },
[types.TOGGLE_DIFF_FILE_RENDERING_MORE](state, filePath) { [types.TOGGLE_DIFF_FILE_RENDERING_MORE](state, filePath) {
const file = state.diffFiles.find(f => f.file_path === filePath); const file = state.diffFiles.find(f => f.file_path === filePath);
......
...@@ -12,8 +12,7 @@ import { ...@@ -12,8 +12,7 @@ import {
MATCH_LINE_TYPE, MATCH_LINE_TYPE,
LINES_TO_BE_RENDERED_DIRECTLY, LINES_TO_BE_RENDERED_DIRECTLY,
TREE_TYPE, TREE_TYPE,
INLINE_DIFF_VIEW_TYPE, INLINE_DIFF_LINES_KEY,
PARALLEL_DIFF_VIEW_TYPE,
SHOW_WHITESPACE, SHOW_WHITESPACE,
NO_SHOW_WHITESPACE, NO_SHOW_WHITESPACE,
} from '../constants'; } from '../constants';
...@@ -178,43 +177,16 @@ export const findIndexInInlineLines = (lines, lineNumbers) => { ...@@ -178,43 +177,16 @@ export const findIndexInInlineLines = (lines, lineNumbers) => {
); );
}; };
export const findIndexInParallelLines = (lines, lineNumbers) => {
const { oldLineNumber, newLineNumber } = lineNumbers;
return lines.findIndex(
line =>
line.left &&
line.right &&
line.left.old_line === oldLineNumber &&
line.right.new_line === newLineNumber,
);
};
const indexGettersByViewType = {
[INLINE_DIFF_VIEW_TYPE]: findIndexInInlineLines,
[PARALLEL_DIFF_VIEW_TYPE]: findIndexInParallelLines,
};
export const getPreviousLineIndex = (diffViewType, file, lineNumbers) => { export const getPreviousLineIndex = (diffViewType, file, lineNumbers) => {
const findIndex = indexGettersByViewType[diffViewType]; return findIndexInInlineLines(file[INLINE_DIFF_LINES_KEY], lineNumbers);
const lines = {
[INLINE_DIFF_VIEW_TYPE]: file.highlighted_diff_lines,
[PARALLEL_DIFF_VIEW_TYPE]: file.parallel_diff_lines,
};
return findIndex && findIndex(lines[diffViewType], lineNumbers);
}; };
export function removeMatchLine(diffFile, lineNumbers, bottom) { export function removeMatchLine(diffFile, lineNumbers, bottom) {
const indexForInline = findIndexInInlineLines(diffFile.highlighted_diff_lines, lineNumbers); const indexForInline = findIndexInInlineLines(diffFile[INLINE_DIFF_LINES_KEY], lineNumbers);
const indexForParallel = findIndexInParallelLines(diffFile.parallel_diff_lines, lineNumbers);
const factor = bottom ? 1 : -1; const factor = bottom ? 1 : -1;
if (indexForInline > -1) { if (indexForInline > -1) {
diffFile.highlighted_diff_lines.splice(indexForInline + factor, 1); diffFile[INLINE_DIFF_LINES_KEY].splice(indexForInline + factor, 1);
}
if (indexForParallel > -1) {
diffFile.parallel_diff_lines.splice(indexForParallel + factor, 1);
} }
} }
...@@ -257,24 +229,6 @@ export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, next ...@@ -257,24 +229,6 @@ export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, next
return linesWithNumbers; return linesWithNumbers;
} }
function addParallelContextLines(options) {
const { parallelLines, contextLines, lineNumbers, isExpandDown } = options;
const normalizedParallelLines = contextLines.map(line => ({
left: line,
right: line,
line_code: line.line_code,
}));
const factor = isExpandDown ? 1 : 0;
if (!isExpandDown && options.bottom) {
parallelLines.push(...normalizedParallelLines);
} else {
const parallelIndex = findIndexInParallelLines(parallelLines, lineNumbers);
parallelLines.splice(parallelIndex + factor, 0, ...normalizedParallelLines);
}
}
function addInlineContextLines(options) { function addInlineContextLines(options) {
const { inlineLines, contextLines, lineNumbers, isExpandDown } = options; const { inlineLines, contextLines, lineNumbers, isExpandDown } = options;
const factor = isExpandDown ? 1 : 0; const factor = isExpandDown ? 1 : 0;
...@@ -289,16 +243,7 @@ function addInlineContextLines(options) { ...@@ -289,16 +243,7 @@ function addInlineContextLines(options) {
} }
export function addContextLines(options) { export function addContextLines(options) {
const { diffViewType } = options; addInlineContextLines(options);
const contextLineHandlers = {
[INLINE_DIFF_VIEW_TYPE]: addInlineContextLines,
[PARALLEL_DIFF_VIEW_TYPE]: addParallelContextLines,
};
const contextLineHandler = contextLineHandlers[diffViewType];
if (contextLineHandler) {
contextLineHandler(options);
}
} }
/** /**
...@@ -324,41 +269,29 @@ export function trimFirstCharOfLineContent(line = {}) { ...@@ -324,41 +269,29 @@ export function trimFirstCharOfLineContent(line = {}) {
return parsedLine; return parsedLine;
} }
function getLineCode({ left, right }, index) {
if (left && left.line_code) {
return left.line_code;
} else if (right && right.line_code) {
return right.line_code;
}
return index;
}
function diffFileUniqueId(file) { function diffFileUniqueId(file) {
return `${file.content_sha}-${file.file_hash}`; return `${file.content_sha}-${file.file_hash}`;
} }
function mergeTwoFiles(target, source) { function mergeTwoFiles(target, source) {
const originalInline = target.highlighted_diff_lines; const originalInline = target[INLINE_DIFF_LINES_KEY];
const originalParallel = target.parallel_diff_lines;
const missingInline = !originalInline.length; const missingInline = !originalInline.length;
const missingParallel = !originalParallel.length;
return { return {
...target, ...target,
highlighted_diff_lines: missingInline ? source.highlighted_diff_lines : originalInline, [INLINE_DIFF_LINES_KEY]: missingInline ? source[INLINE_DIFF_LINES_KEY] : originalInline,
parallel_diff_lines: missingParallel ? source.parallel_diff_lines : originalParallel, parallel_diff_lines: null,
renderIt: source.renderIt, renderIt: source.renderIt,
collapsed: source.collapsed, collapsed: source.collapsed,
}; };
} }
function ensureBasicDiffFileLines(file) { function ensureBasicDiffFileLines(file) {
const missingInline = !file.highlighted_diff_lines; const missingInline = !file[INLINE_DIFF_LINES_KEY];
const missingParallel = !file.parallel_diff_lines || window.gon?.features?.unifiedDiffLines;
Object.assign(file, { Object.assign(file, {
highlighted_diff_lines: missingInline ? [] : file.highlighted_diff_lines, [INLINE_DIFF_LINES_KEY]: missingInline ? [] : file[INLINE_DIFF_LINES_KEY],
parallel_diff_lines: missingParallel ? [] : file.parallel_diff_lines, parallel_diff_lines: null,
}); });
return file; return file;
...@@ -382,7 +315,7 @@ function prepareLine(line, file) { ...@@ -382,7 +315,7 @@ function prepareLine(line, file) {
} }
} }
export function prepareLineForRenamedFile({ line, diffViewType, diffFile, index = 0 }) { export function prepareLineForRenamedFile({ line, diffFile, index = 0 }) {
/* /*
Renamed files are a little different than other diffs, which Renamed files are a little different than other diffs, which
is why this is distinct from `prepareDiffFileLines` below. is why this is distinct from `prepareDiffFileLines` below.
...@@ -407,48 +340,23 @@ export function prepareLineForRenamedFile({ line, diffViewType, diffFile, index ...@@ -407,48 +340,23 @@ export function prepareLineForRenamedFile({ line, diffViewType, diffFile, index
prepareLine(cleanLine, diffFile); // WARNING: In-Place Mutations! prepareLine(cleanLine, diffFile); // WARNING: In-Place Mutations!
if (diffViewType === PARALLEL_DIFF_VIEW_TYPE) {
return {
left: { ...cleanLine },
right: { ...cleanLine },
line_code: cleanLine.line_code,
};
}
return cleanLine; return cleanLine;
} }
function prepareDiffFileLines(file) { function prepareDiffFileLines(file) {
const inlineLines = file.highlighted_diff_lines; const inlineLines = file[INLINE_DIFF_LINES_KEY];
const parallelLines = file.parallel_diff_lines;
let parallelLinesCount = 0;
inlineLines.forEach(line => prepareLine(line, file)); // WARNING: In-Place Mutations! inlineLines.forEach(line => prepareLine(line, file)); // WARNING: In-Place Mutations!
parallelLines.forEach((line, index) => {
Object.assign(line, { line_code: getLineCode(line, index) });
if (line.left) {
parallelLinesCount += 1;
prepareLine(line.left, file); // WARNING: In-Place Mutations!
}
if (line.right) {
parallelLinesCount += 1;
prepareLine(line.right, file); // WARNING: In-Place Mutations!
}
});
Object.assign(file, { Object.assign(file, {
inlineLinesCount: inlineLines.length, inlineLinesCount: inlineLines.length,
parallelLinesCount,
}); });
return file; return file;
} }
function getVisibleDiffLines(file) { function getVisibleDiffLines(file) {
return Math.max(file.inlineLinesCount, file.parallelLinesCount); return file.inlineLinesCount;
} }
function finalizeDiffFile(file) { function finalizeDiffFile(file) {
...@@ -490,43 +398,14 @@ export function prepareDiffData(diff, priorFiles = []) { ...@@ -490,43 +398,14 @@ export function prepareDiffData(diff, priorFiles = []) {
export function getDiffPositionByLineCode(diffFiles) { export function getDiffPositionByLineCode(diffFiles) {
let lines = []; let lines = [];
const hasInlineDiffs = diffFiles.some(file => file.highlighted_diff_lines.length > 0);
if (hasInlineDiffs) {
// In either of these cases, we can use `highlighted_diff_lines` because
// that will include all of the parallel diff lines, too
lines = diffFiles.reduce((acc, diffFile) => { lines = diffFiles.reduce((acc, diffFile) => {
diffFile.highlighted_diff_lines.forEach(line => { diffFile[INLINE_DIFF_LINES_KEY].forEach(line => {
acc.push({ file: diffFile, line }); acc.push({ file: diffFile, line });
}); });
return acc; return acc;
}, []); }, []);
} else {
// If we're in single diff view mode and the inline lines haven't been
// loaded yet, we need to parse the parallel lines
lines = diffFiles.reduce((acc, diffFile) => {
diffFile.parallel_diff_lines.forEach(pair => {
// It's possible for a parallel line to have an opposite line that doesn't exist
// For example: *deleted* lines will have `null` right lines, while
// *added* lines will have `null` left lines.
// So we have to check each line before we push it onto the array so we're not
// pushing null line diffs
if (pair.left) {
acc.push({ file: diffFile, line: pair.left });
}
if (pair.right) {
acc.push({ file: diffFile, line: pair.right });
}
});
return acc;
}, []);
}
return lines.reduce((acc, { file, line }) => { return lines.reduce((acc, { file, line }) => {
if (line.line_code) { if (line.line_code) {
...@@ -739,24 +618,10 @@ export const convertExpandLines = ({ ...@@ -739,24 +618,10 @@ export const convertExpandLines = ({
export const idleCallback = cb => requestIdleCallback(cb); export const idleCallback = cb => requestIdleCallback(cb);
function getLinesFromFileByLineCode(file, lineCode) { function getLinesFromFileByLineCode(file, lineCode) {
const parallelLines = file.parallel_diff_lines; const inlineLines = file[INLINE_DIFF_LINES_KEY];
const inlineLines = file.highlighted_diff_lines;
const matchesCode = line => line.line_code === lineCode; const matchesCode = line => line.line_code === lineCode;
return [ return inlineLines.filter(matchesCode);
...parallelLines.reduce((acc, line) => {
if (line.left) {
acc.push(line.left);
}
if (line.right) {
acc.push(line.right);
}
return acc;
}, []),
...inlineLines,
].filter(matchesCode);
} }
export const updateLineInFile = (selectedFile, lineCode, updateFn) => { export const updateLineInFile = (selectedFile, lineCode, updateFn) => {
...@@ -771,12 +636,7 @@ export const allDiscussionWrappersExpanded = diff => { ...@@ -771,12 +636,7 @@ export const allDiscussionWrappersExpanded = diff => {
} }
}; };
diff.parallel_diff_lines.forEach(line => { diff[INLINE_DIFF_LINES_KEY].forEach(line => {
changeExpandedResult(line.left);
changeExpandedResult(line.right);
});
diff.highlighted_diff_lines.forEach(line => {
changeExpandedResult(line); changeExpandedResult(line);
}); });
......
...@@ -23,6 +23,7 @@ import { ...@@ -23,6 +23,7 @@ import {
commentLineOptions, commentLineOptions,
formatLineRange, formatLineRange,
} from './multiline_comment_utils'; } from './multiline_comment_utils';
import { INLINE_DIFF_LINES_KEY } from '~/diffs/constants';
export default { export default {
name: 'NoteableNote', name: 'NoteableNote',
...@@ -169,12 +170,8 @@ export default { ...@@ -169,12 +170,8 @@ export default {
return this.line && this.startLineNumber !== this.endLineNumber; return this.line && this.startLineNumber !== this.endLineNumber;
}, },
commentLineOptions() { commentLineOptions() {
const sideA = this.line.type === 'new' ? 'right' : 'left'; const lines = this.diffFile[INLINE_DIFF_LINES_KEY].length;
const sideB = sideA === 'left' ? 'right' : 'left'; return commentLineOptions(lines, this.commentLineStart, this.line.line_code);
const lines = this.diffFile.highlighted_diff_lines.length
? this.diffFile.highlighted_diff_lines
: this.diffFile.parallel_diff_lines.map(l => l[sideA] || l[sideB]);
return commentLineOptions(lines, this.commentLineStart, this.line.line_code, sideA);
}, },
diffFile() { diffFile() {
if (this.commentLineStart.line_code) { if (this.commentLineStart.line_code) {
......
...@@ -69,7 +69,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic ...@@ -69,7 +69,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
} }
options = additional_attributes.merge( options = additional_attributes.merge(
diff_view: unified_diff_lines_view_type(@merge_request.project), diff_view: "inline",
merge_ref_head_diff: render_merge_ref_head_diff? merge_ref_head_diff: render_merge_ref_head_diff?
) )
......
...@@ -36,7 +36,6 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo ...@@ -36,7 +36,6 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
push_frontend_feature_flag(:approvals_commented_by, @project, default_enabled: true) push_frontend_feature_flag(:approvals_commented_by, @project, default_enabled: true)
push_frontend_feature_flag(:hide_jump_to_next_unresolved_in_threads, default_enabled: true) push_frontend_feature_flag(:hide_jump_to_next_unresolved_in_threads, default_enabled: true)
push_frontend_feature_flag(:merge_request_widget_graphql, @project) push_frontend_feature_flag(:merge_request_widget_graphql, @project)
push_frontend_feature_flag(:unified_diff_lines, @project, default_enabled: true)
push_frontend_feature_flag(:unified_diff_components, @project) push_frontend_feature_flag(:unified_diff_components, @project)
push_frontend_feature_flag(:highlight_current_diff_row, @project) push_frontend_feature_flag(:highlight_current_diff_row, @project)
push_frontend_feature_flag(:default_merge_ref_for_diffs, @project) push_frontend_feature_flag(:default_merge_ref_for_diffs, @project)
...@@ -481,7 +480,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo ...@@ -481,7 +480,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
def endpoint_metadata_url(project, merge_request) def endpoint_metadata_url(project, merge_request)
params = request.query_parameters params = request.query_parameters
params[:view] = unified_diff_lines_view_type(project) params[:view] = "inline"
if Feature.enabled?(:default_merge_ref_for_diffs, project) if Feature.enabled?(:default_merge_ref_for_diffs, project)
params = params.merge(diff_head: true) params = params.merge(diff_head: true)
......
...@@ -203,14 +203,6 @@ module DiffHelper ...@@ -203,14 +203,6 @@ module DiffHelper
set_secure_cookie(:diff_view, params.delete(:view), type: CookiesHelper::COOKIE_TYPE_PERMANENT) if params[:view].present? set_secure_cookie(:diff_view, params.delete(:view), type: CookiesHelper::COOKIE_TYPE_PERMANENT) if params[:view].present?
end end
def unified_diff_lines_view_type(project)
if Feature.enabled?(:unified_diff_lines, project, default_enabled: true)
'inline'
else
diff_view
end
end
private private
def diff_btn(title, name, selected) def diff_btn(title, name, selected)
......
---
name: unified_diff_lines
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40131
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/241188
milestone: '13.4'
type: development
group: group::source code
default_enabled: true
...@@ -12,7 +12,6 @@ import HiddenFilesWarning from '~/diffs/components/hidden_files_warning.vue'; ...@@ -12,7 +12,6 @@ import HiddenFilesWarning from '~/diffs/components/hidden_files_warning.vue';
import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue'; import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue';
import CommitWidget from '~/diffs/components/commit_widget.vue'; import CommitWidget from '~/diffs/components/commit_widget.vue';
import TreeList from '~/diffs/components/tree_list.vue'; import TreeList from '~/diffs/components/tree_list.vue';
import { INLINE_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '~/diffs/constants';
import createDiffsStore from '../create_diffs_store'; import createDiffsStore from '../create_diffs_store';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
...@@ -75,12 +74,6 @@ describe('diffs/components/app', () => { ...@@ -75,12 +74,6 @@ describe('diffs/components/app', () => {
}); });
} }
function getOppositeViewType(currentViewType) {
return currentViewType === INLINE_DIFF_VIEW_TYPE
? PARALLEL_DIFF_VIEW_TYPE
: INLINE_DIFF_VIEW_TYPE;
}
beforeEach(() => { beforeEach(() => {
// setup globals (needed for component to mount :/) // setup globals (needed for component to mount :/)
window.mrTabs = { window.mrTabs = {
...@@ -125,104 +118,6 @@ describe('diffs/components/app', () => { ...@@ -125,104 +118,6 @@ describe('diffs/components/app', () => {
wrapper.vm.$nextTick(done); wrapper.vm.$nextTick(done);
}); });
describe('when the diff view type changes and it should load a single diff view style', () => {
const noLinesDiff = {
highlighted_diff_lines: [],
parallel_diff_lines: [],
};
const parallelLinesDiff = {
highlighted_diff_lines: [],
parallel_diff_lines: ['line'],
};
const inlineLinesDiff = {
highlighted_diff_lines: ['line'],
parallel_diff_lines: [],
};
const fullDiff = {
highlighted_diff_lines: ['line'],
parallel_diff_lines: ['line'],
};
function expectFetchToOccur({ vueInstance, done = () => {}, existingFiles = 1 } = {}) {
vueInstance.$nextTick(() => {
expect(vueInstance.diffFiles.length).toEqual(existingFiles);
expect(vueInstance.fetchDiffFilesBatch).toHaveBeenCalled();
done();
});
}
it('fetches diffs if it has none', done => {
wrapper.vm.isLatestVersion = () => false;
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, existingFiles: 0, done });
});
it('fetches diffs if it has both view styles, but no lines in either', done => {
wrapper.vm.isLatestVersion = () => false;
store.state.diffs.diffFiles.push(noLinesDiff);
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, done });
});
it('fetches diffs if it only has inline view style', done => {
wrapper.vm.isLatestVersion = () => false;
store.state.diffs.diffFiles.push(inlineLinesDiff);
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, done });
});
it('fetches diffs if it only has parallel view style', done => {
wrapper.vm.isLatestVersion = () => false;
store.state.diffs.diffFiles.push(parallelLinesDiff);
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, done });
});
it('fetches batch diffs if it has none', done => {
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, existingFiles: 0, done });
});
it('fetches batch diffs if it has both view styles, but no lines in either', done => {
store.state.diffs.diffFiles.push(noLinesDiff);
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, done });
});
it('fetches batch diffs if it only has inline view style', done => {
store.state.diffs.diffFiles.push(inlineLinesDiff);
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, done });
});
it('fetches batch diffs if it only has parallel view style', done => {
store.state.diffs.diffFiles.push(parallelLinesDiff);
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expectFetchToOccur({ vueInstance: wrapper.vm, done });
});
it('does not fetch batch diffs if it has already fetched both styles of diff', () => {
store.state.diffs.diffFiles.push(fullDiff);
store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
expect(wrapper.vm.diffFiles.length).toEqual(1);
expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled();
});
});
it('calls batch methods if diffsBatchLoad is enabled, and not latest version', done => { it('calls batch methods if diffsBatchLoad is enabled, and not latest version', done => {
expect(wrapper.vm.diffFilesLength).toEqual(0); expect(wrapper.vm.diffFilesLength).toEqual(0);
wrapper.vm.isLatestVersion = () => false; wrapper.vm.isLatestVersion = () => false;
......
...@@ -12,7 +12,6 @@ import DiffDiscussions from '~/diffs/components/diff_discussions.vue'; ...@@ -12,7 +12,6 @@ import DiffDiscussions from '~/diffs/components/diff_discussions.vue';
import { IMAGE_DIFF_POSITION_TYPE } from '~/diffs/constants'; import { IMAGE_DIFF_POSITION_TYPE } from '~/diffs/constants';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
import { diffViewerModes } from '~/ide/constants'; import { diffViewerModes } from '~/ide/constants';
import { diffLines } from '~/diffs/store/getters';
import DiffView from '~/diffs/components/diff_view.vue'; import DiffView from '~/diffs/components/diff_view.vue';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -74,7 +73,7 @@ describe('DiffContent', () => { ...@@ -74,7 +73,7 @@ describe('DiffContent', () => {
isInlineView: isInlineViewGetterMock, isInlineView: isInlineViewGetterMock,
isParallelView: isParallelViewGetterMock, isParallelView: isParallelViewGetterMock,
getCommentFormForDiffFile: getCommentFormForDiffFileGetterMock, getCommentFormForDiffFile: getCommentFormForDiffFileGetterMock,
diffLines, diffLines: () => () => [...diffFileMockData.parallel_diff_lines],
}, },
actions: { actions: {
saveDiffDiscussion: saveDiffDiscussionMock, saveDiffDiscussion: saveDiffDiscussionMock,
...@@ -122,11 +121,11 @@ describe('DiffContent', () => { ...@@ -122,11 +121,11 @@ describe('DiffContent', () => {
expect(wrapper.find(ParallelDiffView).exists()).toBe(true); expect(wrapper.find(ParallelDiffView).exists()).toBe(true);
}); });
it('should render diff view if `unifiedDiffLines` & `unifiedDiffComponents` are true', () => { it('should render diff view if `unifiedDiffComponents` are true', () => {
isParallelViewGetterMock.mockReturnValue(true); isParallelViewGetterMock.mockReturnValue(true);
createComponent({ createComponent({
props: { diffFile: textDiffFile }, props: { diffFile: textDiffFile },
provide: { glFeatures: { unifiedDiffLines: true, unifiedDiffComponents: true } }, provide: { glFeatures: { unifiedDiffComponents: true } },
}); });
expect(wrapper.find(DiffView).exists()).toBe(true); expect(wrapper.find(DiffView).exists()).toBe(true);
......
...@@ -5,18 +5,16 @@ import { getByText } from '@testing-library/dom'; ...@@ -5,18 +5,16 @@ import { getByText } from '@testing-library/dom';
import { createStore } from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import DiffExpansionCell from '~/diffs/components/diff_expansion_cell.vue'; import DiffExpansionCell from '~/diffs/components/diff_expansion_cell.vue';
import { getPreviousLineIndex } from '~/diffs/store/utils'; import { getPreviousLineIndex } from '~/diffs/store/utils';
import { INLINE_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '~/diffs/constants'; import { INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
const EXPAND_UP_CLASS = '.js-unfold'; const EXPAND_UP_CLASS = '.js-unfold';
const EXPAND_DOWN_CLASS = '.js-unfold-down'; const EXPAND_DOWN_CLASS = '.js-unfold-down';
const lineSources = { const lineSources = {
[INLINE_DIFF_VIEW_TYPE]: 'highlighted_diff_lines', [INLINE_DIFF_VIEW_TYPE]: 'highlighted_diff_lines',
[PARALLEL_DIFF_VIEW_TYPE]: 'parallel_diff_lines',
}; };
const lineHandlers = { const lineHandlers = {
[INLINE_DIFF_VIEW_TYPE]: line => line, [INLINE_DIFF_VIEW_TYPE]: line => line,
[PARALLEL_DIFF_VIEW_TYPE]: line => line.right || line.left,
}; };
function makeLoadMoreLinesPayload({ function makeLoadMoreLinesPayload({
...@@ -126,7 +124,6 @@ describe('DiffExpansionCell', () => { ...@@ -126,7 +124,6 @@ describe('DiffExpansionCell', () => {
describe('any row', () => { describe('any row', () => {
[ [
{ diffViewType: INLINE_DIFF_VIEW_TYPE, lineIndex: 8, file: { parallel_diff_lines: [] } }, { diffViewType: INLINE_DIFF_VIEW_TYPE, lineIndex: 8, file: { parallel_diff_lines: [] } },
{ diffViewType: PARALLEL_DIFF_VIEW_TYPE, lineIndex: 7, file: { highlighted_diff_lines: [] } },
].forEach(({ diffViewType, file, lineIndex }) => { ].forEach(({ diffViewType, file, lineIndex }) => {
describe(`with diffViewType (${diffViewType})`, () => { describe(`with diffViewType (${diffViewType})`, () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -1235,10 +1235,6 @@ describe('DiffsStoreActions', () => { ...@@ -1235,10 +1235,6 @@ describe('DiffsStoreActions', () => {
{ file: { file_path: 'path' }, data: [] }, { file: { file_path: 'path' }, data: [] },
{ diffViewType: 'inline' }, { diffViewType: 'inline' },
[ [
{
type: 'SET_HIDDEN_VIEW_DIFF_FILE_LINES',
payload: { filePath: 'path', lines: ['test'] },
},
{ {
type: 'SET_CURRENT_VIEW_DIFF_FILE_LINES', type: 'SET_CURRENT_VIEW_DIFF_FILE_LINES',
payload: { filePath: 'path', lines: ['test'] }, payload: { filePath: 'path', lines: ['test'] },
...@@ -1258,10 +1254,6 @@ describe('DiffsStoreActions', () => { ...@@ -1258,10 +1254,6 @@ describe('DiffsStoreActions', () => {
{ file: { file_path: 'path' }, data: [] }, { file: { file_path: 'path' }, data: [] },
{ diffViewType: 'inline' }, { diffViewType: 'inline' },
[ [
{
type: 'SET_HIDDEN_VIEW_DIFF_FILE_LINES',
payload: { filePath: 'path', lines },
},
{ {
type: 'SET_CURRENT_VIEW_DIFF_FILE_LINES', type: 'SET_CURRENT_VIEW_DIFF_FILE_LINES',
payload: { filePath: 'path', lines: lines.slice(0, 200) }, payload: { filePath: 'path', lines: lines.slice(0, 200) },
......
import createState from '~/diffs/store/modules/diff_state'; import createState from '~/diffs/store/modules/diff_state';
import mutations from '~/diffs/store/mutations'; import mutations from '~/diffs/store/mutations';
import * as types from '~/diffs/store/mutation_types'; import * as types from '~/diffs/store/mutation_types';
import { INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants'; import { INLINE_DIFF_VIEW_TYPE, INLINE_DIFF_LINES_KEY } from '~/diffs/constants';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
import * as utils from '~/diffs/store/utils'; import * as utils from '~/diffs/store/utils';
...@@ -74,7 +74,7 @@ describe('DiffsStoreMutations', () => { ...@@ -74,7 +74,7 @@ describe('DiffsStoreMutations', () => {
{ {
content_sha: diffFileMockData.content_sha, content_sha: diffFileMockData.content_sha,
file_hash: diffFileMockData.file_hash, file_hash: diffFileMockData.file_hash,
highlighted_diff_lines: [], [INLINE_DIFF_LINES_KEY]: [],
}, },
], ],
}; };
...@@ -84,11 +84,11 @@ describe('DiffsStoreMutations', () => { ...@@ -84,11 +84,11 @@ describe('DiffsStoreMutations', () => {
mutations[types.SET_DIFF_DATA](state, diffMock); mutations[types.SET_DIFF_DATA](state, diffMock);
expect(state.diffFiles[0].parallel_diff_lines).toBeUndefined(); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY]).toEqual([]);
}); });
}); });
describe('SET_DIFFSET_DIFF_DATA_BATCH_DATA', () => { describe('SET_DIFF_DATA_BATCH_DATA', () => {
it('should set diff data batch type properly', () => { it('should set diff data batch type properly', () => {
const state = { diffFiles: [] }; const state = { diffFiles: [] };
const diffMock = { const diffMock = {
...@@ -97,9 +97,6 @@ describe('DiffsStoreMutations', () => { ...@@ -97,9 +97,6 @@ describe('DiffsStoreMutations', () => {
mutations[types.SET_DIFF_DATA_BATCH](state, diffMock); mutations[types.SET_DIFF_DATA_BATCH](state, diffMock);
const firstLine = state.diffFiles[0].parallel_diff_lines[0];
expect(firstLine.right.text).toBeUndefined();
expect(state.diffFiles[0].renderIt).toEqual(true); expect(state.diffFiles[0].renderIt).toEqual(true);
expect(state.diffFiles[0].collapsed).toEqual(false); expect(state.diffFiles[0].collapsed).toEqual(false);
}); });
...@@ -142,8 +139,7 @@ describe('DiffsStoreMutations', () => { ...@@ -142,8 +139,7 @@ describe('DiffsStoreMutations', () => {
}; };
const diffFile = { const diffFile = {
file_hash: options.fileHash, file_hash: options.fileHash,
highlighted_diff_lines: [], [INLINE_DIFF_LINES_KEY]: [],
parallel_diff_lines: [],
}; };
const state = { diffFiles: [diffFile], diffViewType: 'viewType' }; const state = { diffFiles: [diffFile], diffViewType: 'viewType' };
const lines = [{ old_line: 1, new_line: 1 }]; const lines = [{ old_line: 1, new_line: 1 }];
...@@ -171,9 +167,7 @@ describe('DiffsStoreMutations', () => { ...@@ -171,9 +167,7 @@ describe('DiffsStoreMutations', () => {
); );
expect(utils.addContextLines).toHaveBeenCalledWith({ expect(utils.addContextLines).toHaveBeenCalledWith({
inlineLines: diffFile.highlighted_diff_lines, inlineLines: diffFile[INLINE_DIFF_LINES_KEY],
parallelLines: diffFile.parallel_diff_lines,
diffViewType: 'viewType',
contextLines: options.contextLines, contextLines: options.contextLines,
bottom: options.params.bottom, bottom: options.params.bottom,
lineNumbers: options.lineNumbers, lineNumbers: options.lineNumbers,
...@@ -225,19 +219,7 @@ describe('DiffsStoreMutations', () => { ...@@ -225,19 +219,7 @@ describe('DiffsStoreMutations', () => {
diffFiles: [ diffFiles: [
{ {
file_hash: 'ABC', file_hash: 'ABC',
parallel_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{
left: {
line_code: 'ABC_1',
discussions: [],
},
right: {
line_code: 'ABC_2',
discussions: [],
},
},
],
highlighted_diff_lines: [
{ {
line_code: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
...@@ -267,12 +249,8 @@ describe('DiffsStoreMutations', () => { ...@@ -267,12 +249,8 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions.length).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].id).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].right.discussions).toEqual([]);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1);
}); });
it('should not duplicate discussions on line', () => { it('should not duplicate discussions on line', () => {
...@@ -291,19 +269,7 @@ describe('DiffsStoreMutations', () => { ...@@ -291,19 +269,7 @@ describe('DiffsStoreMutations', () => {
diffFiles: [ diffFiles: [
{ {
file_hash: 'ABC', file_hash: 'ABC',
parallel_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{
left: {
line_code: 'ABC_1',
discussions: [],
},
right: {
line_code: 'ABC_2',
discussions: [],
},
},
],
highlighted_diff_lines: [
{ {
line_code: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
...@@ -333,24 +299,16 @@ describe('DiffsStoreMutations', () => { ...@@ -333,24 +299,16 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions.length).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].id).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].right.discussions).toEqual([]);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1);
mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, {
discussion, discussion,
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions.length).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].id).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].right.discussions).toEqual([]);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1);
}); });
it('updates existing discussion', () => { it('updates existing discussion', () => {
...@@ -369,19 +327,7 @@ describe('DiffsStoreMutations', () => { ...@@ -369,19 +327,7 @@ describe('DiffsStoreMutations', () => {
diffFiles: [ diffFiles: [
{ {
file_hash: 'ABC', file_hash: 'ABC',
parallel_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{
left: {
line_code: 'ABC_1',
discussions: [],
},
right: {
line_code: 'ABC_2',
discussions: [],
},
},
],
highlighted_diff_lines: [
{ {
line_code: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
...@@ -411,12 +357,8 @@ describe('DiffsStoreMutations', () => { ...@@ -411,12 +357,8 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions.length).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].id).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].right.discussions).toEqual([]);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1);
mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, {
discussion: { discussion: {
...@@ -427,11 +369,8 @@ describe('DiffsStoreMutations', () => { ...@@ -427,11 +369,8 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].notes.length).toBe(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].notes.length).toBe(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].notes.length).toBe(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].resolved).toBe(true);
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].resolved).toBe(true);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].resolved).toBe(true);
}); });
it('should not duplicate inline diff discussions', () => { it('should not duplicate inline diff discussions', () => {
...@@ -450,7 +389,7 @@ describe('DiffsStoreMutations', () => { ...@@ -450,7 +389,7 @@ describe('DiffsStoreMutations', () => {
diffFiles: [ diffFiles: [
{ {
file_hash: 'ABC', file_hash: 'ABC',
highlighted_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{ {
line_code: 'ABC_1', line_code: 'ABC_1',
discussions: [ discussions: [
...@@ -472,7 +411,6 @@ describe('DiffsStoreMutations', () => { ...@@ -472,7 +411,6 @@ describe('DiffsStoreMutations', () => {
discussions: [], discussions: [],
}, },
], ],
parallel_diff_lines: [],
}, },
], ],
}; };
...@@ -497,7 +435,7 @@ describe('DiffsStoreMutations', () => { ...@@ -497,7 +435,7 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toBe(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions.length).toBe(1);
}); });
it('should add legacy discussions to the given line', () => { it('should add legacy discussions to the given line', () => {
...@@ -517,19 +455,7 @@ describe('DiffsStoreMutations', () => { ...@@ -517,19 +455,7 @@ describe('DiffsStoreMutations', () => {
diffFiles: [ diffFiles: [
{ {
file_hash: 'ABC', file_hash: 'ABC',
parallel_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{
left: {
line_code: 'ABC_1',
discussions: [],
},
right: {
line_code: 'ABC_1',
discussions: [],
},
},
],
highlighted_diff_lines: [
{ {
line_code: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
...@@ -557,11 +483,8 @@ describe('DiffsStoreMutations', () => { ...@@ -557,11 +483,8 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions.length).toEqual(1);
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toEqual(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].id).toEqual(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1);
}); });
it('should add discussions by line_codes and positions attributes', () => { it('should add discussions by line_codes and positions attributes', () => {
...@@ -580,19 +503,7 @@ describe('DiffsStoreMutations', () => { ...@@ -580,19 +503,7 @@ describe('DiffsStoreMutations', () => {
diffFiles: [ diffFiles: [
{ {
file_hash: 'ABC', file_hash: 'ABC',
parallel_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{
left: {
line_code: 'ABC_1',
discussions: [],
},
right: {
line_code: 'ABC_1',
discussions: [],
},
},
],
highlighted_diff_lines: [
{ {
line_code: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
...@@ -624,11 +535,8 @@ describe('DiffsStoreMutations', () => { ...@@ -624,11 +535,8 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions).toHaveLength(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions).toHaveLength(1);
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toBe(1); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].id).toBe(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions).toHaveLength(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toBe(1);
}); });
it('should add discussion to file', () => { it('should add discussion to file', () => {
...@@ -638,8 +546,7 @@ describe('DiffsStoreMutations', () => { ...@@ -638,8 +546,7 @@ describe('DiffsStoreMutations', () => {
{ {
file_hash: 'ABC', file_hash: 'ABC',
discussions: [], discussions: [],
parallel_diff_lines: [], [INLINE_DIFF_LINES_KEY]: [],
highlighted_diff_lines: [],
}, },
], ],
}; };
...@@ -668,30 +575,7 @@ describe('DiffsStoreMutations', () => { ...@@ -668,30 +575,7 @@ describe('DiffsStoreMutations', () => {
diffFiles: [ diffFiles: [
{ {
file_hash: 'ABC', file_hash: 'ABC',
parallel_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{
left: {
line_code: 'ABC_1',
discussions: [
{
id: 1,
line_code: 'ABC_1',
notes: [],
},
{
id: 2,
line_code: 'ABC_1',
notes: [],
},
],
},
right: {
line_code: 'ABC_1',
discussions: [],
},
},
],
highlighted_diff_lines: [
{ {
line_code: 'ABC_1', line_code: 'ABC_1',
discussions: [ discussions: [
...@@ -717,8 +601,7 @@ describe('DiffsStoreMutations', () => { ...@@ -717,8 +601,7 @@ describe('DiffsStoreMutations', () => {
lineCode: 'ABC_1', lineCode: 'ABC_1',
}); });
expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(0); expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions.length).toEqual(0);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(0);
}); });
}); });
...@@ -776,11 +659,7 @@ describe('DiffsStoreMutations', () => { ...@@ -776,11 +659,7 @@ describe('DiffsStoreMutations', () => {
it('sets hasForm on lines', () => { it('sets hasForm on lines', () => {
const file = { const file = {
file_hash: 'hash', file_hash: 'hash',
parallel_diff_lines: [ [INLINE_DIFF_LINES_KEY]: [
{ left: { line_code: '123', hasForm: false }, right: {} },
{ left: {}, right: { line_code: '124', hasForm: false } },
],
highlighted_diff_lines: [
{ line_code: '123', hasForm: false }, { line_code: '123', hasForm: false },
{ line_code: '124', hasForm: false }, { line_code: '124', hasForm: false },
], ],
...@@ -795,11 +674,8 @@ describe('DiffsStoreMutations', () => { ...@@ -795,11 +674,8 @@ describe('DiffsStoreMutations', () => {
fileHash: 'hash', fileHash: 'hash',
}); });
expect(file.highlighted_diff_lines[0].hasForm).toBe(true); expect(file[INLINE_DIFF_LINES_KEY][0].hasForm).toBe(true);
expect(file.highlighted_diff_lines[1].hasForm).toBe(false); expect(file[INLINE_DIFF_LINES_KEY][1].hasForm).toBe(false);
expect(file.parallel_diff_lines[0].left.hasForm).toBe(true);
expect(file.parallel_diff_lines[1].right.hasForm).toBe(false);
}); });
}); });
...@@ -885,8 +761,7 @@ describe('DiffsStoreMutations', () => { ...@@ -885,8 +761,7 @@ describe('DiffsStoreMutations', () => {
file_path: 'test', file_path: 'test',
isLoadingFullFile: true, isLoadingFullFile: true,
isShowingFullFile: false, isShowingFullFile: false,
highlighted_diff_lines: [], [INLINE_DIFF_LINES_KEY]: [],
parallel_diff_lines: [],
}, },
], ],
}; };
...@@ -903,8 +778,7 @@ describe('DiffsStoreMutations', () => { ...@@ -903,8 +778,7 @@ describe('DiffsStoreMutations', () => {
file_path: 'test', file_path: 'test',
isLoadingFullFile: true, isLoadingFullFile: true,
isShowingFullFile: false, isShowingFullFile: false,
highlighted_diff_lines: [], [INLINE_DIFF_LINES_KEY]: [],
parallel_diff_lines: [],
}, },
], ],
}; };
...@@ -927,39 +801,11 @@ describe('DiffsStoreMutations', () => { ...@@ -927,39 +801,11 @@ describe('DiffsStoreMutations', () => {
}); });
}); });
describe('SET_HIDDEN_VIEW_DIFF_FILE_LINES', () => {
[
{ current: 'highlighted', hidden: 'parallel', diffViewType: 'inline' },
{ current: 'parallel', hidden: 'highlighted', diffViewType: 'parallel' },
].forEach(({ current, hidden, diffViewType }) => {
it(`sets the ${hidden} lines when diff view is ${diffViewType}`, () => {
const file = { file_path: 'test', parallel_diff_lines: [], highlighted_diff_lines: [] };
const state = {
diffFiles: [file],
diffViewType,
};
mutations[types.SET_HIDDEN_VIEW_DIFF_FILE_LINES](state, {
filePath: 'test',
lines: ['test'],
});
expect(file[`${current}_diff_lines`]).toEqual([]);
expect(file[`${hidden}_diff_lines`]).toEqual(['test']);
});
});
});
describe('SET_CURRENT_VIEW_DIFF_FILE_LINES', () => { describe('SET_CURRENT_VIEW_DIFF_FILE_LINES', () => {
[ it(`sets the highlighted lines`, () => {
{ current: 'highlighted', hidden: 'parallel', diffViewType: 'inline' }, const file = { file_path: 'test', [INLINE_DIFF_LINES_KEY]: [] };
{ current: 'parallel', hidden: 'highlighted', diffViewType: 'parallel' },
].forEach(({ current, hidden, diffViewType }) => {
it(`sets the ${current} lines when diff view is ${diffViewType}`, () => {
const file = { file_path: 'test', parallel_diff_lines: [], highlighted_diff_lines: [] };
const state = { const state = {
diffFiles: [file], diffFiles: [file],
diffViewType,
}; };
mutations[types.SET_CURRENT_VIEW_DIFF_FILE_LINES](state, { mutations[types.SET_CURRENT_VIEW_DIFF_FILE_LINES](state, {
...@@ -967,22 +813,15 @@ describe('DiffsStoreMutations', () => { ...@@ -967,22 +813,15 @@ describe('DiffsStoreMutations', () => {
lines: ['test'], lines: ['test'],
}); });
expect(file[`${current}_diff_lines`]).toEqual(['test']); expect(file[INLINE_DIFF_LINES_KEY]).toEqual(['test']);
expect(file[`${hidden}_diff_lines`]).toEqual([]);
});
}); });
}); });
describe('ADD_CURRENT_VIEW_DIFF_FILE_LINES', () => { describe('ADD_CURRENT_VIEW_DIFF_FILE_LINES', () => {
[ it('pushes to inline lines', () => {
{ current: 'highlighted', hidden: 'parallel', diffViewType: 'inline' }, const file = { file_path: 'test', [INLINE_DIFF_LINES_KEY]: [] };
{ current: 'parallel', hidden: 'highlighted', diffViewType: 'parallel' },
].forEach(({ current, hidden, diffViewType }) => {
it(`pushes to ${current} lines when diff view is ${diffViewType}`, () => {
const file = { file_path: 'test', parallel_diff_lines: [], highlighted_diff_lines: [] };
const state = { const state = {
diffFiles: [file], diffFiles: [file],
diffViewType,
}; };
mutations[types.ADD_CURRENT_VIEW_DIFF_FILE_LINES](state, { mutations[types.ADD_CURRENT_VIEW_DIFF_FILE_LINES](state, {
...@@ -990,17 +829,14 @@ describe('DiffsStoreMutations', () => { ...@@ -990,17 +829,14 @@ describe('DiffsStoreMutations', () => {
line: 'test', line: 'test',
}); });
expect(file[`${current}_diff_lines`]).toEqual(['test']); expect(file[INLINE_DIFF_LINES_KEY]).toEqual(['test']);
expect(file[`${hidden}_diff_lines`]).toEqual([]);
mutations[types.ADD_CURRENT_VIEW_DIFF_FILE_LINES](state, { mutations[types.ADD_CURRENT_VIEW_DIFF_FILE_LINES](state, {
filePath: 'test', filePath: 'test',
line: 'test2', line: 'test2',
}); });
expect(file[`${current}_diff_lines`]).toEqual(['test', 'test2']); expect(file[INLINE_DIFF_LINES_KEY]).toEqual(['test', 'test2']);
expect(file[`${hidden}_diff_lines`]).toEqual([]);
});
}); });
}); });
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
OLD_LINE_TYPE, OLD_LINE_TYPE,
MATCH_LINE_TYPE, MATCH_LINE_TYPE,
INLINE_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE,
PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_LINES_KEY,
} from '~/diffs/constants'; } from '~/diffs/constants';
import { MERGE_REQUEST_NOTEABLE_TYPE } from '~/notes/constants'; import { MERGE_REQUEST_NOTEABLE_TYPE } from '~/notes/constants';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
...@@ -20,14 +20,6 @@ import { noteableDataMock } from '../../notes/mock_data'; ...@@ -20,14 +20,6 @@ import { noteableDataMock } from '../../notes/mock_data';
const getDiffFileMock = () => JSON.parse(JSON.stringify(diffFileMockData)); const getDiffFileMock = () => JSON.parse(JSON.stringify(diffFileMockData));
const getDiffMetadataMock = () => JSON.parse(JSON.stringify(diffMetadata)); const getDiffMetadataMock = () => JSON.parse(JSON.stringify(diffMetadata));
function extractLinesFromFile(file) {
const unpackedParallel = file.parallel_diff_lines
.flatMap(({ left, right }) => [left, right])
.filter(Boolean);
return [...file.highlighted_diff_lines, ...unpackedParallel];
}
describe('DiffsStoreUtils', () => { describe('DiffsStoreUtils', () => {
describe('findDiffFile', () => { describe('findDiffFile', () => {
const files = [{ file_hash: 1, name: 'one' }]; const files = [{ file_hash: 1, name: 'one' }];
...@@ -45,7 +37,7 @@ describe('DiffsStoreUtils', () => { ...@@ -45,7 +37,7 @@ describe('DiffsStoreUtils', () => {
}); });
}); });
describe('findIndexInInlineLines and findIndexInParallelLines', () => { describe('findIndexInInlineLines', () => {
const expectSet = (method, lines, invalidLines) => { const expectSet = (method, lines, invalidLines) => {
expect(method(lines, { oldLineNumber: 3, newLineNumber: 5 })).toEqual(4); expect(method(lines, { oldLineNumber: 3, newLineNumber: 5 })).toEqual(4);
expect(method(invalidLines || lines, { oldLineNumber: 32, newLineNumber: 53 })).toEqual(-1); expect(method(invalidLines || lines, { oldLineNumber: 32, newLineNumber: 53 })).toEqual(-1);
...@@ -53,39 +45,22 @@ describe('DiffsStoreUtils', () => { ...@@ -53,39 +45,22 @@ describe('DiffsStoreUtils', () => {
describe('findIndexInInlineLines', () => { describe('findIndexInInlineLines', () => {
it('should return correct index for given line numbers', () => { it('should return correct index for given line numbers', () => {
expectSet(utils.findIndexInInlineLines, getDiffFileMock().highlighted_diff_lines); expectSet(utils.findIndexInInlineLines, getDiffFileMock()[INLINE_DIFF_LINES_KEY]);
});
});
describe('findIndexInParallelLines', () => {
it('should return correct index for given line numbers', () => {
expectSet(utils.findIndexInParallelLines, getDiffFileMock().parallel_diff_lines, []);
}); });
}); });
}); });
describe('getPreviousLineIndex', () => { describe('getPreviousLineIndex', () => {
[ describe(`with diffViewType (inline) in split diffs`, () => {
{ diffViewType: INLINE_DIFF_VIEW_TYPE, file: { parallel_diff_lines: [] } },
{ diffViewType: PARALLEL_DIFF_VIEW_TYPE, file: { highlighted_diff_lines: [] } },
].forEach(({ diffViewType, file }) => {
describe(`with diffViewType (${diffViewType}) in split diffs`, () => {
let diffFile; let diffFile;
beforeEach(() => { beforeEach(() => {
diffFile = { ...clone(diffFileMockData), ...file }; diffFile = { ...clone(diffFileMockData) };
}); });
it('should return the correct previous line number', () => { it('should return the correct previous line number', () => {
const emptyLines =
diffViewType === INLINE_DIFF_VIEW_TYPE
? diffFile.parallel_diff_lines
: diffFile.highlighted_diff_lines;
// This expectation asserts that we cannot possibly be using the opposite view type lines in the next expectation
expect(emptyLines.length).toBe(0);
expect( expect(
utils.getPreviousLineIndex(diffViewType, diffFile, { utils.getPreviousLineIndex(INLINE_DIFF_VIEW_TYPE, diffFile, {
oldLineNumber: 3, oldLineNumber: 3,
newLineNumber: 5, newLineNumber: 5,
}), }),
...@@ -93,89 +68,56 @@ describe('DiffsStoreUtils', () => { ...@@ -93,89 +68,56 @@ describe('DiffsStoreUtils', () => {
}); });
}); });
}); });
});
describe('removeMatchLine', () => { describe('removeMatchLine', () => {
it('should remove match line properly by regarding the bottom parameter', () => { it('should remove match line properly by regarding the bottom parameter', () => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 }; const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 };
const inlineIndex = utils.findIndexInInlineLines( const inlineIndex = utils.findIndexInInlineLines(
diffFile.highlighted_diff_lines, diffFile[INLINE_DIFF_LINES_KEY],
lineNumbers,
);
const parallelIndex = utils.findIndexInParallelLines(
diffFile.parallel_diff_lines,
lineNumbers, lineNumbers,
); );
const atInlineIndex = diffFile.highlighted_diff_lines[inlineIndex]; const atInlineIndex = diffFile[INLINE_DIFF_LINES_KEY][inlineIndex];
const atParallelIndex = diffFile.parallel_diff_lines[parallelIndex];
utils.removeMatchLine(diffFile, lineNumbers, false); utils.removeMatchLine(diffFile, lineNumbers, false);
expect(diffFile.highlighted_diff_lines[inlineIndex]).not.toEqual(atInlineIndex); expect(diffFile[INLINE_DIFF_LINES_KEY][inlineIndex]).not.toEqual(atInlineIndex);
expect(diffFile.parallel_diff_lines[parallelIndex]).not.toEqual(atParallelIndex);
utils.removeMatchLine(diffFile, lineNumbers, true); utils.removeMatchLine(diffFile, lineNumbers, true);
expect(diffFile.highlighted_diff_lines[inlineIndex + 1]).not.toEqual(atInlineIndex); expect(diffFile[INLINE_DIFF_LINES_KEY][inlineIndex + 1]).not.toEqual(atInlineIndex);
expect(diffFile.parallel_diff_lines[parallelIndex + 1]).not.toEqual(atParallelIndex);
}); });
}); });
describe('addContextLines', () => { describe('addContextLines', () => {
[INLINE_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE].forEach(diffViewType => { it(`should add context lines`, () => {
it(`should add context lines for ${diffViewType}`, () => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
const inlineLines = diffFile.highlighted_diff_lines; const inlineLines = diffFile[INLINE_DIFF_LINES_KEY];
const parallelLines = diffFile.parallel_diff_lines;
const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 }; const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 };
const contextLines = [{ lineNumber: 42, line_code: '123' }]; const contextLines = [{ lineNumber: 42, line_code: '123' }];
const options = { inlineLines, parallelLines, contextLines, lineNumbers, diffViewType }; const options = { inlineLines, contextLines, lineNumbers };
const inlineIndex = utils.findIndexInInlineLines(inlineLines, lineNumbers); const inlineIndex = utils.findIndexInInlineLines(inlineLines, lineNumbers);
const parallelIndex = utils.findIndexInParallelLines(parallelLines, lineNumbers);
const normalizedParallelLine = {
left: options.contextLines[0],
right: options.contextLines[0],
line_code: '123',
};
utils.addContextLines(options); utils.addContextLines(options);
if (diffViewType === INLINE_DIFF_VIEW_TYPE) {
expect(inlineLines[inlineIndex]).toEqual(contextLines[0]); expect(inlineLines[inlineIndex]).toEqual(contextLines[0]);
} else {
expect(parallelLines[parallelIndex]).toEqual(normalizedParallelLine);
}
}); });
it(`should add context lines properly with bottom parameter for ${diffViewType}`, () => { it(`should add context lines properly with bottom parameter`, () => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
const inlineLines = diffFile.highlighted_diff_lines; const inlineLines = diffFile[INLINE_DIFF_LINES_KEY];
const parallelLines = diffFile.parallel_diff_lines;
const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 }; const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 };
const contextLines = [{ lineNumber: 42, line_code: '123' }]; const contextLines = [{ lineNumber: 42, line_code: '123' }];
const options = { const options = {
inlineLines, inlineLines,
parallelLines,
contextLines, contextLines,
lineNumbers, lineNumbers,
bottom: true, bottom: true,
diffViewType,
};
const normalizedParallelLine = {
left: options.contextLines[0],
right: options.contextLines[0],
line_code: '123',
}; };
utils.addContextLines(options); utils.addContextLines(options);
if (diffViewType === INLINE_DIFF_VIEW_TYPE) {
expect(inlineLines[inlineLines.length - 1]).toEqual(contextLines[0]); expect(inlineLines[inlineLines.length - 1]).toEqual(contextLines[0]);
} else {
expect(parallelLines[parallelLines.length - 1]).toEqual(normalizedParallelLine);
}
});
}); });
}); });
...@@ -195,7 +137,6 @@ describe('DiffsStoreUtils', () => { ...@@ -195,7 +137,6 @@ describe('DiffsStoreUtils', () => {
new_line: 3, new_line: 3,
old_line: 1, old_line: 1,
}, },
diffViewType: PARALLEL_DIFF_VIEW_TYPE,
linePosition: LINE_POSITION_LEFT, linePosition: LINE_POSITION_LEFT,
lineRange: { start_line_code: 'abc_1_1', end_line_code: 'abc_2_2' }, lineRange: { start_line_code: 'abc_1_1', end_line_code: 'abc_2_2' },
}; };
...@@ -256,7 +197,6 @@ describe('DiffsStoreUtils', () => { ...@@ -256,7 +197,6 @@ describe('DiffsStoreUtils', () => {
new_line: 3, new_line: 3,
old_line: 1, old_line: 1,
}, },
diffViewType: PARALLEL_DIFF_VIEW_TYPE,
linePosition: LINE_POSITION_LEFT, linePosition: LINE_POSITION_LEFT,
}; };
...@@ -424,20 +364,6 @@ describe('DiffsStoreUtils', () => { ...@@ -424,20 +364,6 @@ describe('DiffsStoreUtils', () => {
expect(preppedLine).toEqual(correctLine); expect(preppedLine).toEqual(correctLine);
}); });
it('returns a nested object with "left" and "right" lines + the line code for `parallel` lines', () => {
preppedLine = utils.prepareLineForRenamedFile({
diffViewType: PARALLEL_DIFF_VIEW_TYPE,
line: sourceLine,
index: lineIndex,
diffFile,
});
expect(Object.keys(preppedLine)).toEqual(['left', 'right', 'line_code']);
expect(preppedLine.left).toEqual(correctLine);
expect(preppedLine.right).toEqual(correctLine);
expect(preppedLine.line_code).toEqual(correctLine.line_code);
});
it.each` it.each`
brokenSymlink brokenSymlink
${false} ${false}
...@@ -474,13 +400,13 @@ describe('DiffsStoreUtils', () => { ...@@ -474,13 +400,13 @@ describe('DiffsStoreUtils', () => {
preparedDiff = { diff_files: [mock] }; preparedDiff = { diff_files: [mock] };
splitInlineDiff = { splitInlineDiff = {
diff_files: [{ ...mock, parallel_diff_lines: undefined }], diff_files: [{ ...mock }],
}; };
splitParallelDiff = { splitParallelDiff = {
diff_files: [{ ...mock, highlighted_diff_lines: undefined }], diff_files: [{ ...mock, [INLINE_DIFF_LINES_KEY]: undefined }],
}; };
completedDiff = { completedDiff = {
diff_files: [{ ...mock, highlighted_diff_lines: undefined }], diff_files: [{ ...mock, [INLINE_DIFF_LINES_KEY]: undefined }],
}; };
preparedDiff.diff_files = utils.prepareDiffData(preparedDiff); preparedDiff.diff_files = utils.prepareDiffData(preparedDiff);
...@@ -490,19 +416,7 @@ describe('DiffsStoreUtils', () => { ...@@ -490,19 +416,7 @@ describe('DiffsStoreUtils', () => {
}); });
it('sets the renderIt and collapsed attribute on files', () => { it('sets the renderIt and collapsed attribute on files', () => {
const firstParallelDiffLine = preparedDiff.diff_files[0].parallel_diff_lines[2]; const checkLine = preparedDiff.diff_files[0][INLINE_DIFF_LINES_KEY][0];
expect(firstParallelDiffLine.left.discussions.length).toBe(0);
expect(firstParallelDiffLine.left).not.toHaveAttr('text');
expect(firstParallelDiffLine.right.discussions.length).toBe(0);
expect(firstParallelDiffLine.right).not.toHaveAttr('text');
const firstParallelChar = firstParallelDiffLine.right.rich_text.charAt(0);
expect(firstParallelChar).not.toBe(' ');
expect(firstParallelChar).not.toBe('+');
expect(firstParallelChar).not.toBe('-');
const checkLine = preparedDiff.diff_files[0].highlighted_diff_lines[0];
expect(checkLine.discussions.length).toBe(0); expect(checkLine.discussions.length).toBe(0);
expect(checkLine).not.toHaveAttr('text'); expect(checkLine).not.toHaveAttr('text');
...@@ -516,29 +430,14 @@ describe('DiffsStoreUtils', () => { ...@@ -516,29 +430,14 @@ describe('DiffsStoreUtils', () => {
expect(preparedDiff.diff_files[0].collapsed).toBeFalsy(); expect(preparedDiff.diff_files[0].collapsed).toBeFalsy();
}); });
it('adds line_code to all lines', () => {
expect(
preparedDiff.diff_files[0].parallel_diff_lines.filter(line => !line.line_code),
).toHaveLength(0);
});
it('uses right line code if left has none', () => {
const firstLine = preparedDiff.diff_files[0].parallel_diff_lines[0];
expect(firstLine.line_code).toEqual(firstLine.right.line_code);
});
it('guarantees an empty array for both diff styles', () => { it('guarantees an empty array for both diff styles', () => {
expect(splitInlineDiff.diff_files[0].parallel_diff_lines.length).toEqual(0); expect(splitInlineDiff.diff_files[0][INLINE_DIFF_LINES_KEY].length).toBeGreaterThan(0);
expect(splitInlineDiff.diff_files[0].highlighted_diff_lines.length).toBeGreaterThan(0); expect(splitParallelDiff.diff_files[0][INLINE_DIFF_LINES_KEY].length).toEqual(0);
expect(splitParallelDiff.diff_files[0].parallel_diff_lines.length).toBeGreaterThan(0);
expect(splitParallelDiff.diff_files[0].highlighted_diff_lines.length).toEqual(0);
}); });
it('merges existing diff files with newly loaded diff files to ensure split diffs are eventually completed', () => { it('merges existing diff files with newly loaded diff files to ensure split diffs are eventually completed', () => {
expect(completedDiff.diff_files.length).toEqual(1); expect(completedDiff.diff_files.length).toEqual(1);
expect(completedDiff.diff_files[0].parallel_diff_lines.length).toBeGreaterThan(0); expect(completedDiff.diff_files[0][INLINE_DIFF_LINES_KEY].length).toBeGreaterThan(0);
expect(completedDiff.diff_files[0].highlighted_diff_lines.length).toBeGreaterThan(0);
}); });
it('leaves files in the existing state', () => { it('leaves files in the existing state', () => {
...@@ -555,11 +454,11 @@ describe('DiffsStoreUtils', () => { ...@@ -555,11 +454,11 @@ describe('DiffsStoreUtils', () => {
it('completes an existing split diff without overwriting existing diffs', () => { it('completes an existing split diff without overwriting existing diffs', () => {
// The current state has a file that has only loaded inline lines // The current state has a file that has only loaded inline lines
const priorFiles = [{ ...mock, parallel_diff_lines: [] }]; const priorFiles = [{ ...mock }];
// The next (batch) load loads two files: the other half of that file, and a new file // The next (batch) load loads two files: the other half of that file, and a new file
const fakeBatch = [ const fakeBatch = [
{ ...mock, highlighted_diff_lines: undefined }, { ...mock, [INLINE_DIFF_LINES_KEY]: undefined },
{ ...mock, highlighted_diff_lines: undefined, content_sha: 'ABC', file_hash: 'DEF' }, { ...mock, [INLINE_DIFF_LINES_KEY]: undefined, content_sha: 'ABC', file_hash: 'DEF' },
]; ];
const updatedFilesList = utils.prepareDiffData({ diff_files: fakeBatch }, priorFiles); const updatedFilesList = utils.prepareDiffData({ diff_files: fakeBatch }, priorFiles);
...@@ -584,7 +483,7 @@ describe('DiffsStoreUtils', () => { ...@@ -584,7 +483,7 @@ describe('DiffsStoreUtils', () => {
...splitInlineDiff.diff_files, ...splitInlineDiff.diff_files,
...splitParallelDiff.diff_files, ...splitParallelDiff.diff_files,
...completedDiff.diff_files, ...completedDiff.diff_files,
].flatMap(file => extractLinesFromFile(file)); ].flatMap(file => [...file[INLINE_DIFF_LINES_KEY]]);
lines.forEach(line => { lines.forEach(line => {
expect(line.commentsDisabled).toBe(false); expect(line.commentsDisabled).toBe(false);
...@@ -608,8 +507,7 @@ describe('DiffsStoreUtils', () => { ...@@ -608,8 +507,7 @@ describe('DiffsStoreUtils', () => {
}); });
it('guarantees an empty array of lines for both diff styles', () => { it('guarantees an empty array of lines for both diff styles', () => {
expect(preparedDiffFiles[0].parallel_diff_lines.length).toEqual(0); expect(preparedDiffFiles[0][INLINE_DIFF_LINES_KEY].length).toEqual(0);
expect(preparedDiffFiles[0].highlighted_diff_lines.length).toEqual(0);
}); });
it('leaves files in the existing state', () => { it('leaves files in the existing state', () => {
...@@ -647,8 +545,7 @@ describe('DiffsStoreUtils', () => { ...@@ -647,8 +545,7 @@ describe('DiffsStoreUtils', () => {
fileMock, fileMock,
{ {
...metaMock.diff_files[0], ...metaMock.diff_files[0],
highlighted_diff_lines: [], [INLINE_DIFF_LINES_KEY]: [],
parallel_diff_lines: [],
}, },
]); ]);
}); });
...@@ -1217,7 +1114,7 @@ describe('DiffsStoreUtils', () => { ...@@ -1217,7 +1114,7 @@ describe('DiffsStoreUtils', () => {
it('converts inline diff lines to parallel diff lines', () => { it('converts inline diff lines to parallel diff lines', () => {
const file = getDiffFileMock(); const file = getDiffFileMock();
expect(utils.parallelizeDiffLines(file.highlighted_diff_lines)).toEqual( expect(utils.parallelizeDiffLines(file[INLINE_DIFF_LINES_KEY])).toEqual(
file.parallel_diff_lines, file.parallel_diff_lines,
); );
}); });
......
...@@ -358,30 +358,4 @@ RSpec.describe DiffHelper do ...@@ -358,30 +358,4 @@ RSpec.describe DiffHelper do
expect(diff_file_path_text(diff_file, max: 10)).to eq("...open.rb") expect(diff_file_path_text(diff_file, max: 10)).to eq("...open.rb")
end end
end end
describe 'unified_diff_lines_view_type' do
before do
controller.params[:view] = 'parallel'
end
describe 'unified diffs enabled' do
before do
stub_feature_flags(unified_diff_lines: true)
end
it 'returns inline view' do
expect(helper.unified_diff_lines_view_type(project)).to eq 'inline'
end
end
describe 'unified diffs disabled' do
before do
stub_feature_flags(unified_diff_lines: false)
end
it 'returns parallel view' do
expect(helper.unified_diff_lines_view_type(project)).to eq :parallel
end
end
end
end end
...@@ -215,10 +215,6 @@ RSpec.configure do |config| ...@@ -215,10 +215,6 @@ RSpec.configure do |config|
stub_feature_flags(vue_issuable_sidebar: false) stub_feature_flags(vue_issuable_sidebar: false)
stub_feature_flags(vue_issuable_epic_sidebar: false) stub_feature_flags(vue_issuable_epic_sidebar: false)
# The following can be removed once we are confident the
# unified diff lines works as expected
stub_feature_flags(unified_diff_lines: false)
# Merge request widget GraphQL requests are disabled in the tests # Merge request widget GraphQL requests are disabled in the tests
# for now whilst we migrate as much as we can over the GraphQL # for now whilst we migrate as much as we can over the GraphQL
stub_feature_flags(merge_request_widget_graphql: false) stub_feature_flags(merge_request_widget_graphql: false)
...@@ -238,6 +234,8 @@ RSpec.configure do |config| ...@@ -238,6 +234,8 @@ RSpec.configure do |config|
# See https://gitlab.com/gitlab-org/gitlab/-/issues/33867 # See https://gitlab.com/gitlab-org/gitlab/-/issues/33867
stub_feature_flags(file_identifier_hash: false) stub_feature_flags(file_identifier_hash: false)
stub_feature_flags(unified_diff_components: false)
allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged) allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged)
else else
unstub_all_feature_flags unstub_all_feature_flags
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment