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')
-rw-r--r--spec/frontend/diffs/utils/diff_file_spec.js71
-rw-r--r--spec/frontend/diffs/utils/queue_events_spec.js37
2 files changed, 107 insertions, 1 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);
+ });
+ });
+ });
});
diff --git a/spec/frontend/diffs/utils/queue_events_spec.js b/spec/frontend/diffs/utils/queue_events_spec.js
index 007748d8b2c..ad2745f5188 100644
--- a/spec/frontend/diffs/utils/queue_events_spec.js
+++ b/spec/frontend/diffs/utils/queue_events_spec.js
@@ -1,11 +1,15 @@
import api from '~/api';
-import { DEFER_DURATION } from '~/diffs/constants';
+import { DEFER_DURATION, TRACKING_CAP_KEY, TRACKING_CAP_LENGTH } from '~/diffs/constants';
import { queueRedisHllEvents } from '~/diffs/utils/queue_events';
jest.mock('~/api', () => ({
trackRedisHllUserEvent: jest.fn(),
}));
+beforeAll(() => {
+ localStorage.clear();
+});
+
describe('diffs events queue', () => {
describe('queueRedisHllEvents', () => {
it('does not dispatch the event immediately', () => {
@@ -17,6 +21,7 @@ describe('diffs events queue', () => {
queueRedisHllEvents(['know_event']);
jest.advanceTimersByTime(DEFER_DURATION + 1);
expect(api.trackRedisHllUserEvent).toHaveBeenCalled();
+ expect(localStorage.getItem(TRACKING_CAP_KEY)).toBe(null);
});
it('increase defer duration based on the provided events count', () => {
@@ -32,5 +37,35 @@ describe('diffs events queue', () => {
deferDuration *= index + 1;
});
});
+
+ describe('with tracking cap verification', () => {
+ const currentTimestamp = Date.now();
+
+ beforeEach(() => {
+ localStorage.clear();
+ });
+
+ it('dispatches the event if cap value is not found', () => {
+ queueRedisHllEvents(['know_event'], { verifyCap: true });
+ jest.advanceTimersByTime(DEFER_DURATION + 1);
+ expect(api.trackRedisHllUserEvent).toHaveBeenCalled();
+ expect(localStorage.getItem(TRACKING_CAP_KEY)).toBe(currentTimestamp.toString());
+ });
+
+ it('dispatches the event if cap value is less than limit', () => {
+ localStorage.setItem(TRACKING_CAP_KEY, 1);
+ queueRedisHllEvents(['know_event'], { verifyCap: true });
+ jest.advanceTimersByTime(DEFER_DURATION + 1);
+ expect(api.trackRedisHllUserEvent).toHaveBeenCalled();
+ expect(localStorage.getItem(TRACKING_CAP_KEY)).toBe(currentTimestamp.toString());
+ });
+
+ it('does not dispatch the event if cap value is greater than limit', () => {
+ localStorage.setItem(TRACKING_CAP_KEY, currentTimestamp - (TRACKING_CAP_LENGTH + 1));
+ queueRedisHllEvents(['know_event'], { verifyCap: true });
+ jest.advanceTimersByTime(DEFER_DURATION + 1);
+ expect(api.trackRedisHllUserEvent).toHaveBeenCalled();
+ });
+ });
});
});