@@ -227,7 +227,7 @@ function filterAndSortTracks(tracks, params) {
227227 ( t ) =>
228228 t . title ?. toLowerCase ( ) . includes ( query ) ||
229229 t . artist ?. toLowerCase ( ) . includes ( query ) ||
230- t . album ?. toLowerCase ( ) . includes ( query )
230+ t . album ?. toLowerCase ( ) . includes ( query ) ,
231231 ) ;
232232
233233 // Calculate and attach search scores for ranking
@@ -246,14 +246,14 @@ function filterAndSortTracks(tracks, params) {
246246 // Artist filter
247247 if ( params . artist ) {
248248 result = result . filter (
249- ( t ) => t . artist ?. toLowerCase ( ) === params . artist . toLowerCase ( )
249+ ( t ) => t . artist ?. toLowerCase ( ) === params . artist . toLowerCase ( ) ,
250250 ) ;
251251 }
252252
253253 // Album filter
254254 if ( params . album ) {
255255 result = result . filter (
256- ( t ) => t . album ?. toLowerCase ( ) === params . album . toLowerCase ( )
256+ ( t ) => t . album ?. toLowerCase ( ) === params . album . toLowerCase ( ) ,
257257 ) ;
258258 }
259259
@@ -351,6 +351,35 @@ export async function setupLibraryMocks(page, state) {
351351 } ) ;
352352 } ) ;
353353
354+ // GET /api/library/count - get filtered count and total duration (pagination support)
355+ await page . route ( / \/ a p i \/ l i b r a r y \/ c o u n t ( \? .* ) ? $ / , async ( route , request ) => {
356+ if ( request . method ( ) !== 'GET' ) {
357+ await route . continue ( ) ;
358+ return ;
359+ }
360+
361+ const url = new URL ( request . url ( ) ) ;
362+ const params = Object . fromEntries ( url . searchParams ) ;
363+ state . apiCalls . push ( { method : 'GET' , url : '/api/library/count' , params } ) ;
364+
365+ // Use filterAndSortTracks without pagination to get all matching tracks
366+ const filtered = filterAndSortTracks ( state . tracks , {
367+ ...params ,
368+ limit : undefined ,
369+ offset : undefined ,
370+ } ) ;
371+ const totalDuration = filtered . tracks . reduce ( ( sum , t ) => sum + ( t . duration || 0 ) , 0 ) ;
372+
373+ await route . fulfill ( {
374+ status : 200 ,
375+ contentType : 'application/json' ,
376+ body : JSON . stringify ( {
377+ total : filtered . total ,
378+ total_duration : totalDuration ,
379+ } ) ,
380+ } ) ;
381+ } ) ;
382+
354383 // GET /api/library/stats - get library statistics
355384 await page . route ( / \/ a p i \/ l i b r a r y \/ s t a t s ( \? .* ) ? $ / , async ( route , request ) => {
356385 if ( request . method ( ) !== 'GET' ) {
@@ -437,7 +466,8 @@ export async function setupLibraryMocks(page, state) {
437466 status : 200 ,
438467 contentType : 'application/json' ,
439468 body : JSON . stringify ( {
440- data : 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==' ,
469+ data :
470+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==' ,
441471 mime_type : 'image/png' ,
442472 source : 'mock' ,
443473 } ) ,
@@ -661,7 +691,6 @@ export async function setupLibraryMocks(page, state) {
661691 } ) ;
662692}
663693
664-
665694/**
666695 * Helper to clear API call history
667696 * @param {Object } state - State from createLibraryState()
@@ -686,4 +715,3 @@ export function findApiCalls(state, method, urlPattern) {
686715 return urlPattern . test ( call . url ) ;
687716 } ) ;
688717}
689-
0 commit comments