From c121f91693cca49336d3ed78da2a000fe335438a Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 13 Sep 2021 21:31:32 +0300 Subject: [PATCH] #69 : Add unit tests --- src/utils/page.test.js | 76 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) 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) + }) + }) +})