Browse a found podcast by season and cancel abandoned previews

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-20 15:12:52 +02:00
1 parent 2ea3f7b337
commit 12617a6d52
7 files changed
+215 -19

No files matched your search

+67 -1
View File
@@ -799,7 +799,7 @@ function podcastsStore(stores = {}, overrides = {}) {
podcastFetchError: 'Last check failed', podcastLastChecked: 'Checked', podcastNeverChecked: 'Not checked yet',
podcastJamBlocked: 'jam blocked', podcastRequestFailed: 'request failed',
},
URLSearchParams, URL, GUEST: false,
URLSearchParams, URL, AbortController, GUEST: false,
fetch: async (url, init = {}) => {
calls.push({url, init});
if (overrides.respond) return overrides.respond(url, init);
@@ -1311,3 +1311,69 @@ test('a found podcast is previewed, then subscribed with the card id and origin
await new Promise(resolve => setImmediate(resolve));
assert.equal(store.found, null);
});
test('the seasons of a found podcast can be browsed, and an abandoned preview is cancelled', async () => {
const pending = [];
const {store, calls} = podcastsStore({}, {
T: Object.assign({}, FOUND_T, {podcastAllSeasons: 'All seasons'}),
respond: (url, init) => new Promise((resolve, reject) => {
pending.push(resolve);
init.signal?.addEventListener('abort', () => reject(Object.assign(new Error('aborted'), {name: 'AbortError'})));
}),
});
const tick = () => new Promise(resolve => setImmediate(resolve));
const answer = (index, preview) => pending[index]({ok: true, status: 200, json: async () => preview});
const body = index => JSON.parse(calls[index].init.body);
const hit = store.foundHit(foundEntity());
const preview = (extra = {}) => Object.assign({
podcast_id: POD_A, feed_url: hit.feed_url, moved: false, title: 'Night Radio', episode_count: 4,
seasons: [{season: 1, episode_count: 2}, {season: 2, episode_count: 1}, {season: null, episode_count: 1}],
listed_count: 4, episodes: [{title: 'Newest', season: 2}], subscribed: false, local_podcast_id: null,
}, extra);
store.openFound(hit);
assert.equal(store.found.season, 'all');
assert.equal(calls[0].init.signal.aborted, false);
answer(0, preview());
await tick();
assert.equal(store.foundMore(store.found.preview), 'and 3 more');
// A season chip lists that season; choosing another one cancels the
// request still running.
store.selectFoundSeason('1');
assert.equal(store.found.season, '1');
assert.deepEqual(body(1), {podcast_id: POD_A, feed_url: hit.feed_url, season: '1'});
store.selectFoundSeason('none');
assert.equal(calls[1].init.signal.aborted, true);
assert.deepEqual(body(2), {podcast_id: POD_A, feed_url: hit.feed_url, season: 'none'});
await tick();
// The cancelled request shows no error.
assert.equal(store.found.previewError, '');
answer(2, preview({listed_count: 1, episodes: [{title: 'Bonus', season: null}]}));
await tick();
assert.equal(store.found.previewLoading, false);
assert.equal(store.found.preview.episodes[0].title, 'Bonus');
assert.equal(store.foundMore(store.found.preview), '');
// The same chip again shows every season.
store.selectFoundSeason('none');
assert.equal(store.found.season, 'all');
assert.deepEqual(body(3), {podcast_id: POD_A, feed_url: hit.feed_url});
store.selectFoundSeason({season: 1});
assert.equal(calls.length, 4, 'only season values from the chips');
// Closing the card cancels its preview.
store.closeFound();
assert.equal(calls[3].init.signal.aborted, true);
assert.equal(store.found, null);
// So does opening another card.
store.openFound(hit);
store.openFound(store.foundHit(foundEntity({podcast_id: POD_B})));
assert.equal(calls[4].init.signal.aborted, true);
assert.equal(calls[5].init.signal.aborted, false);
assert.equal(body(5).podcast_id, POD_B);
answer(5, preview({podcast_id: POD_B}));
await tick();
assert.equal(store.found.hit.podcast_id, POD_B);
assert.equal(store.found.preview.podcast_id, POD_B);
assert.equal(store.found.previewError, '');
});