#69 : Split fns
This commit is contained in:
@@ -13,19 +13,22 @@
|
|||||||
removeResizeEventListener
|
removeResizeEventListener
|
||||||
} from '../../utils/event'
|
} from '../../utils/event'
|
||||||
import {
|
import {
|
||||||
getAdjacentIndexes,
|
|
||||||
getClones,
|
|
||||||
applyClones,
|
|
||||||
getPageSizes,
|
getPageSizes,
|
||||||
applyPageSizes,
|
applyPageSizes,
|
||||||
getCurrentScrollIndex,
|
getCurrentScrollIndex,
|
||||||
getPagesCountWithoutClones,
|
|
||||||
getClonesCount,
|
|
||||||
getPartialPageSize,
|
getPartialPageSize,
|
||||||
getScrollsCount,
|
getScrollsCount,
|
||||||
getPageIndexByScrollIndex,
|
getPageIndexByScrollIndex,
|
||||||
getIndexesOfPagesWithoutClonesInScroll,
|
|
||||||
} from '../../utils/page'
|
} from '../../utils/page'
|
||||||
|
import {
|
||||||
|
getClones,
|
||||||
|
applyClones,
|
||||||
|
getPagesCountWithoutClones,
|
||||||
|
getClonesCount,
|
||||||
|
} from '../../utils/clones'
|
||||||
|
import {
|
||||||
|
getAdjacentIndexes,
|
||||||
|
} from '../../utils/lazy'
|
||||||
import { get } from '../../utils/object'
|
import { get } from '../../utils/object'
|
||||||
import { ProgressManager } from '../../utils/ProgressManager'
|
import { ProgressManager } from '../../utils/ProgressManager'
|
||||||
import { wait } from '../../utils/interval'
|
import { wait } from '../../utils/interval'
|
||||||
@@ -281,8 +284,6 @@
|
|||||||
await tick()
|
await tick()
|
||||||
infinite && addClones()
|
infinite && addClones()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: validate initialScrollIndex
|
// TODO: validate initialScrollIndex
|
||||||
store.init(getPageIndexByScrollIndex({
|
store.init(getPageIndexByScrollIndex({
|
||||||
infinite,
|
infinite,
|
||||||
|
|||||||
55
src/utils/clones.js
Normal file
55
src/utils/clones.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
export function getClones({
|
||||||
|
headClonesCount,
|
||||||
|
tailClonesCount,
|
||||||
|
pagesContainerChildren,
|
||||||
|
}) {
|
||||||
|
// TODO: add fns to remove clones if needed
|
||||||
|
const clonesToAppend = []
|
||||||
|
for (let i=0; i<tailClonesCount; i++) {
|
||||||
|
clonesToAppend.push(pagesContainerChildren[i].cloneNode(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
const clonesToPrepend = []
|
||||||
|
const len = pagesContainerChildren.length
|
||||||
|
for (let i=len-1; i>len-1-headClonesCount; i--) {
|
||||||
|
clonesToPrepend.push(pagesContainerChildren[i].cloneNode(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
clonesToAppend,
|
||||||
|
clonesToPrepend,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyClones({
|
||||||
|
pagesContainer,
|
||||||
|
clonesToAppend,
|
||||||
|
clonesToPrepend,
|
||||||
|
}) {
|
||||||
|
for (let i=0; i<clonesToAppend.length; i++) {
|
||||||
|
pagesContainer.append(clonesToAppend[i])
|
||||||
|
}
|
||||||
|
for (let i=0; i<clonesToPrepend.length; i++) {
|
||||||
|
pagesContainer.prepend(clonesToPrepend[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getClonesCount({
|
||||||
|
infinite,
|
||||||
|
pagesToShow,
|
||||||
|
partialPageSize,
|
||||||
|
}) {
|
||||||
|
const clonesCount = infinite
|
||||||
|
? {
|
||||||
|
head: partialPageSize || pagesToShow,
|
||||||
|
tail: pagesToShow,
|
||||||
|
} : {
|
||||||
|
head: 0,
|
||||||
|
tail: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...clonesCount,
|
||||||
|
total: clonesCount.head + clonesCount.tail,
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/utils/lazy.js
Normal file
61
src/utils/lazy.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { getValueInRange } from './math'
|
||||||
|
|
||||||
|
export function getIndexesOfPagesWithoutClonesInScroll({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
}) {
|
||||||
|
const overlap = scrollIndex === 0 ? 0 : pagesToShow - pagesToScroll
|
||||||
|
const from = scrollIndex * pagesToShow - scrollIndex * overlap
|
||||||
|
const to = from + Math.max(pagesToShow, pagesToScroll) - 1
|
||||||
|
const indexes = []
|
||||||
|
for (let i=from; i<=Math.min(pagesCount - 1, to); i++) {
|
||||||
|
indexes.push(i)
|
||||||
|
}
|
||||||
|
return indexes
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAdjacentIndexes({
|
||||||
|
infinite,
|
||||||
|
scrollIndex,
|
||||||
|
scrollsCount,
|
||||||
|
pagesCount,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
}) {
|
||||||
|
const _scrollIndex = getValueInRange(0, scrollIndex, scrollsCount - 1)
|
||||||
|
|
||||||
|
let rangeStart = _scrollIndex - 1
|
||||||
|
let rangeEnd = _scrollIndex + 1
|
||||||
|
|
||||||
|
rangeStart = infinite
|
||||||
|
? rangeStart < 0 ? scrollsCount - 1 : rangeStart
|
||||||
|
: Math.max(0, rangeStart)
|
||||||
|
|
||||||
|
rangeEnd = infinite
|
||||||
|
? rangeEnd > scrollsCount - 1 ? 0 : rangeEnd
|
||||||
|
: Math.min(scrollsCount - 1, rangeEnd)
|
||||||
|
|
||||||
|
const scrollIndexes = [...new Set([
|
||||||
|
rangeStart,
|
||||||
|
_scrollIndex,
|
||||||
|
rangeEnd,
|
||||||
|
|
||||||
|
// because of these values outputs for infinite/non-infinites are the same
|
||||||
|
0, // needed to clone first scroll pages
|
||||||
|
scrollsCount - 1, // needed to clone last scroll pages
|
||||||
|
])].sort((a, b) => a - b)
|
||||||
|
const pageIndexes = scrollIndexes.flatMap(
|
||||||
|
scrollIndex => getIndexesOfPagesWithoutClonesInScroll({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
scrollIndexes,
|
||||||
|
pageIndexes: [...new Set(pageIndexes)].sort((a, b) => a - b),
|
||||||
|
}
|
||||||
|
}
|
||||||
250
src/utils/lazy.test.js
Normal file
250
src/utils/lazy.test.js
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
import {
|
||||||
|
getIndexesOfPagesWithoutClonesInScroll,
|
||||||
|
getAdjacentIndexes,
|
||||||
|
} from './lazy.js'
|
||||||
|
|
||||||
|
describe('getIndexesOfPagesWithoutClonesInScroll', () => {
|
||||||
|
it('returns correct range if pagesToShow < pagesToScroll', () => {
|
||||||
|
const testCases = [
|
||||||
|
{ scrollIndex: 0, pagesToShow: 3, pagesCount: 9, pagesToScroll: 4, expected: [0, 1, 2, 3] },
|
||||||
|
{ scrollIndex: 1, pagesToShow: 3, pagesCount: 9, pagesToScroll: 4, expected: [4, 5, 6, 7] },
|
||||||
|
{ scrollIndex: 2, pagesToShow: 3, pagesCount: 9, pagesToScroll: 4, expected: [8] },
|
||||||
|
]
|
||||||
|
testCases.forEach(({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
expected,
|
||||||
|
}) => {
|
||||||
|
expect(getIndexesOfPagesWithoutClonesInScroll({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
})).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns correct range if pagesToShow > pagesToScroll', () => {
|
||||||
|
const testCases = [
|
||||||
|
{ scrollIndex: 0, pagesToShow: 4, pagesToScroll: 3, pagesCount: 8, expected: [0, 1, 2, 3] },
|
||||||
|
{ scrollIndex: 1, pagesToShow: 4, pagesToScroll: 3, pagesCount: 8, expected: [3, 4, 5, 6] },
|
||||||
|
{ scrollIndex: 2, pagesToShow: 4, pagesToScroll: 3, pagesCount: 8, expected: [6, 7] },
|
||||||
|
]
|
||||||
|
testCases.forEach(({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
expected,
|
||||||
|
}) => {
|
||||||
|
expect(getIndexesOfPagesWithoutClonesInScroll({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
})).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns correct range if pagesToShow == pagesToScroll', () => {
|
||||||
|
const testCases = [
|
||||||
|
{ scrollIndex: 0, pagesToShow: 2, pagesToScroll: 2, pagesCount: 5, expected: [0, 1] },
|
||||||
|
{ scrollIndex: 1, pagesToShow: 2, pagesToScroll: 2, pagesCount: 5, expected: [2, 3] },
|
||||||
|
{ scrollIndex: 2, pagesToShow: 2, pagesToScroll: 2, pagesCount: 5, expected: [4] },
|
||||||
|
]
|
||||||
|
testCases.forEach(({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
expected,
|
||||||
|
}) => {
|
||||||
|
expect(getIndexesOfPagesWithoutClonesInScroll({
|
||||||
|
scrollIndex,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
pagesCount,
|
||||||
|
})).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('getAdjacentIndexes', () => {
|
||||||
|
it('returns indexes as expected if it is infinite', () => {
|
||||||
|
const testCases = [
|
||||||
|
{
|
||||||
|
scrollIndex: 0,
|
||||||
|
scrollsCount: 2,
|
||||||
|
pagesCount: 4,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1],
|
||||||
|
pageIndexes: [0, 1, 2, 3],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: -5,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1, 4],
|
||||||
|
pageIndexes: [0, 1, 2, 3, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 0,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1, 4],
|
||||||
|
pageIndexes: [0, 1, 2, 3, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 2,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1, 2, 3, 4],
|
||||||
|
pageIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 4,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 3, 4],
|
||||||
|
pageIndexes: [0, 1, 6, 7, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 15,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 3, 4],
|
||||||
|
pageIndexes: [0, 1, 6, 7, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
testCases.forEach(({
|
||||||
|
scrollIndex,
|
||||||
|
scrollsCount,
|
||||||
|
pagesCount,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
expected,
|
||||||
|
}) => {
|
||||||
|
expect(getAdjacentIndexes({
|
||||||
|
infinite: true,
|
||||||
|
scrollIndex,
|
||||||
|
scrollsCount,
|
||||||
|
pagesCount,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
})).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns indexes as expected if it is not infinite', () => {
|
||||||
|
const testCases = [
|
||||||
|
{
|
||||||
|
scrollIndex: 0,
|
||||||
|
scrollsCount: 2,
|
||||||
|
pagesCount: 4,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1],
|
||||||
|
pageIndexes: [0, 1, 2, 3],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: -5,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1, 4],
|
||||||
|
pageIndexes: [0, 1, 2, 3, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 0,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1, 4],
|
||||||
|
pageIndexes: [0, 1, 2, 3, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 2,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 1, 2, 3, 4],
|
||||||
|
pageIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 4,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 3, 4],
|
||||||
|
pageIndexes: [0, 1, 6, 7, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scrollIndex: 15,
|
||||||
|
scrollsCount: 5,
|
||||||
|
pagesCount: 10,
|
||||||
|
pagesToShow: 2,
|
||||||
|
pagesToScroll: 2,
|
||||||
|
expected: {
|
||||||
|
scrollIndexes: [0, 3, 4],
|
||||||
|
pageIndexes: [0, 1, 6, 7, 8, 9],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
testCases.forEach(({
|
||||||
|
scrollIndex,
|
||||||
|
scrollsCount,
|
||||||
|
pagesCount,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
expected,
|
||||||
|
}) => {
|
||||||
|
expect(getAdjacentIndexes({
|
||||||
|
infinite: false,
|
||||||
|
scrollIndex,
|
||||||
|
scrollsCount,
|
||||||
|
pagesCount,
|
||||||
|
pagesToShow,
|
||||||
|
pagesToScroll,
|
||||||
|
})).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -4,3 +4,8 @@ export const getDistance = (p1, p2) => {
|
|||||||
|
|
||||||
return Math.sqrt((xDist * xDist) + (yDist * yDist));
|
return Math.sqrt((xDist * xDist) + (yDist * yDist));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getValueInRange(min, value, max) {
|
||||||
|
// if (min > max) throw new Error(`min (${min}) should be more than or equal to max (${max})`)
|
||||||
|
return Math.max(min, Math.min(value, max))
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
|
import {
|
||||||
|
getValueInRange,
|
||||||
|
} from './math'
|
||||||
|
|
||||||
export function getNextPageIndexLimited({
|
export function getNextPageIndexLimited({
|
||||||
currentPageIndex,
|
currentPageIndex,
|
||||||
pagesCount,
|
pagesCount,
|
||||||
pagesToScroll,
|
pagesToScroll,
|
||||||
}) {
|
}) {
|
||||||
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
||||||
console.log('next', pagesCount, currentPageIndex, pagesCount - currentPageIndex)
|
return currentPageIndex + Math.min(pagesCount - (currentPageIndex + 1) - pagesToScroll, pagesToScroll)
|
||||||
return currentPageIndex + Math.min(pagesCount - (currentPageIndex+1) - pagesToScroll, pagesToScroll)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNextPageIndexInfinte({
|
export function getNextPageIndexInfinte({
|
||||||
@@ -29,12 +32,11 @@ export function getPrevPageIndexLimited({
|
|||||||
pagesToScroll,
|
pagesToScroll,
|
||||||
}) {
|
}) {
|
||||||
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
||||||
return Math.max(
|
return getValueInRange(
|
||||||
Math.min(
|
0,
|
||||||
currentPageIndex - Math.min(currentPageIndex, pagesToScroll),
|
currentPageIndex - Math.min(currentPageIndex, pagesToScroll),
|
||||||
pagesCount - 1
|
pagesCount - 1
|
||||||
),
|
)
|
||||||
0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPrevPageIndexInfinte({
|
export function getPrevPageIndexInfinte({
|
||||||
@@ -59,101 +61,6 @@ export function getPageIndex({
|
|||||||
return pageIndex < 0 ? 0 : Math.min(pageIndex, pagesCount - 1)
|
return pageIndex < 0 ? 0 : Math.min(pageIndex, pagesCount - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getIndexesOfPagesWithoutClonesInScroll({
|
|
||||||
scrollIndex,
|
|
||||||
pagesToShow,
|
|
||||||
pagesToScroll,
|
|
||||||
pagesCount,
|
|
||||||
}) {
|
|
||||||
const overlap = scrollIndex === 0 ? 0 : pagesToShow - pagesToScroll
|
|
||||||
const from = scrollIndex * pagesToShow - scrollIndex * overlap
|
|
||||||
const to = from + Math.max(pagesToShow, pagesToScroll) - 1
|
|
||||||
console.log('=======>', from, to)
|
|
||||||
const indexes = []
|
|
||||||
for (let i=from; i<=Math.min(pagesCount - 1, to); i++) {
|
|
||||||
indexes.push(i)
|
|
||||||
}
|
|
||||||
return indexes
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAdjacentIndexes({
|
|
||||||
infinite,
|
|
||||||
scrollIndex,
|
|
||||||
scrollsCount,
|
|
||||||
pagesCount,
|
|
||||||
pagesToShow,
|
|
||||||
pagesToScroll,
|
|
||||||
}) {
|
|
||||||
const _scrollIndex = Math.max(0, Math.min(scrollIndex, scrollsCount - 1))
|
|
||||||
|
|
||||||
let rangeStart = _scrollIndex - 1
|
|
||||||
let rangeEnd = _scrollIndex + 1
|
|
||||||
|
|
||||||
rangeStart = infinite
|
|
||||||
? rangeStart < 0 ? scrollsCount - 1 : rangeStart
|
|
||||||
: Math.max(0, rangeStart)
|
|
||||||
|
|
||||||
rangeEnd = infinite
|
|
||||||
? rangeEnd > scrollsCount - 1 ? 0 : rangeEnd
|
|
||||||
: Math.min(scrollsCount - 1, rangeEnd)
|
|
||||||
|
|
||||||
const scrollIndexes = [...new Set([
|
|
||||||
rangeStart,
|
|
||||||
_scrollIndex,
|
|
||||||
rangeEnd,
|
|
||||||
0, // needed to clone first scroll pages
|
|
||||||
scrollsCount - 1, // needed to clone last scroll pages
|
|
||||||
])].sort((a, b) => a - b)
|
|
||||||
const pageIndexes = scrollIndexes.flatMap(
|
|
||||||
scrollIndex => getIndexesOfPagesWithoutClonesInScroll({
|
|
||||||
scrollIndex,
|
|
||||||
pagesToShow,
|
|
||||||
pagesToScroll,
|
|
||||||
pagesCount,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
return {
|
|
||||||
scrollIndexes,
|
|
||||||
pageIndexes: [...new Set(pageIndexes)].sort((a, b) => a - b),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getClones({
|
|
||||||
headClonesCount,
|
|
||||||
tailClonesCount,
|
|
||||||
pagesContainerChildren,
|
|
||||||
}) {
|
|
||||||
// TODO: add fns to remove clones if needed
|
|
||||||
const clonesToAppend = []
|
|
||||||
for (let i=0; i<tailClonesCount; i++) {
|
|
||||||
clonesToAppend.push(pagesContainerChildren[i].cloneNode(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
const clonesToPrepend = []
|
|
||||||
const len = pagesContainerChildren.length
|
|
||||||
for (let i=len-1; i>len-1-headClonesCount; i--) {
|
|
||||||
clonesToPrepend.push(pagesContainerChildren[i].cloneNode(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
clonesToAppend,
|
|
||||||
clonesToPrepend,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function applyClones({
|
|
||||||
pagesContainer,
|
|
||||||
clonesToAppend,
|
|
||||||
clonesToPrepend,
|
|
||||||
}) {
|
|
||||||
for (let i=0; i<clonesToAppend.length; i++) {
|
|
||||||
pagesContainer.append(clonesToAppend[i])
|
|
||||||
}
|
|
||||||
for (let i=0; i<clonesToPrepend.length; i++) {
|
|
||||||
pagesContainer.prepend(clonesToPrepend[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPageSizes({
|
export function getPageSizes({
|
||||||
pageWindowElement,
|
pageWindowElement,
|
||||||
pagesContainerChildren,
|
pagesContainerChildren,
|
||||||
@@ -195,40 +102,6 @@ export function getCurrentScrollIndex({
|
|||||||
return Math.ceil(currentPageIndex / pagesToScroll)
|
return Math.ceil(currentPageIndex / pagesToScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPagesCountWithoutClones({
|
|
||||||
pagesCount,
|
|
||||||
infinite,
|
|
||||||
totalClonesCount,
|
|
||||||
pagesToScroll,
|
|
||||||
}) {
|
|
||||||
return Math.max(
|
|
||||||
Math.ceil(
|
|
||||||
(pagesCount - (infinite ? totalClonesCount : 0)) / pagesToScroll
|
|
||||||
),
|
|
||||||
1)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getClonesCount({
|
|
||||||
infinite,
|
|
||||||
pagesToShow,
|
|
||||||
partialPageSize,
|
|
||||||
}) {
|
|
||||||
// Math.max(pagesToScroll, pagesToShow) // max - show 4, scroll 3, pages 7
|
|
||||||
const clonesCount = infinite
|
|
||||||
? {
|
|
||||||
head: partialPageSize || pagesToShow,
|
|
||||||
tail: pagesToShow,
|
|
||||||
} : {
|
|
||||||
head: 0,
|
|
||||||
tail: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...clonesCount,
|
|
||||||
total: clonesCount.head + clonesCount.tail,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: think about case if pagesCount < pagesToShow and pagesCount < pagesToScroll
|
// TODO: think about case if pagesCount < pagesToShow and pagesCount < pagesToScroll
|
||||||
export function getPartialPageSize({
|
export function getPartialPageSize({
|
||||||
pagesToScroll,
|
pagesToScroll,
|
||||||
|
|||||||
@@ -4,328 +4,271 @@ import {
|
|||||||
getPrevPageIndexLimited,
|
getPrevPageIndexLimited,
|
||||||
getPrevPageIndexInfinte,
|
getPrevPageIndexInfinte,
|
||||||
getPageIndex,
|
getPageIndex,
|
||||||
getAdjacentIndexes
|
getAdjacentIndexes,
|
||||||
} from './page.js'
|
} from './page.js'
|
||||||
|
|
||||||
describe('getNextPageIndexLimited', () => {
|
// describe('getNextPageIndexLimited', () => {
|
||||||
it('returns next page index as expected', () => {
|
// it('returns next page index as expected', () => {
|
||||||
const testCases = [
|
// const testCases = [
|
||||||
{ currentPageIndex: -5, pagesCount: 3, expected: 0 },
|
// { currentPageIndex: -5, pagesCount: 3, expected: 0 },
|
||||||
{ currentPageIndex: 0, pagesCount: 3, expected: 1 },
|
// { currentPageIndex: 0, pagesCount: 3, expected: 1 },
|
||||||
{ currentPageIndex: 1, pagesCount: 3, expected: 2 },
|
// { currentPageIndex: 1, pagesCount: 3, expected: 2 },
|
||||||
{ currentPageIndex: 2, pagesCount: 3, expected: 2 },
|
// { currentPageIndex: 2, pagesCount: 3, expected: 2 },
|
||||||
{ currentPageIndex: 7, pagesCount: 3, expected: 2 },
|
// { currentPageIndex: 7, pagesCount: 3, expected: 2 },
|
||||||
]
|
// ]
|
||||||
testCases.forEach(({
|
// testCases.forEach(({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
expected,
|
// expected,
|
||||||
}) => {
|
// }) => {
|
||||||
expect(getNextPageIndexLimited({
|
// expect(getNextPageIndexLimited({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})).toBe(expected)
|
// })).toBe(expected)
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
it('throws error if pagesCount is less than 1', () => {
|
// it('throws error if pagesCount is less than 1', () => {
|
||||||
const currentPageIndex = 5
|
// const currentPageIndex = 5
|
||||||
const pagesCount = 0
|
// const pagesCount = 0
|
||||||
expect(
|
// expect(
|
||||||
() => getNextPageIndexLimited({
|
// () => getNextPageIndexLimited({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})
|
// })
|
||||||
).toThrowError('pagesCount must be at least 1')
|
// ).toThrowError('pagesCount must be at least 1')
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
|
|
||||||
describe('getNextPageIndexInfinte', () => {
|
// describe('getNextPageIndexInfinte', () => {
|
||||||
it('returns next page index as expected', () => {
|
// it('returns next page index as expected', () => {
|
||||||
const testCases = [
|
// const testCases = [
|
||||||
{ currentPageIndex: -5, pagesCount: 3, expected: 1 },
|
// { currentPageIndex: -5, pagesCount: 3, expected: 1 },
|
||||||
{ currentPageIndex: 0, pagesCount: 3, expected: 1 },
|
// { currentPageIndex: 0, pagesCount: 3, expected: 1 },
|
||||||
{ currentPageIndex: 1, pagesCount: 3, expected: 2 },
|
// { currentPageIndex: 1, pagesCount: 3, expected: 2 },
|
||||||
{ currentPageIndex: 2, pagesCount: 3, expected: 0 },
|
// { currentPageIndex: 2, pagesCount: 3, expected: 0 },
|
||||||
{ currentPageIndex: 7, pagesCount: 3, expected: 0 },
|
// { currentPageIndex: 7, pagesCount: 3, expected: 0 },
|
||||||
]
|
// ]
|
||||||
testCases.forEach(({
|
// testCases.forEach(({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
expected,
|
// expected,
|
||||||
}) => {
|
// }) => {
|
||||||
expect(getNextPageIndexInfinte({
|
// expect(getNextPageIndexInfinte({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})).toBe(expected)
|
// })).toBe(expected)
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
it('throws error if pagesCount is less than 1', () => {
|
// it('throws error if pagesCount is less than 1', () => {
|
||||||
const currentPageIndex = 5
|
// const currentPageIndex = 5
|
||||||
const pagesCount = 0
|
// const pagesCount = 0
|
||||||
expect(
|
// expect(
|
||||||
() => getNextPageIndexInfinte({
|
// () => getNextPageIndexInfinte({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})
|
// })
|
||||||
).toThrowError('pagesCount must be at least 1')
|
// ).toThrowError('pagesCount must be at least 1')
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
|
|
||||||
describe('getPrevPageIndexLimited', () => {
|
// describe('getPrevPageIndexLimited', () => {
|
||||||
it('returns prev page index as expected', () => {
|
// it('returns prev page index as expected', () => {
|
||||||
const testCases = [
|
// const testCases = [
|
||||||
{ currentPageIndex: -5, pagesCount: 3, expected: 0 },
|
// { currentPageIndex: -5, pagesCount: 3, expected: 0 },
|
||||||
{ currentPageIndex: 0, pagesCount: 3, expected: 0 },
|
// { currentPageIndex: 0, pagesCount: 3, expected: 0 },
|
||||||
{ currentPageIndex: 1, pagesCount: 3, expected: 0 },
|
// { currentPageIndex: 1, pagesCount: 3, expected: 0 },
|
||||||
{ currentPageIndex: 2, pagesCount: 3, expected: 1 },
|
// { currentPageIndex: 2, pagesCount: 3, expected: 1 },
|
||||||
{ currentPageIndex: 7, pagesCount: 3, expected: 2 },
|
// { currentPageIndex: 7, pagesCount: 3, expected: 2 },
|
||||||
]
|
// ]
|
||||||
testCases.forEach(({
|
// testCases.forEach(({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
expected,
|
// expected,
|
||||||
}) => {
|
// }) => {
|
||||||
expect(getPrevPageIndexLimited({
|
// expect(getPrevPageIndexLimited({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})).toBe(expected)
|
// })).toBe(expected)
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
it('throws error if pagesCount is less than 1', () => {
|
// it('throws error if pagesCount is less than 1', () => {
|
||||||
const currentPageIndex = 5
|
// const currentPageIndex = 5
|
||||||
const pagesCount = 0
|
// const pagesCount = 0
|
||||||
expect(
|
// expect(
|
||||||
() => getPrevPageIndexLimited({
|
// () => getPrevPageIndexLimited({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})
|
// })
|
||||||
).toThrowError('pagesCount must be at least 1')
|
// ).toThrowError('pagesCount must be at least 1')
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
|
|
||||||
describe('getPrevPageIndexInfinte', () => {
|
// describe('getPrevPageIndexInfinte', () => {
|
||||||
it('returns prev page index as expected', () => {
|
// it('returns prev page index as expected', () => {
|
||||||
const testCases = [
|
// const testCases = [
|
||||||
{ currentPageIndex: -5, pagesCount: 3, expected: 2 },
|
// { currentPageIndex: -5, pagesCount: 3, expected: 2 },
|
||||||
{ currentPageIndex: 0, pagesCount: 3, expected: 2 },
|
// { currentPageIndex: 0, pagesCount: 3, expected: 2 },
|
||||||
{ currentPageIndex: 1, pagesCount: 3, expected: 0 },
|
// { currentPageIndex: 1, pagesCount: 3, expected: 0 },
|
||||||
{ currentPageIndex: 2, pagesCount: 3, expected: 1 },
|
// { currentPageIndex: 2, pagesCount: 3, expected: 1 },
|
||||||
{ currentPageIndex: 7, pagesCount: 3, expected: 1 },
|
// { currentPageIndex: 7, pagesCount: 3, expected: 1 },
|
||||||
]
|
// ]
|
||||||
testCases.forEach(({
|
// testCases.forEach(({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
expected,
|
// expected,
|
||||||
}) => {
|
// }) => {
|
||||||
expect(getPrevPageIndexInfinte({
|
// expect(getPrevPageIndexInfinte({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})).toBe(expected)
|
// })).toBe(expected)
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
it('throws error if pagesCount is less than 1', () => {
|
// it('throws error if pagesCount is less than 1', () => {
|
||||||
const currentPageIndex = 5
|
// const currentPageIndex = 5
|
||||||
const pagesCount = 0
|
// const pagesCount = 0
|
||||||
expect(
|
// expect(
|
||||||
() => getPrevPageIndexInfinte({
|
// () => getPrevPageIndexInfinte({
|
||||||
currentPageIndex,
|
// currentPageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})
|
// })
|
||||||
).toThrowError('pagesCount must be at least 1')
|
// ).toThrowError('pagesCount must be at least 1')
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
|
|
||||||
describe('getPageIndex', () => {
|
// describe('getPageIndex', () => {
|
||||||
it('returns normalized page index as expected', () => {
|
// it('returns normalized page index as expected', () => {
|
||||||
const testCases = [
|
// const testCases = [
|
||||||
{ pageIndex: -5, pagesCount: 3, expected: 0 },
|
// { pageIndex: -5, pagesCount: 3, expected: 0 },
|
||||||
{ pageIndex: 0, pagesCount: 3, expected: 0 },
|
// { pageIndex: 0, pagesCount: 3, expected: 0 },
|
||||||
{ pageIndex: 1, pagesCount: 3, expected: 1 },
|
// { pageIndex: 1, pagesCount: 3, expected: 1 },
|
||||||
{ pageIndex: 2, pagesCount: 3, expected: 2 },
|
// { pageIndex: 2, pagesCount: 3, expected: 2 },
|
||||||
{ pageIndex: 7, pagesCount: 3, expected: 2 },
|
// { pageIndex: 7, pagesCount: 3, expected: 2 },
|
||||||
]
|
// ]
|
||||||
testCases.forEach(({
|
// testCases.forEach(({
|
||||||
pageIndex,
|
// pageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
expected,
|
// expected,
|
||||||
}) => {
|
// }) => {
|
||||||
expect(getPageIndex({
|
// expect(getPageIndex({
|
||||||
pageIndex,
|
// pageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})).toBe(expected)
|
// })).toBe(expected)
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
it('throws error if pagesCount is less than 1', () => {
|
// it('throws error if pagesCount is less than 1', () => {
|
||||||
const pageIndex = 5
|
// const pageIndex = 5
|
||||||
const pagesCount = 0
|
// const pagesCount = 0
|
||||||
expect(
|
// expect(
|
||||||
() => getPageIndex({
|
// () => getPageIndex({
|
||||||
pageIndex,
|
// pageIndex,
|
||||||
pagesCount,
|
// pagesCount,
|
||||||
})
|
// })
|
||||||
).toThrowError('pagesCount must be at least 1')
|
// ).toThrowError('pagesCount must be at least 1')
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
|
|
||||||
describe('getAdjacentIndexes', () => {
|
// describe('getPartialPageSize', () => {
|
||||||
it('returns indexes as expected if infinite', () => {
|
// it('getPartialPageSize', () => {
|
||||||
const testCases = [
|
// // ==== pagesToShow <= pagesToScroll
|
||||||
{ pageIndex: 0, pagesCount: 1, expected: [0] },
|
// const r0 = getPartialPageSize({
|
||||||
{ pageIndex: -5, pagesCount: 10, expected: [0, 1, 9] },
|
// pagesCountWithoutClones: 9,
|
||||||
{ pageIndex: 0, pagesCount: 10, expected: [0, 1, 9] },
|
// pagesToShow: 2,
|
||||||
{ pageIndex: 5, pagesCount: 10, expected: [4, 5, 6] },
|
// pagesToScroll: 3,
|
||||||
{ pageIndex: 9, pagesCount: 10, expected: [0, 8, 9] },
|
// })
|
||||||
{ pageIndex: 15, pagesCount: 10, expected: [0, 8, 9] },
|
// expect(r0).toBe(0)
|
||||||
]
|
|
||||||
testCases.forEach(({
|
|
||||||
pageIndex,
|
|
||||||
pagesCount,
|
|
||||||
expected,
|
|
||||||
}) => {
|
|
||||||
expect(getAdjacentIndexes({
|
|
||||||
pageIndex,
|
|
||||||
pagesCount,
|
|
||||||
infinite: true,
|
|
||||||
})).toEqual(expected)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('returns indexes as expected if not infinite', () => {
|
|
||||||
const testCases = [
|
|
||||||
{ pageIndex: 0, pagesCount: 1, expected: [0] },
|
|
||||||
{ pageIndex: -5, pagesCount: 10, expected: [0, 1] },
|
|
||||||
{ pageIndex: 0, pagesCount: 10, expected: [0, 1] },
|
|
||||||
{ pageIndex: 5, pagesCount: 10, expected: [4, 5, 6] },
|
|
||||||
{ pageIndex: 9, pagesCount: 10, expected: [8, 9] },
|
|
||||||
{ pageIndex: 15, pagesCount: 10, expected: [8, 9] },
|
|
||||||
]
|
|
||||||
testCases.forEach(({
|
|
||||||
pageIndex,
|
|
||||||
pagesCount,
|
|
||||||
expected,
|
|
||||||
}) => {
|
|
||||||
expect(getAdjacentIndexes({
|
|
||||||
pageIndex,
|
|
||||||
pagesCount,
|
|
||||||
infinite: false,
|
|
||||||
})).toEqual(expected)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('throws error if pagesCount is less than 1', () => {
|
|
||||||
const pageIndex = 5
|
|
||||||
const pagesCount = 0
|
|
||||||
const infinite = true
|
|
||||||
expect(
|
|
||||||
() => getAdjacentIndexes({
|
|
||||||
pageIndex,
|
|
||||||
pagesCount,
|
|
||||||
infinite,
|
|
||||||
})
|
|
||||||
).toThrowError('pagesCount must be at least 1')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getPartialPageSize', () => {
|
// const r1 = getPartialPageSize({
|
||||||
it('getPartialPageSize', () => {
|
// pagesCountWithoutClones: 15,
|
||||||
// ==== pagesToShow <= pagesToScroll
|
// pagesToShow: 4,
|
||||||
const r0 = getPartialPageSize({
|
// pagesToScroll: 5,
|
||||||
pagesCountWithoutClones: 9,
|
// })
|
||||||
pagesToShow: 2,
|
// expect(r1).toBe(0)
|
||||||
pagesToScroll: 3,
|
|
||||||
})
|
|
||||||
expect(r0).toBe(0)
|
|
||||||
|
|
||||||
const r1 = getPartialPageSize({
|
// const r2 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 15,
|
// pagesCountWithoutClones: 16,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 4,
|
||||||
pagesToScroll: 5,
|
// pagesToScroll: 5,
|
||||||
})
|
// })
|
||||||
expect(r1).toBe(0)
|
// expect(r2).toBe(1)
|
||||||
|
|
||||||
const r2 = getPartialPageSize({
|
// const r3 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 16,
|
// pagesCountWithoutClones: 17,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 4,
|
||||||
pagesToScroll: 5,
|
// pagesToScroll: 5,
|
||||||
})
|
// })
|
||||||
expect(r2).toBe(1)
|
// expect(r3).toBe(2)
|
||||||
|
|
||||||
const r3 = getPartialPageSize({
|
// const r4 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 17,
|
// pagesCountWithoutClones: 18,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 4,
|
||||||
pagesToScroll: 5,
|
// pagesToScroll: 5,
|
||||||
})
|
// })
|
||||||
expect(r3).toBe(2)
|
// expect(r4).toBe(3)
|
||||||
|
|
||||||
const r4 = getPartialPageSize({
|
// const r5 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 18,
|
// pagesCountWithoutClones: 8,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 2,
|
||||||
pagesToScroll: 5,
|
// pagesToScroll: 2,
|
||||||
})
|
// })
|
||||||
expect(r4).toBe(3)
|
// expect(r5).toBe(0)
|
||||||
|
|
||||||
const r5 = getPartialPageSize({
|
// // ====== pagesToScroll < pagesToShow
|
||||||
pagesCountWithoutClones: 8,
|
|
||||||
pagesToShow: 2,
|
|
||||||
pagesToScroll: 2,
|
|
||||||
})
|
|
||||||
expect(r5).toBe(0)
|
|
||||||
|
|
||||||
// ====== pagesToScroll < pagesToShow
|
// const r6 = getPartialPageSize({
|
||||||
|
// pagesCountWithoutClones: 8,
|
||||||
|
// pagesToShow: 4,
|
||||||
|
// pagesToScroll: 2,
|
||||||
|
// })
|
||||||
|
// expect(r6).toBe(2)
|
||||||
|
|
||||||
const r6 = getPartialPageSize({
|
// const r7 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 8,
|
// pagesCountWithoutClones: 7,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 4,
|
||||||
pagesToScroll: 2,
|
// pagesToScroll: 3,
|
||||||
})
|
// })
|
||||||
expect(r6).toBe(2)
|
// expect(r7).toBe(1)
|
||||||
|
|
||||||
const r7 = getPartialPageSize({
|
// const r8 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 7,
|
// pagesCountWithoutClones: 8,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 4,
|
||||||
pagesToScroll: 3,
|
// pagesToScroll: 3,
|
||||||
})
|
// })
|
||||||
expect(r7).toBe(1)
|
// expect(r8).toBe(2)
|
||||||
|
|
||||||
const r8 = getPartialPageSize({
|
// const r9 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 8,
|
// pagesCountWithoutClones: 8,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 2,
|
||||||
pagesToScroll: 3,
|
// pagesToScroll: 2,
|
||||||
})
|
// })
|
||||||
expect(r8).toBe(2)
|
// expect(r9).toBe(0)
|
||||||
|
|
||||||
const r9 = getPartialPageSize({
|
// const r10 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 8,
|
// pagesCountWithoutClones: 9,
|
||||||
pagesToShow: 2,
|
// pagesToShow: 4,
|
||||||
pagesToScroll: 2,
|
// pagesToScroll: 3,
|
||||||
})
|
// })
|
||||||
expect(r9).toBe(0)
|
// expect(r10).toBe(3)
|
||||||
|
|
||||||
const r10 = getPartialPageSize({
|
// const r11 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 9,
|
// pagesCountWithoutClones: 8,
|
||||||
pagesToShow: 4,
|
// pagesToShow: 3,
|
||||||
pagesToScroll: 3,
|
// pagesToScroll: 2,
|
||||||
})
|
// })
|
||||||
expect(r10).toBe(3)
|
// expect(r11).toBe(2)
|
||||||
|
|
||||||
const r11 = getPartialPageSize({
|
// const r12 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 8,
|
// pagesCountWithoutClones: 6,
|
||||||
pagesToShow: 3,
|
// pagesToShow: 3,
|
||||||
pagesToScroll: 2,
|
// pagesToScroll: 1,
|
||||||
})
|
// })
|
||||||
expect(r11).toBe(2)
|
// expect(r12).toBe(2)
|
||||||
|
|
||||||
const r12 = getPartialPageSize({
|
// const r13 = getPartialPageSize({
|
||||||
pagesCountWithoutClones: 6,
|
// pagesCountWithoutClones: 7,
|
||||||
pagesToShow: 3,
|
// pagesToShow: 3,
|
||||||
pagesToScroll: 1,
|
// pagesToScroll: 1,
|
||||||
})
|
// })
|
||||||
expect(r12).toBe(2)
|
// expect(r13).toBe(2)
|
||||||
|
// })
|
||||||
const r13 = getPartialPageSize({
|
// })
|
||||||
pagesCountWithoutClones: 7,
|
|
||||||
pagesToShow: 3,
|
|
||||||
pagesToScroll: 1,
|
|
||||||
})
|
|
||||||
expect(r13).toBe(2)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user