/** * GitHub #1305: an album whose sortorder only listed deleted galleries showed "Loading album content..." forever. * The batch endpoint answered [] for the dead IDs and the Galleries tab read "entries but nothing loaded" as loading. * * Run: node --experimental-strip-types --test tests/ (from adminApp/, Node 22.6+) */ import assert from 'node:assert/strict'; import {test} from 'node:test'; import { isAlbumItemsLoading, isEntryLoaded, reorderSortorder } from '../src/utils/albumItemsLoadState.ts'; const settled = { loadedGalleryIds: [] as number[], loadedAlbumIds: [] as number[], isFetching: false, orderedItemCount: 0 }; test('an album of deleted galleries stops loading once the batch answers empty', () => { assert.equal(isAlbumItemsLoading({...settled, sortorder: [101, 102]}), false); }); test('an album of deleted nested albums stops loading once the album request answers empty', () => { assert.equal(isAlbumItemsLoading({...settled, sortorder: ['a7']}), false); }); test('an album with only some members deleted stops loading once the live ones are in the grid', () => { const state = {...settled, sortorder: [101, 5, 'a7'], loadedGalleryIds: [5]}; assert.equal(isAlbumItemsLoading({...state, orderedItemCount: 1}), false); }); test('it keeps loading while a request is in flight', () => { assert.equal(isAlbumItemsLoading({...settled, sortorder: [101], isFetching: true}), true); }); test('it keeps loading while loaded members are not in the grid yet', () => { assert.equal( isAlbumItemsLoading({...settled, sortorder: [5, 'a7'], loadedGalleryIds: [5]}), true ); assert.equal(isAlbumItemsLoading({...settled, sortorder: [5, 'a7'], loadedAlbumIds: [7]}), true); }); test('an empty album is not loading', () => { assert.equal(isAlbumItemsLoading({...settled, sortorder: []}), false); }); test('a gallery ID and the album entry with the same number are told apart', () => { assert.equal(isEntryLoaded(7, [], [7]), false); assert.equal(isEntryLoaded('a7', [7], []), false); assert.equal(isEntryLoaded(7, [7], []), true); assert.equal(isEntryLoaded('a7', [], [7]), true); }); test('reordering the grid keeps entries the grid does not show in their slot', () => { // 9 is a gallery the current user may not view: the batch endpoint leaves it out, so the grid shows 5, 6, a7. const sortorder = [5, 9, 6, 'a7']; assert.deepEqual(reorderSortorder(sortorder, ['a7', 5, 6]), ['a7', 9, 5, 6]); }); test('reordering an album whose entries all show is a plain reorder', () => { assert.deepEqual(reorderSortorder([5, 6, 'a7'], [6, 'a7', 5]), [6, 'a7', 5]); }); test('reordering keeps a grid item missing from the sortorder', () => { assert.deepEqual(reorderSortorder([5], [8, 5]), [8, 5]); });