#69 : Fix case, update tests

This commit is contained in:
Vadim
2021-09-10 22:17:25 +03:00
parent f03a6d0cbe
commit 8c0a1fbd4c
4 changed files with 30 additions and 27 deletions

View File

@@ -389,6 +389,7 @@
infinite,
particlesCount,
particlesToScroll,
particlesToShow,
clonesCountTail: clonesCount.tail,
}),
options,

View File

@@ -39,6 +39,7 @@ function createStore() {
infinite,
particlesCount,
particlesToScroll,
particlesToShow,
clonesCountTail,
}) {
update(store => {
@@ -46,6 +47,7 @@ function createStore() {
currentParticleIndex: store.currentParticleIndex,
particlesCount,
particlesToScroll,
particlesToShow,
clonesCountTail,
})
return {

View File

@@ -6,12 +6,10 @@ export function getNextParticleIndexLimited({
currentParticleIndex,
particlesCount,
particlesToScroll,
particlesToShow,
}) {
if (particlesCount < 1) throw new Error('particlesCount must be at least 1')
return Math.max(
currentParticleIndex + Math.min(particlesCount - (currentParticleIndex + 1) - particlesToScroll, particlesToScroll),
0
)
return getValueInRange(0, currentParticleIndex + particlesToScroll, particlesCount - particlesToShow)
}
export function getNextParticleIndexInfinte({

View File

@@ -9,21 +9,23 @@ import {
describe('getNextParticleIndexLimited', () => {
it('returns next page index as expected', () => {
const testCases = [
{ currentParticleIndex: -5, particlesCount: 7, particlesToScroll: 2, expected: 0 },
{ currentParticleIndex: 0, particlesCount: 7, particlesToScroll: 2, expected: 2 },
{ currentParticleIndex: 2, particlesCount: 7, particlesToScroll: 2, expected: 4 },
{ currentParticleIndex: 7, particlesCount: 7, particlesToScroll: 2, expected: 4 },
{ currentParticleIndex: -5, particlesCount: 7, particlesToScroll: 2, particlesToShow: 2, expected: 0 },
{ currentParticleIndex: 0, particlesCount: 7, particlesToScroll: 2, particlesToShow: 2, expected: 2 },
{ currentParticleIndex: 2, particlesCount: 7, particlesToScroll: 2, particlesToShow: 2, expected: 4 },
{ currentParticleIndex: 7, particlesCount: 7, particlesToScroll: 2, particlesToShow: 2, expected: 5 },
]
testCases.forEach(({
currentParticleIndex,
particlesCount,
particlesToScroll,
particlesToShow,
expected,
}) => {
expect(getNextParticleIndexLimited({
currentParticleIndex,
particlesCount,
particlesToScroll,
particlesToShow,
})).toBe(expected)
})
})
@@ -133,7 +135,7 @@ describe('getPrevParticleIndexInfinte', () => {
})
it('throws error if particlesCount is less than 1', () => {
const currentParticleIndex = 2
const particlesCount = 7
const particlesCount = 0
const particlesToScroll = 2
expect(
@@ -149,45 +151,45 @@ describe('getPrevParticleIndexInfinte', () => {
describe('getPartialPageSize', () => {
it('returns result as expected if particlesToShow <= particlesToScroll', () => {
const testCases = [{
pagesCountWithoutClones: 9,
particlesCountWithoutClones: 9,
particlesToShow: 2,
particlesToScroll: 3,
expected: 0,
}, {
pagesCountWithoutClones: 15,
particlesCountWithoutClones: 15,
particlesToShow: 4,
particlesToScroll: 5,
expected: 0,
}, {
pagesCountWithoutClones: 16,
particlesCountWithoutClones: 16,
particlesToShow: 4,
particlesToScroll: 5,
expected: 1,
}, {
pagesCountWithoutClones: 17,
particlesCountWithoutClones: 17,
particlesToShow: 4,
particlesToScroll: 5,
expected: 2,
}, {
pagesCountWithoutClones: 18,
particlesCountWithoutClones: 18,
particlesToShow: 4,
particlesToScroll: 5,
expected: 3,
}, {
pagesCountWithoutClones: 8,
particlesCountWithoutClones: 8,
particlesToShow: 2,
particlesToScroll: 2,
expected: 0,
}]
testCases.forEach(({
pagesCountWithoutClones,
particlesCountWithoutClones,
particlesToShow,
particlesToScroll,
expected,
}) => {
expect(getPartialPageSize({
pagesCountWithoutClones,
particlesCountWithoutClones,
particlesToShow,
particlesToScroll,
})).toBe(expected)
@@ -196,55 +198,55 @@ describe('getPartialPageSize', () => {
it('returns result as expected if particlesToShow > particlesToScroll', () => {
const testCases = [{
pagesCountWithoutClones: 8,
particlesCountWithoutClones: 8,
particlesToShow: 4,
particlesToScroll: 2,
expected: 2,
}, {
pagesCountWithoutClones: 7,
particlesCountWithoutClones: 7,
particlesToShow: 4,
particlesToScroll: 3,
expected: 1,
}, {
pagesCountWithoutClones: 8,
particlesCountWithoutClones: 8,
particlesToShow: 4,
particlesToScroll: 3,
expected: 2,
}, {
pagesCountWithoutClones: 8,
particlesCountWithoutClones: 8,
particlesToShow: 2,
particlesToScroll: 2,
expected: 0,
}, {
pagesCountWithoutClones: 9,
particlesCountWithoutClones: 9,
particlesToShow: 4,
particlesToScroll: 3,
expected: 3,
}, {
pagesCountWithoutClones: 8,
particlesCountWithoutClones: 8,
particlesToShow: 3,
particlesToScroll: 2,
expected: 2,
}, {
pagesCountWithoutClones: 6,
particlesCountWithoutClones: 6,
particlesToShow: 3,
particlesToScroll: 1,
expected: 2,
}, {
pagesCountWithoutClones: 7,
particlesCountWithoutClones: 7,
particlesToShow: 3,
particlesToScroll: 1,
expected: 2,
}]
testCases.forEach(({
pagesCountWithoutClones,
particlesCountWithoutClones,
particlesToShow,
particlesToScroll,
expected,
}) => {
expect(getPartialPageSize({
pagesCountWithoutClones,
particlesCountWithoutClones,
particlesToShow,
particlesToScroll,
})).toBe(expected)