feat(web): every paged list loads as you scroll; Liked becomes tabs (#5416)
release / go (push) Successful in 1m53s
release / govulncheck (push) Successful in 49s
release / web (push) Successful in 1m50s
release / android (push) Successful in 6m44s
release / Build signed APK (releases and dev) (push) Successful in 6m30s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / integration (push) Canceled after 21m41s
release / go (push) Successful in 1m53s
release / govulncheck (push) Successful in 49s
release / web (push) Successful in 1m50s
release / android (push) Successful in 6m44s
release / Build signed APK (releases and dev) (push) Successful in 6m30s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / integration (push) Canceled after 21m41s
Preference 172: no "Load more" buttons. Eight remained, on Liked (three sections), the three Search overflow pages, Genres and Years. - ListContinuation: the one bottom-of-list block. It loads the next page ahead of the reader, announces "Loading more…" through aria-live, shows an optional end line, and on a failed page shows the error with Try again, dropping the sentinel so a dead endpoint isn't re-hit on every scroll. Used on all ten paged lists, including the four that already autoloaded. - A failed next page no longer replaces the list. TanStack sets isError for it, so the page-level error branches now apply only to a failed first load. Genres and Years did the same with their own loader; a later page's failure now keeps the grid. - Liked: Artists | Albums | Tracks tabs (operator's choice). Stacked, a long Artists list loading as you scroll would bury the other two. It opens on the first tab that has likes. - TabStrip: the in-page tab strip, now shared by Liked, Playback errors and Requests. - test-utils/intersectionObserver: a stand-in so tests can scroll to the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,82 +38,99 @@ function page<T>(items: T[], total: number, offset = 0, limit = 50): Page<T> {
|
||||
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
|
||||
const ar: ArtistRef = { id: 'a1', name: 'Miles', sort_name: 'Miles', album_count: 1, cover_url: '' };
|
||||
const al: AlbumRef = {
|
||||
id: 'al1', title: 'Kind of Blue', sort_title: 'Kind of Blue', artist_id: 'a1', artist_name: 'Miles',
|
||||
year: 1959, track_count: 1, duration_sec: 100, cover_url: '/x', cover_art_source: null
|
||||
};
|
||||
const tr: TrackRef = makeTrack({
|
||||
title: 'So What', album_id: 'al1', album_title: 'Kind of Blue',
|
||||
artist_id: 'a1', artist_name: 'Miles', duration_sec: 100
|
||||
});
|
||||
|
||||
function setup(opts: {
|
||||
artists?: Page<ArtistRef>;
|
||||
albums?: Page<AlbumRef>;
|
||||
tracks?: Page<TrackRef>;
|
||||
tracksQuery?: Parameters<typeof mockInfiniteQuery>[0];
|
||||
}) {
|
||||
(createLikedArtistsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [opts.artists ?? page<ArtistRef>([], 0)] })
|
||||
);
|
||||
(createLikedAlbumsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [opts.albums ?? page<AlbumRef>([], 0)] })
|
||||
);
|
||||
(createLikedTracksInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [opts.tracks ?? page<TrackRef>([], 0)], ...opts.tracksQuery })
|
||||
);
|
||||
}
|
||||
|
||||
describe('liked library page', () => {
|
||||
test('renders three sections when each has items', () => {
|
||||
const ar: ArtistRef = { id: 'a1', name: 'X', sort_name: 'X', album_count: 1, cover_url: '' };
|
||||
const al: AlbumRef = {
|
||||
id: 'al1', title: 'Y', sort_title: 'Y', artist_id: 'a1', artist_name: 'X',
|
||||
year: 2020, track_count: 1, duration_sec: 100, cover_url: '/x', cover_art_source: null
|
||||
};
|
||||
const tr: TrackRef = makeTrack({
|
||||
title: 'Z', album_id: 'al1', album_title: 'Y',
|
||||
artist_id: 'a1', artist_name: 'X', duration_sec: 100
|
||||
});
|
||||
(createLikedArtistsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page([ar], 1)] })
|
||||
);
|
||||
(createLikedAlbumsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page([al], 1)] })
|
||||
);
|
||||
(createLikedTracksInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page([tr], 1)] })
|
||||
);
|
||||
// #5416: one list at a time. Stacked, a long Artists list that loads as you
|
||||
// scroll would bury Albums and Tracks.
|
||||
test('tabs carry each count and show one list at a time', async () => {
|
||||
setup({ artists: page([ar], 1), albums: page([al], 1), tracks: page([tr], 1) });
|
||||
render(LikedPage);
|
||||
expect(screen.getByRole('heading', { name: /artists/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: /albums/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: /tracks/i })).toBeInTheDocument();
|
||||
|
||||
const tabs = screen.getAllByRole('tab');
|
||||
expect(tabs.map((t) => t.textContent?.replace(/\s+/g, ' ').trim())).toEqual([
|
||||
'Artists 1',
|
||||
'Albums 1',
|
||||
'Tracks 1'
|
||||
]);
|
||||
expect(screen.getByText('Miles')).toBeInTheDocument();
|
||||
expect(screen.queryByText('So What')).not.toBeInTheDocument();
|
||||
|
||||
await fireEvent.click(screen.getByRole('tab', { name: /albums/i }));
|
||||
expect(screen.getByText('Kind of Blue')).toBeInTheDocument();
|
||||
|
||||
await fireEvent.click(screen.getByRole('tab', { name: /tracks/i }));
|
||||
expect(screen.getByText('So What')).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: /tracks/i })).toHaveAttribute('aria-selected', 'true');
|
||||
});
|
||||
|
||||
test('all three sections empty renders the whole-tab onboarding card', () => {
|
||||
(createLikedArtistsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<ArtistRef>([], 0)] })
|
||||
);
|
||||
(createLikedAlbumsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<AlbumRef>([], 0)] })
|
||||
);
|
||||
(createLikedTracksInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<TrackRef>([], 0)] })
|
||||
);
|
||||
test('opens on the first tab that has likes', () => {
|
||||
setup({ tracks: page([tr], 1) });
|
||||
render(LikedPage);
|
||||
expect(screen.getByRole('tab', { name: /tracks/i })).toHaveAttribute('aria-selected', 'true');
|
||||
expect(screen.getByText('So What')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('all three empty renders the whole-page onboarding card and no tabs', () => {
|
||||
setup({});
|
||||
render(LikedPage);
|
||||
// The whole-tab EmptyState replaces the three per-section hints
|
||||
// when every section is empty — single heading + action affordances.
|
||||
expect(screen.getByRole('heading', { name: /no likes yet/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: /explore home/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: /browse albums/i })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('tablist')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('one populated section + two empty subsections renders inline hints', () => {
|
||||
(createLikedArtistsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<ArtistRef>([{ id: 'a1', name: 'Miles' } as ArtistRef], 1)] })
|
||||
);
|
||||
(createLikedAlbumsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<AlbumRef>([], 0)] })
|
||||
);
|
||||
(createLikedTracksInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<TrackRef>([], 0)] })
|
||||
);
|
||||
test('an empty tab shows its inline hint', async () => {
|
||||
setup({ artists: page([ar], 1) });
|
||||
render(LikedPage);
|
||||
await fireEvent.click(screen.getByRole('tab', { name: /albums/i }));
|
||||
expect(screen.getByText(/no liked albums yet/i)).toBeInTheDocument();
|
||||
await fireEvent.click(screen.getByRole('tab', { name: /tracks/i }));
|
||||
expect(screen.getByText(/no liked tracks yet/i)).toBeInTheDocument();
|
||||
// Inline variant uses link affordances, not the big card heading.
|
||||
expect(screen.queryByRole('heading', { name: /no likes yet/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Load more calls fetchNextPage on each section that has more', async () => {
|
||||
const fetchTracks = vi.fn();
|
||||
(createLikedTracksInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<TrackRef>([], 100)], hasNextPage: true, fetchNextPage: fetchTracks })
|
||||
);
|
||||
(createLikedAlbumsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<AlbumRef>([], 0)] })
|
||||
);
|
||||
(createLikedArtistsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page<ArtistRef>([], 0)] })
|
||||
);
|
||||
// Preference 172: the list continues itself; there is no button to press.
|
||||
test('more tracks load as you scroll, with no Load more button', () => {
|
||||
setup({ tracks: page([tr], 100), tracksQuery: { hasNextPage: true } });
|
||||
const { container } = render(LikedPage);
|
||||
expect(screen.queryByRole('button', { name: /load more/i })).not.toBeInTheDocument();
|
||||
expect(container.querySelector('div[aria-hidden="true"].h-px')).not.toBeNull();
|
||||
});
|
||||
|
||||
test('a failed page offers Try again, which fetches it', async () => {
|
||||
const fetchNextPage = vi.fn();
|
||||
setup({
|
||||
tracks: page([tr], 100),
|
||||
tracksQuery: { hasNextPage: true, isFetchNextPageError: true, fetchNextPage }
|
||||
});
|
||||
render(LikedPage);
|
||||
const buttons = screen.getAllByRole('button', { name: /load more/i });
|
||||
expect(buttons).toHaveLength(1);
|
||||
await fireEvent.click(buttons[0]);
|
||||
expect(fetchTracks).toHaveBeenCalledTimes(1);
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Try again' }));
|
||||
expect(fetchNextPage).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user