Commit 3e86f62f authored by Thomas Randolph's avatar Thomas Randolph

Add utility to determine if a file is considered diffable

parent 8f0fce0e
import { diffViewerModes as viewerModes } from '~/ide/constants';
import { truncateSha } from '~/lib/utils/text_utility'; import { truncateSha } from '~/lib/utils/text_utility';
import { uuids } from '~/lib/utils/uuids'; import { uuids } from '~/lib/utils/uuids';
...@@ -46,6 +47,8 @@ function identifier(file) { ...@@ -46,6 +47,8 @@ function identifier(file) {
})[0]; })[0];
} }
export const isNotDiffable = (file) => file?.viewer?.name === viewerModes.not_diffable;
export function prepareRawDiffFile({ file, allFiles, meta = false }) { export function prepareRawDiffFile({ file, allFiles, meta = false }) {
const additionalProperties = { const additionalProperties = {
brokenSymlink: fileSymlinkInformation(file, allFiles), brokenSymlink: fileSymlinkInformation(file, allFiles),
......
import { prepareRawDiffFile, getShortShaFromFile } from '~/diffs/utils/diff_file'; import { prepareRawDiffFile, getShortShaFromFile, isNotDiffable } from '~/diffs/utils/diff_file';
import { diffViewerModes } from '~/ide/constants';
function getDiffFiles() { function getDiffFiles() {
const loadFull = 'namespace/project/-/merge_requests/12345/diff_for_path?file_identifier=abc'; const loadFull = 'namespace/project/-/merge_requests/12345/diff_for_path?file_identifier=abc';
...@@ -154,4 +155,26 @@ describe('diff_file utilities', () => { ...@@ -154,4 +155,26 @@ describe('diff_file utilities', () => {
expect(getShortShaFromFile({ content_sha: cs })).toBe(response); expect(getShortShaFromFile({ content_sha: cs })).toBe(response);
}); });
}); });
describe('isNotDiffable', () => {
it.each`
bool | vw
${true} | ${diffViewerModes.not_diffable}
${false} | ${diffViewerModes.text}
${false} | ${diffViewerModes.image}
`('returns $bool when the viewer is $vw', ({ bool, vw }) => {
expect(isNotDiffable({ viewer: { name: vw } })).toBe(bool);
});
it.each`
file
${undefined}
${null}
${{}}
${{ viewer: undefined }}
${{ viewer: null }}
`('reports `false` when the file is `$file`', ({ file }) => {
expect(isNotDiffable(file)).toBe(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