diff --git a/app/soapbox/features/timeline-insertion/__tests__/abovefold.test.ts b/app/soapbox/features/timeline-insertion/__tests__/abovefold.test.ts new file mode 100644 index 0000000000..81de8c1a42 --- /dev/null +++ b/app/soapbox/features/timeline-insertion/__tests__/abovefold.test.ts @@ -0,0 +1,18 @@ +import { abovefoldAlgorithm } from '../abovefold'; + +const DATA = Object.freeze(['a', 'b', 'c', 'd']); + +test('abovefoldAlgorithm', () => { + const result = Array(50).fill('').map((_, i) => { + return abovefoldAlgorithm(DATA, i, { seed: '!', range: [2, 6], pageSize: 20 }); + }); + + // console.log(result); + expect(result[0]).toBe(undefined); + expect(result[4]).toBe('a'); + expect(result[5]).toBe(undefined); + expect(result[24]).toBe('b'); + expect(result[30]).toBe(undefined); + expect(result[42]).toBe('c'); + expect(result[43]).toBe(undefined); +}); \ No newline at end of file diff --git a/app/soapbox/features/timeline-insertion/types.ts b/app/soapbox/features/timeline-insertion/types.ts index 69b6280c41..b874754d00 100644 --- a/app/soapbox/features/timeline-insertion/types.ts +++ b/app/soapbox/features/timeline-insertion/types.ts @@ -3,7 +3,7 @@ */ type PickAlgorithm = ( /** Elligible candidates to pick. */ - items: D[], + items: readonly D[], /** Current iteration by which an item may be chosen. */ iteration: number, /** Implementation-specific opts. */