mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 09:51:37 +00:00
fix: preserve keyset totals when count is skipped
This commit is contained in:
parent
23dfde8d34
commit
9a6591fa59
2 changed files with 42 additions and 1 deletions
|
|
@ -350,7 +350,10 @@ export default {
|
||||||
this.pageCursors = { 0: null }
|
this.pageCursors = { 0: null }
|
||||||
},
|
},
|
||||||
updateVisibleBrowseRange(totalEntities = this.serverTotalEntities) {
|
updateVisibleBrowseRange(totalEntities = this.serverTotalEntities) {
|
||||||
this.serverTotalEntities = Number(totalEntities) || 0
|
const hasExplicitTotal = totalEntities !== null && totalEntities !== undefined
|
||||||
|
if (hasExplicitTotal) {
|
||||||
|
this.serverTotalEntities = Number(totalEntities) || 0
|
||||||
|
}
|
||||||
|
|
||||||
const visibleTotalEntities = this.deepScrollBlocked
|
const visibleTotalEntities = this.deepScrollBlocked
|
||||||
? Math.min(this.serverTotalEntities, this.maxOffsetPages * this.booksPerFetch)
|
? Math.min(this.serverTotalEntities, this.maxOffsetPages * this.booksPerFetch)
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,44 @@ describe('LazyBookshelf', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('preserves visible totals when keyset follow-up responses omit total', () => {
|
||||||
|
const requestUrls = []
|
||||||
|
const getStub = cy.stub().callsFake((url) => {
|
||||||
|
requestUrls.push(url)
|
||||||
|
|
||||||
|
if (requestUrls.length === 1) {
|
||||||
|
return Promise.resolve({
|
||||||
|
results: [{ id: 'item-1', mediaType: 'book', media: { metadata: { title: 'Alpha' } } }],
|
||||||
|
total: 4,
|
||||||
|
nextCursor: 'cursor-1',
|
||||||
|
paginationMode: 'keyset',
|
||||||
|
isCountDeferred: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve({
|
||||||
|
results: [{ id: 'item-2', mediaType: 'book', media: { metadata: { title: 'Beta' } } }],
|
||||||
|
total: null,
|
||||||
|
nextCursor: null,
|
||||||
|
paginationMode: 'keyset',
|
||||||
|
isCountDeferred: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
mountBookshelf(getStub, { initialPagesToLoad: 1 }).then(({ wrapper }) => {
|
||||||
|
cy.wrap(null)
|
||||||
|
.then(() => wrapper.vm.loadPage(1))
|
||||||
|
.then(() => {
|
||||||
|
expect(wrapper.vm.serverTotalEntities).to.equal(4)
|
||||||
|
expect(wrapper.vm.totalEntities).to.equal(4)
|
||||||
|
expect(wrapper.vm.totalShelves).to.equal(4)
|
||||||
|
expect(wrapper.vm.entities).to.have.length(4)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('[id^="shelf-"]').should('have.length', 4)
|
||||||
|
})
|
||||||
|
|
||||||
it('keeps offset fallback mode explicit and caps deep endless scroll', () => {
|
it('keeps offset fallback mode explicit and caps deep endless scroll', () => {
|
||||||
const requestUrls = []
|
const requestUrls = []
|
||||||
const getStub = cy.stub().callsFake((url) => {
|
const getStub = cy.stub().callsFake((url) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue