mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-08 10:21:38 +00:00
fix: align large-library browse strategy keys
This commit is contained in:
parent
1533d4146a
commit
8585cfff6b
2 changed files with 113 additions and 16 deletions
|
|
@ -4,7 +4,13 @@ const expect = chai.expect
|
|||
const { getLibraryBrowseStrategy } = require('../../../server/utils/queries/libraryBrowseStrategy')
|
||||
|
||||
describe('libraryBrowseStrategy', () => {
|
||||
afterEach(() => {
|
||||
delete global.ServerSettings
|
||||
})
|
||||
|
||||
it('uses keyset pagination for title browse', () => {
|
||||
global.ServerSettings = { sortingIgnorePrefix: true }
|
||||
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
sortBy: 'media.metadata.title',
|
||||
|
|
@ -19,6 +25,20 @@ describe('libraryBrowseStrategy', () => {
|
|||
expect(strategy.cursorKeys).to.deep.equal(['titleIgnorePrefix', 'id'])
|
||||
})
|
||||
|
||||
it('uses raw title cursor keys when prefix ignoring is disabled', () => {
|
||||
global.ServerSettings = { sortingIgnorePrefix: false }
|
||||
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
sortBy: 'media.metadata.title',
|
||||
filterGroup: null,
|
||||
pageMode: 'endless'
|
||||
})
|
||||
|
||||
expect(strategy.paginationMode).to.equal('keyset')
|
||||
expect(strategy.cursorKeys).to.deep.equal(['title', 'id'])
|
||||
})
|
||||
|
||||
it('falls back to offset for random sort', () => {
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
|
|
@ -41,6 +61,7 @@ describe('libraryBrowseStrategy', () => {
|
|||
|
||||
expect(strategy.family).to.equal('recent-browse')
|
||||
expect(strategy.paginationMode).to.equal('keyset')
|
||||
expect(strategy.cursorKeys).to.deep.equal(['createdAt', 'id'])
|
||||
})
|
||||
|
||||
it('uses keyset pagination for progress browse', () => {
|
||||
|
|
@ -53,6 +74,7 @@ describe('libraryBrowseStrategy', () => {
|
|||
|
||||
expect(strategy.family).to.equal('progress-browse')
|
||||
expect(strategy.paginationMode).to.equal('keyset')
|
||||
expect(strategy.cursorKeys).to.deep.equal(['mediaProgresses.updatedAt', 'id'])
|
||||
})
|
||||
|
||||
it('uses keyset pagination for updated browse', () => {
|
||||
|
|
@ -64,11 +86,13 @@ describe('libraryBrowseStrategy', () => {
|
|||
})
|
||||
|
||||
expect(strategy.family).to.equal('plain-browse')
|
||||
expect(strategy.paginationMode).to.equal('keyset')
|
||||
expect(strategy.cursorKeys).to.deep.equal(['updatedAt', 'id'])
|
||||
expect(strategy.paginationMode).to.equal('offset')
|
||||
expect(strategy.cursorKeys).to.deep.equal([])
|
||||
})
|
||||
|
||||
it('uses keyset pagination for deterministic author browse', () => {
|
||||
global.ServerSettings = { sortingIgnorePrefix: true }
|
||||
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
sortBy: 'media.metadata.authorName',
|
||||
|
|
@ -81,6 +105,47 @@ describe('libraryBrowseStrategy', () => {
|
|||
expect(strategy.cursorKeys).to.deep.equal(['authorNamesFirstLast', 'titleIgnorePrefix', 'id'])
|
||||
})
|
||||
|
||||
it('uses keyset pagination for deterministic author last-first browse', () => {
|
||||
global.ServerSettings = { sortingIgnorePrefix: false }
|
||||
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
sortBy: 'media.metadata.authorNameLF',
|
||||
filterGroup: null,
|
||||
pageMode: 'endless'
|
||||
})
|
||||
|
||||
expect(strategy.family).to.equal('author-browse')
|
||||
expect(strategy.paginationMode).to.equal('keyset')
|
||||
expect(strategy.cursorKeys).to.deep.equal(['authorNamesLastFirst', 'title', 'id'])
|
||||
})
|
||||
|
||||
it('uses keyset pagination for progress created-at browse', () => {
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
sortBy: 'progress.createdAt',
|
||||
filterGroup: 'progress',
|
||||
pageMode: 'endless'
|
||||
})
|
||||
|
||||
expect(strategy.family).to.equal('progress-browse')
|
||||
expect(strategy.paginationMode).to.equal('keyset')
|
||||
expect(strategy.cursorKeys).to.deep.equal(['mediaProgresses.createdAt', 'id'])
|
||||
})
|
||||
|
||||
it('uses keyset pagination for progress finished-at browse', () => {
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
sortBy: 'progress.finishedAt',
|
||||
filterGroup: 'progress',
|
||||
pageMode: 'endless'
|
||||
})
|
||||
|
||||
expect(strategy.family).to.equal('progress-browse')
|
||||
expect(strategy.paginationMode).to.equal('keyset')
|
||||
expect(strategy.cursorKeys).to.deep.equal(['mediaProgresses.finishedAt', 'id'])
|
||||
})
|
||||
|
||||
it('defines a filtered browse family for generic library filters', () => {
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
|
|
@ -125,4 +190,16 @@ describe('libraryBrowseStrategy', () => {
|
|||
|
||||
expect(strategy.family).to.equal('podcast-browse')
|
||||
})
|
||||
|
||||
it('falls back to offset for unsupported endless-scroll sorts', () => {
|
||||
const strategy = getLibraryBrowseStrategy({
|
||||
mediaType: 'book',
|
||||
sortBy: 'size',
|
||||
filterGroup: null,
|
||||
pageMode: 'endless'
|
||||
})
|
||||
|
||||
expect(strategy.paginationMode).to.equal('offset')
|
||||
expect(strategy.cursorKeys).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue