Commit 4ef6ed6e authored by Thomas Randolph's avatar Thomas Randolph

Add and update tests for marking files as broken symlinks

parent ea86163b
import { prepareRawDiffFile } from '~/diffs/diff_file';
const DIFF_FILES = [
{
file_hash: 'ABC', // This file is just a normal file
},
{
file_hash: 'DEF', // This file replaces a symlink
a_mode: '0',
b_mode: '0755',
},
{
file_hash: 'DEF', // This symlink is replaced by a file
a_mode: '120000',
b_mode: '0',
},
{
file_hash: 'GHI', // This symlink replaces a file
a_mode: '0',
b_mode: '120000',
},
{
file_hash: 'GHI', // This file is replaced by a symlink
a_mode: '0755',
b_mode: '0',
},
];
function makeBrokenSymlinkObject(replaced, wasSymbolic, isSymbolic, wasReal, isReal) {
return {
replaced,
wasSymbolic,
isSymbolic,
wasReal,
isReal,
};
}
describe('diff_file utilities', () => {
describe('prepareRawDiffFile', () => {
it.each`
fileIndex | description | brokenSymlink
${0} | ${'a file that is not symlink-adjacent'} | ${false}
${1} | ${'a file that replaces a symlink'} | ${makeBrokenSymlinkObject(false, false, false, false, true)}
${2} | ${'a symlink that is replaced by a file'} | ${makeBrokenSymlinkObject(true, true, false, false, false)}
${3} | ${'a symlink that replaces a file'} | ${makeBrokenSymlinkObject(false, false, true, false, false)}
${4} | ${'a file that is replaced by a symlink'} | ${makeBrokenSymlinkObject(true, false, false, true, false)}
`(
'properly marks $description with the correct .brokenSymlink value',
({ fileIndex, brokenSymlink }) => {
const preppedRaw = prepareRawDiffFile({
file: DIFF_FILES[fileIndex],
allFiles: DIFF_FILES,
});
expect(preppedRaw.brokenSymlink).toStrictEqual(brokenSymlink);
},
);
});
});
......@@ -20,6 +20,14 @@ import { noteableDataMock } from '../../notes/mock_data';
const getDiffFileMock = () => JSON.parse(JSON.stringify(diffFileMockData));
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('findDiffFile', () => {
const files = [{ file_hash: 1, name: 'one' }];
......@@ -429,6 +437,28 @@ describe('DiffsStoreUtils', () => {
expect(preppedLine.right).toEqual(correctLine);
expect(preppedLine.line_code).toEqual(correctLine.line_code);
});
it.each`
brokenSymlink
${false}
${{}}
${'anything except `false`'}
`(
"properly assigns each line's `commentsDisabled` as the same value as the parent file's `brokenSymlink` value (`$brokenSymlink`)",
({ brokenSymlink }) => {
preppedLine = utils.prepareLineForRenamedFile({
diffViewType: INLINE_DIFF_VIEW_TYPE,
line: sourceLine,
index: lineIndex,
diffFile: {
...diffFile,
brokenSymlink,
},
});
expect(preppedLine.commentsDisabled).toStrictEqual(brokenSymlink);
},
);
});
describe('prepareDiffData', () => {
......@@ -541,6 +571,25 @@ describe('DiffsStoreUtils', () => {
}),
]);
});
it('adds the `.brokenSymlink` property to each diff file', () => {
preparedDiff.diff_files.forEach(file => {
expect(file).toEqual(expect.objectContaining({ brokenSymlink: false }));
});
});
it("copies the diff file's `.brokenSymlink` value to each of that file's child lines", () => {
const lines = [
...preparedDiff.diff_files,
...splitInlineDiff.diff_files,
...splitParallelDiff.diff_files,
...completedDiff.diff_files,
].flatMap(file => extractLinesFromFile(file));
lines.forEach(line => {
expect(line.commentsDisabled).toBe(false);
});
});
});
describe('for diff metadata', () => {
......@@ -603,6 +652,12 @@ describe('DiffsStoreUtils', () => {
},
]);
});
it('adds the `.brokenSymlink` property to each meta diff file', () => {
preparedDiffFiles.forEach(file => {
expect(file).toMatchObject({ brokenSymlink: false });
});
});
});
});
......
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