diff --git a/src/utils/page.test.js b/src/utils/page.test.js index a6cce2d..d6fdc44 100644 --- a/src/utils/page.test.js +++ b/src/utils/page.test.js @@ -1,5 +1,4 @@ import { - getPartialPageSize, getPartialPageSize, _getCurrentPageIndexByCurrentParticleIndexInfinite, _getCurrentPageIndexByCurrentParticleIndexLimited, @@ -291,3 +290,78 @@ describe('_getCurrentPageIndexByCurrentParticleIndexInfinite', () => { }) }) }) + +describe('_getCurrentPageIndexByCurrentParticleIndexLimited particlesCount: 5', () => { + it('returns result as expected if particlesToScroll: 2 (particlesToShow: 2)', () => { + const testCases = [{ + currentParticleIndex: 0, + particlesToScroll: 2, + expected: 0, + }, { + currentParticleIndex: 2, + particlesToScroll: 2, + expected: 1, + }, { + currentParticleIndex: 4, + particlesToScroll: 2, + expected: 2, + }] + + testCases.forEach(({ + currentParticleIndex, + particlesToScroll, + expected, + }) => { + expect(_getCurrentPageIndexByCurrentParticleIndexLimited({ + currentParticleIndex, + particlesToScroll, + })).toBe(expected) + }) + }) + + it('returns result as expected if particlesToScroll: 2 (particlesToShow: 3)', () => { + const testCases = [{ + currentParticleIndex: 0, + particlesToScroll: 2, + expected: 0, + }, { + currentParticleIndex: 2, + particlesToScroll: 2, + expected: 1, + }] + + testCases.forEach(({ + currentParticleIndex, + particlesToScroll, + expected, + }) => { + expect(_getCurrentPageIndexByCurrentParticleIndexLimited({ + currentParticleIndex, + particlesToScroll, + })).toBe(expected) + }) + }) + + it('returns result as expected if particlesToScroll: 3 (particlesToShow: 2)', () => { + const testCases = [{ + currentParticleIndex: 0, + particlesToScroll: 3, + expected: 0, + }, { + currentParticleIndex: 3, + particlesToScroll: 3, + expected: 1, + }] + + testCases.forEach(({ + currentParticleIndex, + particlesToScroll, + expected, + }) => { + expect(_getCurrentPageIndexByCurrentParticleIndexLimited({ + currentParticleIndex, + particlesToScroll, + })).toBe(expected) + }) + }) +})