level_0
int64
0
10k
index
int64
0
0
repo_id
stringlengths
22
152
file_path
stringlengths
41
203
content
stringlengths
11
11.5M
9,588
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/addItem.test.ts
import addItem from './addItem'; describe('addItem()', () => { it('adds item to empty array', () => { const item = 'item to add'; const result = addItem([], item); expect(result).toStrictEqual([item]); }); it('appends item to ends of array', () => { const array = ['item 1...
9,590
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/arraysContainSameElements.test.ts
import arraysContainSameElements from './arraysContainSameElements'; describe('arraysContainSameElements()', () => { it('returns true for empty arrays', () => { const result = arraysContainSameElements([], []); expect(result).toBeTruthy(); }); it('returns false if arrays are of different ...
9,592
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/capitalize.test.ts
import capitalize from './capitalize'; describe('capitalize()', () => { it('returns undefined when called with undefined', () => { expect(capitalize(undefined)).toBe(undefined); }); it('returns an empty string when an empty string is provided', () => { expect(capitalize('')).toBe(''); ...
9,594
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/chunk.test.ts
import chunk from './chunk'; describe('chunk()', () => { it('creates an array of chunks of a given other array of fixed size', () => { const output = chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'], 3); const expected = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['...
9,596
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/clamp.test.ts
import clamp from './clamp'; describe('clamp()', () => { it('returns the exact value passed in if it already lies between min & max', () => { expect(clamp(7, 0, 10)).toBe(7); }); it('returns the min if the value passed in is lower than min', () => { expect(clamp(-2, 0, 10)).toBe(0); })...
9,598
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/clsx.test.ts
import clsx from './clsx'; describe('clsx()', () => { it('handles array arguments', () => { const result = clsx(['a', 'b']); expect(result).toBe('a b'); }); it('returns empty string when empty array is passed', () => { const result = clsx([]); expect(result).toBe(''); ...
9,600
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/compare.test.ts
import compare from './compare'; describe('compare()', () => { it('returns 1 if a is greater than b', () => { const result = compare(2, 1); expect(result).toBe(1); }); it('returns -1 if a is greater than b', () => { const result = compare(1, 2); expect(result).toBe(-1); ...
9,602
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/debounce.test.ts
import debounce from './debounce'; describe('debounce()', () => { beforeAll(() => { jest.useFakeTimers(); }); afterEach(() => { jest.clearAllTimers(); }); afterAll(() => { jest.useRealTimers(); }); it('delays invoking function until after wait time', () => { ...
9,604
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/diff.test.ts
import diff from './diff'; describe('diff()', () => { it('finds all values that are present in a given first array but not present in a given second array', () => { const output = diff([1, null, 'a', true], [1, undefined, 'a', false]); const expected = [null, true]; expect(output).toEqual...
9,606
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/getRandomString.test.ts
import { disableRandomMock, initRandomMock } from '@proton/testing/lib/mockRandomValues'; import getRandomString, { DEFAULT_CHARSET } from './getRandomString'; describe('getRandomString()', () => { const getConsecutiveArray = (length: number) => [...Array(length).keys()]; const mockedRandomValues = jest ...
9,608
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/getSafeErrorObject.test.ts
import { getSafeArray, getSafeErrorObject, getSafeObject, getSafeValue } from './getSafeErrorObject'; describe('getSafeValue', () => { const error = new Error('blah'); const testCases = [ { name: 'number', value: 3, expected: 3 }, { name: 'string', value: 'abc', expected: 'abc' }, { na...
9,610
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/groupWith.test.ts
import groupWith from './groupWith'; describe('groupWith', () => { it('groups items of an array into a two dimensional array based on a condition of whether or not two items should be grouped', () => { expect(groupWith((a, b) => a === b, [1, 1, 1, 2, 2, 3])).toEqual([[1, 1, 1], [2, 2], [3]]); }); ...
9,612
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/identity.test.ts
import identity from './identity'; describe('identity()', () => { it('returns the value as reference', () => { const value = {}; expect(identity(value)).toBe(value); }); });
9,614
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/isArrayOfUint8Array.test.ts
import isArrayOfUint8Array from './isArrayOfUint8Array'; describe('isArrayOfUint8Array()', () => { it('returns true if array is empty', () => { const result = isArrayOfUint8Array([]); expect(result).toBe(true); }); it('returns true if every item is an instance of Uint8Array', () => { ...
9,616
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/isBetween.test.ts
import isBetween from './isBetween'; describe('isBetween()', () => { it('returns true if a given number is between two other given number', () => { expect(isBetween(5, -10, 10)).toBe(true); }); it('returns true if a given number is exactly equal to the min', () => { expect(isBetween(-10, -...
9,618
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/isFunction.test.ts
import isFunction from './isFunction'; it('should return true for class', () => { const result = isFunction(class Any {}); expect(result).toEqual(true); }); it('should return true for function', () => { const result = isFunction(() => {}); expect(result).toEqual(true); }); it('should return true for ...
9,620
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/isLastWeek.test.ts
import isLastWeek from './isLastWeek'; describe('isLastWeek', () => { beforeEach(() => { jest.useFakeTimers().setSystemTime(new Date('2023-03-27T20:00:00')); }); afterEach(() => { jest.useRealTimers(); }); it('should return true if the date is in the last week', () => { co...
9,622
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/isTruthy.test.ts
import isTruthy from './isTruthy'; describe('isTruthy()', () => { it('tells whether a value is JavaScript "truthy" or not', () => { expect(isTruthy(false)).toBe(false); expect(isTruthy(null)).toBe(false); expect(isTruthy(0)).toBe(false); expect(isTruthy(undefined)).toBe(false); ...
9,627
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/lastItem.test.ts
import lastItem from './lastItem'; describe('lastItem()', () => { it('should return undefined when array is empty', () => { const result = lastItem([]); expect(result).toBe(undefined); }); it('should return only item when array is of length 1', () => { const item = 'item'; ...
9,629
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/mergeUint8Arrays.test.ts
import mergeUint8Arrays from './mergeUint8Arrays'; describe('mergeUint8Arrays()', () => { it('returns empty array if arrays is empty', () => { const arrays: Uint8Array[] = []; const result = mergeUint8Arrays(arrays); expect(result).toStrictEqual(new Uint8Array()); }); it('merges ...
9,631
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/mod.test.ts
import mod from './mod'; describe('mod()', () => { it('should return a positive remainder', () => { expect(mod(-4, 3)).toEqual(2); expect(mod(-3, 3)).toEqual(0); expect(mod(-2, 3)).toEqual(1); expect(mod(-1, 3)).toEqual(2); expect(mod(0, 3)).toEqual(0); expect(mod(1,...
9,633
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/move.test.ts
import move from './move'; describe('move()', () => { it('should return a new array', () => { const list = [1, 2, 3, 4, 5]; expect(move(list, 0, 0) !== list).toBeTruthy(); }); it('should correctly move elements to new positions', () => { const list = [1, 2, 3, 4, 5]; expect...
9,635
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/noop.test.ts
import noop from './noop'; describe('noop()', () => { it('returns undefined', () => { expect(noop()).toBe(undefined); }); });
9,637
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/orderBy.test.ts
import orderBy from './orderBy'; describe('orderBy()', () => { it('orders an array of objects by the numeric value of a given property of the objects in the array', () => { const arrayOfObjects = [{ id: 7 }, { id: 3 }, { id: 3 }, { id: 6 }, { id: 18 }, { id: 2 }]; const output = orderBy(arrayOfObj...
9,640
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/partition.test.ts
import partition from './partition'; describe('partition()', () => { it('returns empty arrays if array is empty', () => { const array: string[] = []; const predicate = (item: string): item is string => { return typeof item === 'string'; }; const result = partition(array...
9,642
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/percentOf.test.ts
import percentOf from './percentOf'; describe('percentOf()', () => { it('returns the value of a percentage of another value', () => { const output = percentOf(10, 200); expect(output).toBe(20); }); it("returns a decimal in case the percentage can't be resolved in integers", () => { ...
9,644
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/percentage.test.ts
import percentage from './percentage'; describe('percentage()', () => { it('returns the percentage between an entire and a fraction', () => { const output = percentage(500, 100); expect(output).toBe(20); }); it("returns a decimal in case the percentage can't be resolved in integers", () =...
9,646
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/randomIntFromInterval.test.ts
import randomIntFromInterval from './randomIntFromInterval'; describe('randomIntFromInterval()', () => { it('should be able to return min', () => { jest.spyOn(Math, 'random').mockReturnValue(0); const min = 1; const max = 100; const result = randomIntFromInterval(min, max); ...
9,648
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/range.test.ts
import range from './range'; describe('range()', () => { it('defaults to creating a specific array if no arguments are provided', () => { expect(range()).toEqual([0]); }); it('returns an empty array if end is before start', () => { expect(range(10, 2)).toEqual([]); }); it('returns...
9,650
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/remove.test.ts
import remove from './remove'; describe('remove()', () => { it('removes an item from an array', () => { const output = remove(['a', 'b', 'c'], 'b'); expect(output).toEqual(['a', 'c']); }); it('removes only the first occurence should there be multiple', () => { const output = remove...
9,652
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/removeIndex.test.ts
import removeIndex from './removeIndex'; describe('removeIndex()', () => { it('removes item at a given index from an array', () => { const output = removeIndex(['a', 'b', 'c', 'd', 'e'], 2); const expected = ['a', 'b', 'd', 'e']; expect(output).toEqual(expected); }); });
9,654
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/replace.test.ts
import replace from './replace'; describe('replace()', () => { it('replaces an item from an array', () => { const output = replace(['a', 'b', 'c'], 'b', 'x'); expect(output).toEqual(['a', 'x', 'c']); }); it('replaces only the first occurence should there be multiple', () => { const...
9,656
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/shallowEqual.test.ts
import shallowEqual from './shallowEqual'; describe('shallowEqual()', () => { it('returns true when comparing 2 empty arrays', () => { const result = shallowEqual([], []); expect(result).toBe(true); }); it('returns true if arrays contain the same items', () => { const result = sha...
9,658
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/shuffle.test.ts
import shuffle from './shuffle'; describe('shuffle()', () => { it('returns empty array when empty array is passed', () => { const result = shuffle([]); expect(result).toStrictEqual([]); }); it('returns same array when array of length 1 is passed', () => { const input = [0]; ...
9,660
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/throttle.test.ts
import throttle from './throttle'; describe('throttle()', () => { beforeAll(() => { jest.useFakeTimers(); }); afterEach(() => { jest.clearAllTimers(); }); afterAll(() => { jest.useRealTimers(); }); it('invokes function at most once every wait milliseconds', () => ...
9,662
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/truncate.test.ts
import truncate, { DEFAULT_TRUNCATE_OMISSION } from './truncate'; describe('truncate()', () => { it('returns empty sting if provided string is empty', () => { expect(truncate('', 0)).toEqual(''); expect(truncate('', 1)).toEqual(''); expect(truncate('', 2)).toEqual(''); }); it('trun...
9,665
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/unary.test.ts
import unary from './unary'; describe('unary()', () => { it('should handle functions with no arguments', () => { const myFunction = () => { return 'myFunction'; }; const unaryFunction = unary(myFunction); expect(unaryFunction('I still require an argument')).toEqual('my...
9,667
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/uncapitalize.test.ts
import uncapitalize from './uncapitalize'; describe('uncapitalize()', () => { it('returns an empty string when an empty string is provided', () => { expect(uncapitalize('')).toBe(''); }); it('uncapitalizes a single letter', () => { expect(uncapitalize('A')).toBe('a'); }); it('unca...
9,669
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/unique.test.ts
import unique from './unique'; describe('unique()', () => { it('should return same', () => { expect(unique([1, 2])).toEqual([1, 2]); }); it('should only return unique items', () => { expect(unique([1, 2, 1])).toEqual([1, 2]); }); });
9,671
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/uniqueBy.test.ts
import uniqueBy from './uniqueBy'; describe('uniqueBy()', () => { it('should only get unique items', () => { const list = [{ foo: 'abc' }, { foo: 'bar' }, { foo: 'asd' }, { foo: 'bar' }, { foo: 'bar' }]; expect(uniqueBy(list, ({ foo }) => foo)).toEqual([{ foo: 'abc' }, { foo: 'bar' }, { foo: 'asd' ...
9,673
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/updateItem.test.ts
import updateItem from './updateItem'; describe('updateItem()', () => { it('returns empty array if array is empty', () => { const array: any[] = []; const index = 1; const newItem = 'new item'; const result = updateItem(array, index, newItem); expect(result).toStrictEqual(...
9,675
0
petrpan-code/ProtonMail/WebClients/packages
petrpan-code/ProtonMail/WebClients/packages/utils/withDecimalPrecision.test.ts
import withDecimalPrecision from './withDecimalPrecision'; describe('withDecimalPrecision()', () => { it('returns the same number when the precision is infinity', () => { const list = [2.234, 5, 381712.0001, -1, -1.38, -0.99, -10282.12312]; expect(list.map((x) => withDecimalPrecision(x, Infinity)))...