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