#69 : Fix unit tests
This commit is contained in:
@@ -8,7 +8,10 @@ export function getNextParticleIndexLimited({
|
|||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
}) {
|
}) {
|
||||||
if (particlesCount < 1) throw new Error('particlesCount must be at least 1')
|
if (particlesCount < 1) throw new Error('particlesCount must be at least 1')
|
||||||
return currentParticleIndex + Math.min(particlesCount - (currentParticleIndex + 1) - particlesToScroll, particlesToScroll)
|
return Math.max(
|
||||||
|
currentParticleIndex + Math.min(particlesCount - (currentParticleIndex + 1) - particlesToScroll, particlesToScroll),
|
||||||
|
0
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNextParticleIndexInfinte({
|
export function getNextParticleIndexInfinte({
|
||||||
|
|||||||
@@ -7,182 +7,188 @@ import {
|
|||||||
getPartialPageSize,
|
getPartialPageSize,
|
||||||
} from './page.js'
|
} from './page.js'
|
||||||
|
|
||||||
// describe('getNextParticleIndexLimited', () => {
|
describe('getNextParticleIndexLimited', () => {
|
||||||
// it('returns next page index as expected', () => {
|
it('returns next page index as expected', () => {
|
||||||
// const testCases = [
|
const testCases = [
|
||||||
// { currentParticleIndex: -5, particlesCount: 3, particlesToScroll: 1, expected: 0 },
|
{ currentParticleIndex: -5, particlesCount: 7, particlesToScroll: 2, expected: 0 },
|
||||||
// { currentParticleIndex: 0, particlesCount: 3, particlesToScroll: 1, expected: 1 },
|
{ currentParticleIndex: 0, particlesCount: 7, particlesToScroll: 2, expected: 2 },
|
||||||
// { currentParticleIndex: 1, particlesCount: 3, particlesToScroll: 1, expected: 2 },
|
{ currentParticleIndex: 2, particlesCount: 7, particlesToScroll: 2, expected: 4 },
|
||||||
// { currentParticleIndex: 2, particlesCount: 3, particlesToScroll: 1, expected: 2 },
|
{ currentParticleIndex: 7, particlesCount: 7, particlesToScroll: 2, expected: 4 },
|
||||||
// { currentParticleIndex: 7, particlesCount: 3, particlesToScroll: 1, expected: 2 },
|
]
|
||||||
// ]
|
testCases.forEach(({
|
||||||
// testCases.forEach(({
|
currentParticleIndex,
|
||||||
// currentParticleIndex,
|
particlesCount,
|
||||||
// particlesCount,
|
particlesToScroll,
|
||||||
// particlesToScroll,
|
expected,
|
||||||
// expected,
|
}) => {
|
||||||
// }) => {
|
expect(getNextParticleIndexLimited({
|
||||||
// expect(getNextParticleIndexLimited({
|
currentParticleIndex,
|
||||||
// currentParticleIndex,
|
particlesCount,
|
||||||
// particlesCount,
|
particlesToScroll,
|
||||||
// particlesToScroll,
|
})).toBe(expected)
|
||||||
// })).toBe(expected)
|
})
|
||||||
// })
|
})
|
||||||
// })
|
it('throws error if particlesCount is less than 1', () => {
|
||||||
// it('throws error if particlesCount is less than 1', () => {
|
const currentParticleIndex = 5
|
||||||
// const currentParticleIndex = 5
|
const particlesCount = 0
|
||||||
// const particlesCount = 0
|
const particlesToScroll = 1
|
||||||
// const particlesToScroll = 1
|
expect(
|
||||||
// expect(
|
() => getNextParticleIndexLimited({
|
||||||
// () => getNextParticleIndexLimited({
|
currentParticleIndex,
|
||||||
// currentParticleIndex,
|
particlesCount,
|
||||||
// particlesCount,
|
particlesToScroll,
|
||||||
// particlesToScroll,
|
})
|
||||||
// })
|
).toThrowError('particlesCount must be at least 1')
|
||||||
// ).toThrowError('particlesCount must be at least 1')
|
})
|
||||||
// })
|
})
|
||||||
// })
|
|
||||||
|
|
||||||
// describe('getNextParticleIndexInfinte', () => {
|
describe('getNextParticleIndexInfinte', () => {
|
||||||
// it('returns next page index as expected', () => {
|
it('returns next page index as expected', () => {
|
||||||
// const testCases = [
|
const testCases = [
|
||||||
// { currentParticleIndex: -5, particlesCount: 3, expected: 1 },
|
{ currentParticleIndex: -5, particlesCount: 7, particlesToScroll: 2, clonesCountTail: 3, expected: 2 },
|
||||||
// { currentParticleIndex: 0, particlesCount: 3, expected: 1 },
|
{ currentParticleIndex: 0, particlesCount: 7, particlesToScroll: 2, clonesCountTail: 3, expected: 2 },
|
||||||
// { currentParticleIndex: 1, particlesCount: 3, expected: 2 },
|
{ currentParticleIndex: 2, particlesCount: 7, particlesToScroll: 2, clonesCountTail: 3, expected: 4 },
|
||||||
// { currentParticleIndex: 2, particlesCount: 3, expected: 0 },
|
{ currentParticleIndex: 7, particlesCount: 7, particlesToScroll: 2, clonesCountTail: 3, expected: 4 },
|
||||||
// { currentParticleIndex: 7, particlesCount: 3, expected: 0 },
|
]
|
||||||
// ]
|
testCases.forEach(({
|
||||||
// testCases.forEach(({
|
currentParticleIndex,
|
||||||
// currentParticleIndex,
|
particlesCount,
|
||||||
// particlesCount,
|
particlesToScroll,
|
||||||
// expected,
|
clonesCountTail,
|
||||||
// }) => {
|
expected,
|
||||||
// expect(getNextParticleIndexInfinte({
|
}) => {
|
||||||
// currentParticleIndex,
|
expect(getNextParticleIndexInfinte({
|
||||||
// particlesCount,
|
currentParticleIndex,
|
||||||
// })).toBe(expected)
|
particlesCount,
|
||||||
// })
|
particlesToScroll,
|
||||||
// })
|
clonesCountTail,
|
||||||
// it('throws error if particlesCount is less than 1', () => {
|
})).toBe(expected)
|
||||||
// const currentParticleIndex = 5
|
})
|
||||||
// const particlesCount = 0
|
})
|
||||||
// expect(
|
it('throws error if particlesCount is less than 1', () => {
|
||||||
// () => getNextParticleIndexInfinte({
|
const currentParticleIndex = 5
|
||||||
// currentParticleIndex,
|
const particlesCount = 0
|
||||||
// particlesCount,
|
expect(
|
||||||
// })
|
() => getNextParticleIndexInfinte({
|
||||||
// ).toThrowError('particlesCount must be at least 1')
|
currentParticleIndex,
|
||||||
// })
|
particlesCount,
|
||||||
// })
|
})
|
||||||
|
).toThrowError('particlesCount must be at least 1')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// describe('getPrevParticleIndexLimited', () => {
|
describe('getPrevParticleIndexLimited', () => {
|
||||||
// it('returns prev page index as expected', () => {
|
it('returns prev page index as expected', () => {
|
||||||
// const testCases = [
|
const testCases = [
|
||||||
// { currentParticleIndex: -5, particlesCount: 3, expected: 0 },
|
{ currentParticleIndex: -5, particlesCount: 7, particlesToScroll: 2, expected: 0 },
|
||||||
// { currentParticleIndex: 0, particlesCount: 3, expected: 0 },
|
{ currentParticleIndex: 0, particlesCount: 7, particlesToScroll: 2, expected: 0 },
|
||||||
// { currentParticleIndex: 1, particlesCount: 3, expected: 0 },
|
{ currentParticleIndex: 2, particlesCount: 7, particlesToScroll: 2, expected: 0 },
|
||||||
// { currentParticleIndex: 2, particlesCount: 3, expected: 1 },
|
{ currentParticleIndex: 4, particlesCount: 7, particlesToScroll: 2, expected: 2 },
|
||||||
// { currentParticleIndex: 7, particlesCount: 3, expected: 2 },
|
{ currentParticleIndex: 10, particlesCount: 7, particlesToScroll: 2, expected: 6 },
|
||||||
// ]
|
]
|
||||||
// testCases.forEach(({
|
testCases.forEach(({
|
||||||
// currentParticleIndex,
|
currentParticleIndex,
|
||||||
// particlesCount,
|
particlesCount,
|
||||||
// expected,
|
particlesToScroll,
|
||||||
// }) => {
|
expected,
|
||||||
// expect(getPrevParticleIndexLimited({
|
}) => {
|
||||||
// currentParticleIndex,
|
expect(getPrevParticleIndexLimited({
|
||||||
// particlesCount,
|
currentParticleIndex,
|
||||||
// })).toBe(expected)
|
particlesCount,
|
||||||
// })
|
particlesToScroll,
|
||||||
// })
|
})).toBe(expected)
|
||||||
// it('throws error if particlesCount is less than 1', () => {
|
})
|
||||||
// const currentParticleIndex = 5
|
})
|
||||||
// const particlesCount = 0
|
it('throws error if particlesCount is less than 1', () => {
|
||||||
// expect(
|
const currentParticleIndex = 5
|
||||||
// () => getPrevParticleIndexLimited({
|
const particlesCount = 0
|
||||||
// currentParticleIndex,
|
expect(
|
||||||
// particlesCount,
|
() => getPrevParticleIndexLimited({
|
||||||
// })
|
currentParticleIndex,
|
||||||
// ).toThrowError('particlesCount must be at least 1')
|
particlesCount,
|
||||||
// })
|
})
|
||||||
// })
|
).toThrowError('particlesCount must be at least 1')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// describe('getPrevParticleIndexInfinte', () => {
|
describe('getPrevParticleIndexInfinte', () => {
|
||||||
// it('returns prev page index as expected', () => {
|
it('returns prev page index as expected', () => {
|
||||||
// const testCases = [
|
const testCases = [
|
||||||
// { currentParticleIndex: -5, particlesCount: 3, expected: 2 },
|
{ currentParticleIndex: -5, particlesCount: 7, particlesToScroll: 2, expected: 0 },
|
||||||
// { currentParticleIndex: 0, particlesCount: 3, expected: 2 },
|
{ currentParticleIndex: 2, particlesCount: 7, particlesToScroll: 2, expected: 0 },
|
||||||
// { currentParticleIndex: 1, particlesCount: 3, expected: 0 },
|
{ currentParticleIndex: 2, particlesCount: 7, particlesToScroll: 2, expected: 0 },
|
||||||
// { currentParticleIndex: 2, particlesCount: 3, expected: 1 },
|
{ currentParticleIndex: 10, particlesCount: 7, particlesToScroll: 2, expected: 4 },
|
||||||
// { currentParticleIndex: 7, particlesCount: 3, expected: 1 },
|
]
|
||||||
// ]
|
testCases.forEach(({
|
||||||
// testCases.forEach(({
|
currentParticleIndex,
|
||||||
// currentParticleIndex,
|
particlesCount,
|
||||||
// particlesCount,
|
particlesToScroll,
|
||||||
// expected,
|
expected,
|
||||||
// }) => {
|
}) => {
|
||||||
// expect(getPrevParticleIndexInfinte({
|
expect(getPrevParticleIndexInfinte({
|
||||||
// currentParticleIndex,
|
currentParticleIndex,
|
||||||
// particlesCount,
|
particlesCount,
|
||||||
// })).toBe(expected)
|
particlesToScroll,
|
||||||
// })
|
})).toBe(expected)
|
||||||
// })
|
})
|
||||||
// it('throws error if particlesCount is less than 1', () => {
|
})
|
||||||
// const currentParticleIndex = 5
|
it('throws error if particlesCount is less than 1', () => {
|
||||||
// const particlesCount = 0
|
const currentParticleIndex = 2
|
||||||
// expect(
|
const particlesCount = 7
|
||||||
// () => getPrevParticleIndexInfinte({
|
const particlesToScroll = 2
|
||||||
// currentParticleIndex,
|
|
||||||
// particlesCount,
|
expect(
|
||||||
// })
|
() => getPrevParticleIndexInfinte({
|
||||||
// ).toThrowError('particlesCount must be at least 1')
|
currentParticleIndex,
|
||||||
// })
|
particlesCount,
|
||||||
// })
|
particlesToScroll,
|
||||||
|
})
|
||||||
|
).toThrowError('particlesCount must be at least 1')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('getPartialPageSize', () => {
|
describe('getPartialPageSize', () => {
|
||||||
it('returns result as expected if particlesToShow <= particlesToScroll', () => {
|
it('returns result as expected if particlesToShow <= particlesToScroll', () => {
|
||||||
const testCases = [
|
const testCases = [{
|
||||||
{
|
pagesCountWithoutClones: 9,
|
||||||
particlesCountWithoutClones: 9,
|
particlesToShow: 2,
|
||||||
particlesToShow: 2,
|
particlesToScroll: 3,
|
||||||
particlesToScroll: 3,
|
expected: 0,
|
||||||
expected: 0,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 15,
|
||||||
particlesCountWithoutClones: 15,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 5,
|
||||||
particlesToScroll: 5,
|
expected: 0,
|
||||||
expected: 0,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 16,
|
||||||
particlesCountWithoutClones: 16,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 5,
|
||||||
particlesToScroll: 5,
|
expected: 1,
|
||||||
expected: 1,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 17,
|
||||||
particlesCountWithoutClones: 17,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 5,
|
||||||
particlesToScroll: 5,
|
expected: 2,
|
||||||
expected: 2,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 18,
|
||||||
particlesCountWithoutClones: 18,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 5,
|
||||||
particlesToScroll: 5,
|
expected: 3,
|
||||||
expected: 3,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 8,
|
||||||
particlesCountWithoutClones: 8,
|
particlesToShow: 2,
|
||||||
particlesToShow: 2,
|
particlesToScroll: 2,
|
||||||
particlesToScroll: 2,
|
expected: 0,
|
||||||
expected: 0,
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
testCases.forEach(({
|
testCases.forEach(({
|
||||||
particlesCountWithoutClones,
|
pagesCountWithoutClones,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
expected,
|
expected,
|
||||||
}) => {
|
}) => {
|
||||||
expect(getPartialPageSize({
|
expect(getPartialPageSize({
|
||||||
particlesCountWithoutClones,
|
pagesCountWithoutClones,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
})).toBe(expected)
|
})).toBe(expected)
|
||||||
@@ -190,58 +196,56 @@ describe('getPartialPageSize', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns result as expected if particlesToShow > particlesToScroll', () => {
|
it('returns result as expected if particlesToShow > particlesToScroll', () => {
|
||||||
const testCases = [
|
const testCases = [{
|
||||||
{
|
pagesCountWithoutClones: 8,
|
||||||
particlesCountWithoutClones: 8,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 2,
|
||||||
particlesToScroll: 2,
|
expected: 2,
|
||||||
expected: 2,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 7,
|
||||||
particlesCountWithoutClones: 7,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 3,
|
||||||
particlesToScroll: 3,
|
expected: 1,
|
||||||
expected: 1,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 8,
|
||||||
particlesCountWithoutClones: 8,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 3,
|
||||||
particlesToScroll: 3,
|
expected: 2,
|
||||||
expected: 2,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 8,
|
||||||
particlesCountWithoutClones: 8,
|
particlesToShow: 2,
|
||||||
particlesToShow: 2,
|
particlesToScroll: 2,
|
||||||
particlesToScroll: 2,
|
expected: 0,
|
||||||
expected: 0,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 9,
|
||||||
particlesCountWithoutClones: 9,
|
particlesToShow: 4,
|
||||||
particlesToShow: 4,
|
particlesToScroll: 3,
|
||||||
particlesToScroll: 3,
|
expected: 3,
|
||||||
expected: 3,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 8,
|
||||||
particlesCountWithoutClones: 8,
|
particlesToShow: 3,
|
||||||
particlesToShow: 3,
|
particlesToScroll: 2,
|
||||||
particlesToScroll: 2,
|
expected: 2,
|
||||||
expected: 2,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 6,
|
||||||
particlesCountWithoutClones: 6,
|
particlesToShow: 3,
|
||||||
particlesToShow: 3,
|
particlesToScroll: 1,
|
||||||
particlesToScroll: 1,
|
expected: 2,
|
||||||
expected: 2,
|
}, {
|
||||||
}, {
|
pagesCountWithoutClones: 7,
|
||||||
particlesCountWithoutClones: 7,
|
particlesToShow: 3,
|
||||||
particlesToShow: 3,
|
particlesToScroll: 1,
|
||||||
particlesToScroll: 1,
|
expected: 2,
|
||||||
expected: 2,
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
testCases.forEach(({
|
testCases.forEach(({
|
||||||
particlesCountWithoutClones,
|
pagesCountWithoutClones,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
expected,
|
expected,
|
||||||
}) => {
|
}) => {
|
||||||
expect(getPartialPageSize({
|
expect(getPartialPageSize({
|
||||||
particlesCountWithoutClones,
|
pagesCountWithoutClones,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
})).toBe(expected)
|
})).toBe(expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user