Fix pages count
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
/**
|
||||
* Infinite looping
|
||||
*/
|
||||
export let infinite
|
||||
export let infinite = false
|
||||
$: {
|
||||
data.infinite = infinite
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ function createCarousel(onChange) {
|
||||
infinite: data.infinite,
|
||||
particlesCountWithoutClones: data.particlesCountWithoutClones,
|
||||
particlesToScroll: data.particlesToScroll,
|
||||
particlesToShow: data.particlesToShow,
|
||||
})
|
||||
},
|
||||
setParticlesToShow({ data }) {
|
||||
|
||||
@@ -60,14 +60,21 @@ export function _getPagesCountByParticlesCountInfinite({
|
||||
export function _getPagesCountByParticlesCountLimited({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
}) {
|
||||
return Math.round(particlesCountWithoutClones / particlesToScroll)
|
||||
const partialPageSize = getPartialPageSize({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
})
|
||||
return Math.ceil(particlesCountWithoutClones / particlesToScroll) - partialPageSize
|
||||
}
|
||||
|
||||
export function getPagesCountByParticlesCount({
|
||||
infinite,
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
}) {
|
||||
return infinite
|
||||
? _getPagesCountByParticlesCountInfinite({
|
||||
@@ -77,6 +84,7 @@ export function getPagesCountByParticlesCount({
|
||||
: _getPagesCountByParticlesCountLimited({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -435,17 +435,42 @@ describe('_getPagesCountByParticlesCountLimited', () => {
|
||||
const testCases = [{
|
||||
particlesCountWithoutClones: 5,
|
||||
particlesToScroll: 2,
|
||||
expected: 3,
|
||||
particlesToShow: 3,
|
||||
expected: 2,
|
||||
}]
|
||||
|
||||
testCases.forEach(({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
expected,
|
||||
}) => {
|
||||
expect(_getPagesCountByParticlesCountLimited({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
})).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
it('returns result as expected if particlesCountWithoutClones: 9; particlesToScroll: 2 (particlesToShow: 3)', () => {
|
||||
const testCases = [{
|
||||
particlesCountWithoutClones: 9,
|
||||
particlesToScroll: 2,
|
||||
particlesToShow: 3,
|
||||
expected: 4,
|
||||
}]
|
||||
|
||||
testCases.forEach(({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
expected,
|
||||
}) => {
|
||||
expect(_getPagesCountByParticlesCountLimited({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
})).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -454,17 +479,20 @@ describe('_getPagesCountByParticlesCountLimited', () => {
|
||||
const testCases = [{
|
||||
particlesCountWithoutClones: 6,
|
||||
particlesToScroll: 2,
|
||||
particlesToShow: 2,
|
||||
expected: 3,
|
||||
}]
|
||||
|
||||
testCases.forEach(({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
expected,
|
||||
}) => {
|
||||
expect(_getPagesCountByParticlesCountLimited({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
})).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -473,17 +501,20 @@ describe('_getPagesCountByParticlesCountLimited', () => {
|
||||
const testCases = [{
|
||||
particlesCountWithoutClones: 5,
|
||||
particlesToScroll: 3,
|
||||
particlesToShow: 2,
|
||||
expected: 2,
|
||||
}]
|
||||
|
||||
testCases.forEach(({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
expected,
|
||||
}) => {
|
||||
expect(_getPagesCountByParticlesCountLimited({
|
||||
particlesCountWithoutClones,
|
||||
particlesToScroll,
|
||||
particlesToShow,
|
||||
})).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user