Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/diffs/utils/diff_file_spec.js')
-rw-r--r--spec/frontend/diffs/utils/diff_file_spec.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/frontend/diffs/utils/diff_file_spec.js b/spec/frontend/diffs/utils/diff_file_spec.js
index 3223b6c2dab..778897be3ba 100644
--- a/spec/frontend/diffs/utils/diff_file_spec.js
+++ b/spec/frontend/diffs/utils/diff_file_spec.js
@@ -3,6 +3,7 @@ import {
getShortShaFromFile,
stats,
isNotDiffable,
+ match,
} from '~/diffs/utils/diff_file';
import { diffViewerModes } from '~/ide/constants';
import mockDiffFile from '../mock_data/diff_file';
@@ -149,6 +150,38 @@ describe('diff_file utilities', () => {
expect(preppedFile).not.toHaveProp('id');
});
+
+ it.each`
+ index
+ ${null}
+ ${undefined}
+ ${-1}
+ ${false}
+ ${true}
+ ${'idx'}
+ ${'42'}
+ `('does not set the order property if an invalid index ($index) is provided', ({ index }) => {
+ const preppedFile = prepareRawDiffFile({
+ file: files[0],
+ allFiles: files,
+ index,
+ });
+
+ /* expect.anything() doesn't match null or undefined */
+ expect(preppedFile).toEqual(expect.not.objectContaining({ order: null }));
+ expect(preppedFile).toEqual(expect.not.objectContaining({ order: undefined }));
+ expect(preppedFile).toEqual(expect.not.objectContaining({ order: expect.anything() }));
+ });
+
+ it('sets the provided valid index to the order property', () => {
+ const preppedFile = prepareRawDiffFile({
+ file: files[0],
+ allFiles: files,
+ index: 42,
+ });
+
+ expect(preppedFile).toEqual(expect.objectContaining({ order: 42 }));
+ });
});
describe('getShortShaFromFile', () => {
@@ -230,4 +263,42 @@ describe('diff_file utilities', () => {
expect(isNotDiffable(file)).toBe(false);
});
});
+
+ describe('match', () => {
+ const authorityFileId = '68296a4f-f1c7-445a-bd0e-6e3b02c4eec0';
+ const fih = 'file_identifier_hash';
+ const fihs = 'file identifier hashes';
+ let authorityFile;
+
+ beforeAll(() => {
+ const files = getDiffFiles();
+
+ authorityFile = prepareRawDiffFile({
+ file: files[0],
+ allFiles: files,
+ });
+
+ Object.freeze(authorityFile);
+ });
+
+ describe.each`
+ mode | comparisonFiles | keyName
+ ${'universal'} | ${[{ [fih]: 'ABC1' }, { id: 'foo' }, { id: authorityFileId }]} | ${'ids'}
+ ${'mr'} | ${[{ id: authorityFileId }, { [fih]: 'ABC2' }, { [fih]: 'ABC1' }]} | ${fihs}
+ `('$mode mode', ({ mode, comparisonFiles, keyName }) => {
+ it(`fails to match if files or ${keyName} aren't present`, () => {
+ expect(match({ fileA: authorityFile, fileB: undefined, mode })).toBe(false);
+ expect(match({ fileA: authorityFile, fileB: null, mode })).toBe(false);
+ expect(match({ fileA: authorityFile, fileB: comparisonFiles[0], mode })).toBe(false);
+ });
+
+ it(`fails to match if the ${keyName} aren't the same`, () => {
+ expect(match({ fileA: authorityFile, fileB: comparisonFiles[1], mode })).toBe(false);
+ });
+
+ it(`matches if the ${keyName} are the same`, () => {
+ expect(match({ fileA: authorityFile, fileB: comparisonFiles[2], mode })).toBe(true);
+ });
+ });
+ });
});