diff --git a/app/soapbox/features/timeline-insertion/__tests__/linear.test.ts b/app/soapbox/features/timeline-insertion/__tests__/linear.test.ts new file mode 100644 index 000000000..09d484f12 --- /dev/null +++ b/app/soapbox/features/timeline-insertion/__tests__/linear.test.ts @@ -0,0 +1,19 @@ +import { linearAlgorithm } from '../linear'; + +const DATA = Object.freeze(['a', 'b', 'c', 'd']); + +test('linearAlgorithm', () => { + const result = Array(50).fill('').map((_, i) => { + return linearAlgorithm(DATA, i, { interval: 5 }); + }); + + // console.log(result); + expect(result[0]).toBe(undefined); + expect(result[4]).toBe('a'); + expect(result[8]).toBe(undefined); + expect(result[9]).toBe('b'); + expect(result[10]).toBe(undefined); + expect(result[14]).toBe('c'); + expect(result[15]).toBe(undefined); + expect(result[19]).toBe('d'); +}); \ No newline at end of file diff --git a/app/soapbox/features/timeline-insertion/linear.ts b/app/soapbox/features/timeline-insertion/linear.ts index a3cbce685..a542e1fce 100644 --- a/app/soapbox/features/timeline-insertion/linear.ts +++ b/app/soapbox/features/timeline-insertion/linear.ts @@ -8,7 +8,7 @@ type Opts = { /** Picks the next item every iteration. */ const linearAlgorithm: PickAlgorithm = (items, iteration, rawOpts) => { const opts = normalizeOpts(rawOpts); - const itemIndex = items ? Math.floor((iteration + 1) / opts.interval) % items.length : 0; + const itemIndex = items ? Math.floor(iteration / opts.interval) % items.length : 0; const item = items ? items[itemIndex] : undefined; const showItem = (iteration + 1) % opts.interval === 0;