Fix podcast page

This commit is contained in:
ab committed 2026-11-22 17:49:23 +02:00
1 parent 319f0bcba7
commit eefe8a9777
16 files changed
+692 -222

No files matched your search

+8
View File
@@ -61,6 +61,8 @@ retention and administrator actions:
```bash
node --test tests/podcasts.test.cjs
FURU_PODCAST_RENDER_FIXTURE=1 cargo test renders_podcast_navigation_and_views
node tests/browser-podcast-ui.cjs
FURU_PODCAST_TEST_DATABASE_URL=postgresql://... cargo test podcasts -- --include-ignored
FURU_PODCAST_TEST_DATABASE_URL=postgresql://... cargo test admin_unicode_search -- --include-ignored
```
@@ -72,6 +74,12 @@ offline unsubscribe replay, legacy-peer filtering, and private Unicode search. T
admin fixture exercises list counts, all three catalogue lists and the track picker
with Cyrillic and Greek searches. Use a PostgreSQL build with ICU support; running
these fixtures on a database created with locale `C` covers the locale regression.
The browser UI fixture checks direct list/detail hashes on first load and reload,
back navigation, RSS artwork and broken-image fallbacks, explicit subscriptions,
compact search cards and mobile layout. It uses isolated API fixtures with the
rendered application. Set `PLAYWRIGHT_MODULE` and `CHROME_PATH` as for the other
browser tests. Optional `ALPINE_FIXTURE` points to a local Alpine.js bundle for
offline browser runs; otherwise the page loads Alpine from its normal CDN.
The access regression suite uses a disposable migrated database and a local OIDC
provider with signed tokens and PKCE:
+1 -1
View File
@@ -722,7 +722,7 @@ impl Federation {
.map(|r| Arc::clone(&r.podcast_dht))
.context("federation is not running")?;
let hits = overlay.search(query, 100).await?;
Ok(Value::Array(hits.into_iter().map(|hit| json!({"id":hit.podcast_id,"url":hit.feed_url,"metadata":{"title":hit.card.title,"author":hit.card.author,"description":hit.card.description}})).collect()))
Ok(Value::Array(hits.into_iter().map(|hit| json!({"id":hit.podcast_id,"url":hit.feed_url,"metadata":{"title":hit.card.title,"author":hit.card.author,"description":hit.card.description,"image_url":hit.card.image_url}})).collect()))
}
async fn similarity_services(&self) -> Result<(Arc<MusicDhtService>, Arc<SimilarityDht>)> {
+33
View File
@@ -33,6 +33,11 @@ fn renders_podcast_navigation_and_views() {
2
);
assert!(html.contains("/api/podcasts/action"));
assert!(
html.find("Alpine.store('podcasts',").unwrap()
< html.find("Alpine.store('library',").unwrap(),
"podcast navigation must be registered before library.init restores the hash"
);
if std::env::var_os("FURU_PODCAST_RENDER_FIXTURE").is_some() {
std::fs::write("target/podcast-player-fixture.html", html).unwrap();
}
@@ -187,6 +192,22 @@ async fn postgres_multiuser_progress_retention_and_admin() {
1
);
let request = |value| serde_json::from_value::<Action>(value).unwrap();
let preview = action(
pool.clone(),
config.clone(),
99,
false,
request(json!({"action":"detail","id":podcast})),
)
.await
.unwrap();
assert_eq!(preview["subscribed"], false);
let count: i64 =
sqlx::query_scalar("SELECT count(*) FROM furumusic__podcast_subscription WHERE user_id=99")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(count, 0);
action(
pool.clone(),
config.clone(),
@@ -196,6 +217,18 @@ async fn postgres_multiuser_progress_retention_and_admin() {
)
.await
.unwrap();
assert!(
action(
pool.clone(),
config.clone(),
99,
false,
request(json!({"action":"detail","id":podcast}))
)
.await
.is_err(),
"private podcasts must not be exposed by the detail route"
);
assert_eq!(
list(&pool, 2, false).await.unwrap()["mine"]
.as_array()
+7 -2
View File
@@ -104,17 +104,22 @@ async fn action(
}
match body.action.as_str() {
"list" => return list(&pool, user, false).await,
"detail" => {
let detail:Option<Value>=sqlx::query_scalar("SELECT jsonb_build_object('id',p.id,'url',p.origin_url,'metadata',p.metadata,'subscribed',EXISTS(SELECT 1 FROM furumusic__podcast_subscription s WHERE s.user_id=$1 AND s.podcast_id=p.id),'episodes',(SELECT count(*) FROM furumusic__podcast_episode e WHERE e.podcast_id=p.id)) FROM furumusic__podcast p WHERE p.id=$2 AND EXISTS(SELECT 1 FROM furumusic__podcast_subscription s WHERE s.podcast_id=p.id AND (s.user_id=$1 OR s.shared))").bind(user).bind(&body.id).fetch_optional(&pool).await?;
return detail.context("podcast not found");
}
"admin_list" => return list(&pool, user, true).await,
"add" => {
let id = subscribe(&pool, user, &body.url).await?;
sync::ensure_subscribed(&pool, user, &id).await?;
sync::seed_user(&pool, user).await?;
let checked = refresh(&pool, &id).await;
let download_id = id.clone();
tokio::spawn(async move {
let _ = download_pending(&pool, &config, Some(&id)).await;
let _ = download_pending(&pool, &config, Some(&download_id)).await;
});
return Ok(
json!({"ok":true,"warning":checked.err().map(|_| "Feed check failed; the subscription was saved") }),
json!({"ok":true,"id":id,"warning":checked.err().map(|_| "Feed check failed; the subscription was saved") }),
);
}
"remove" => {
+2 -1
View File
@@ -4,11 +4,12 @@
{% block head_extra %}
{% include "player/styles.html" %}
{% include "player/podcast_styles.html" %}
{% endblock head_extra %}
{% block body %}
{% include "player/shell.html" %}
{% include "player/modals.html" %}
{% include "player/scripts.html" %}
{% include "player/podcast_scripts.html" %}
{% include "player/scripts.html" %}
{% endblock body %}
+23
View File
@@ -0,0 +1,23 @@
<template x-if="$store.podcasts.artwork(pod)">
<img
:src="$store.podcasts.artwork(pod)"
alt=""
aria-hidden="true"
loading="lazy"
decoding="async"
referrerpolicy="no-referrer"
@error="$store.podcasts.artworkFailed(pod)"
/>
</template>
<template x-if="!$store.podcasts.artwork(pod)">
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
aria-hidden="true"
>
<rect x="9" y="2" width="6" height="13" rx="3" />
<path d="M5 10v2a7 7 0 0014 0v-2M12 19v3M8 22h8" />
</svg>
</template>
+18
View File
@@ -0,0 +1,18 @@
<button
type="button"
class="card podcast-tile"
@click="$store.podcasts.open(pod)"
:title="pod.metadata.title"
>
<div class="card-img podcast-artwork">{% include "player/podcast_artwork.html" %}</div>
<div class="card-title" x-text="pod.metadata.title"></div>
<div
class="card-subtitle"
x-text="pod.metadata.author || $store.podcasts.text('podcasts')"
></div>
<div
class="card-subtitle"
x-show="pod.episodes != null"
x-text="(pod.episodes || 0) + ' ' + $store.podcasts.text('episodes') + (pod.new_episodes ? ' · ' + pod.new_episodes + ' ' + $store.podcasts.text('unplayed') : '')"
></div>
</button>
+61
View File
@@ -0,0 +1,61 @@
<h2 class="podcast-section-title" x-text="$store.podcasts.text('episodes')"></h2>
<div class="podcast-toolbar">
<input
type="text"
x-model="$store.podcasts.filter"
:placeholder="$store.podcasts.text('filter')"
:aria-label="$store.podcasts.text('filter')"
/><select x-model="$store.podcasts.season" :aria-label="$store.podcasts.text('season')">
<option value="" x-text="$store.podcasts.text('allSeasons')"></option>
<template x-for="season in $store.podcasts.seasons()" :key="season"
><option :value="season" x-text="$store.podcasts.text('season')+' '+season"></option
></template></select
><label
><input type="checkbox" x-model="$store.podcasts.unplayedOnly" />
<span x-text="$store.podcasts.text('unplayedOnly')"></span
></label>
</div>
<p
x-show="!$store.podcasts.filteredEpisodes().length"
x-text="$store.podcasts.text('noEpisodes')"
></p>
<template x-for="episode in $store.podcasts.filteredEpisodes()" :key="episode.id"
><article class="podcast-episode">
<h3 x-text="episode.metadata.title"></h3>
<div x-text="$store.podcasts.date(episode.metadata.published_at_ms)"></div>
<details x-show="episode.metadata.description">
<summary x-text="$store.podcasts.text('description')"></summary>
<p class="podcast-description" x-text="episode.metadata.description"></p>
</details>
<div class="podcast-toolbar">
<button
class="release-action-btn secondary"
@click="$store.podcasts.play(episode)"
x-text="$store.podcasts.text(episode.position_ms&&!episode.completed?'resume':'play')"
></button
><button
class="release-action-btn secondary"
@click="$store.podcasts.download(episode)"
:disabled="episode.cached||episode.downloading"
x-text="$store.podcasts.text(episode.cached?'saved':episode.downloading?'downloading':'download')"
></button
><button
class="release-action-btn secondary"
@click="$store.podcasts.mark(episode)"
x-text="$store.podcasts.text(episode.completed?'markUnplayed':'markPlayed')"
></button
><button
class="release-action-btn secondary"
x-show="episode.position_ms"
@click="$store.podcasts.restart(episode)"
x-text="$store.podcasts.text('restart')"
></button>
</div>
<div role="status" x-show="episode.error" x-text="episode.error"></div></article></template
><button
class="release-action-btn secondary"
x-show="$store.podcasts.hasMore"
@click="$store.podcasts.more()"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('loadMore')"
></button>
+148 -38
View File
@@ -2,11 +2,19 @@
document.addEventListener('alpine:init', () => {
const labels = {
podcasts: ['Podcasts', 'Подкасты'],
episodes: ['Episodes', 'Выпуски'],
subscribeHint: [
'Subscribe to listen and save episodes.',
'Подпишитесь, чтобы слушать и сохранять выпуски.',
],
notFound: ['Podcast not found.', 'Подкаст не найден.'],
showMore: ['Show more', 'Подробнее'],
showLess: ['Show less', 'Свернуть'],
add: ['Add', 'Добавить'],
mine: ['My podcasts', 'Мои подкасты'],
public: ['Public podcasts', 'Публичные подкасты'],
results: ['Podcast search results','Результаты поиска подкастов'],
noMatches: ['No matching podcasts.','Подходящих подкастов нет.'],
results: ['Podcast search results', 'Результаты поиска подкастов'],
noMatches: ['No matching podcasts.', 'Подходящих подкастов нет.'],
empty: ['Add an RSS or Atom feed.', 'Добавьте RSS или Atom ленту.'],
check: ['Check episodes', 'Проверить выпуски'],
checkAll: ['Check all', 'Проверить все'],
@@ -65,6 +73,12 @@
episodes: [],
hasMore: false,
selected: null,
selectedId: null,
loading: false,
adding: false,
failedArtwork: {},
descriptionExpanded: false,
_navigation: 0,
url: '',
query: '',
filter: '',
@@ -105,32 +119,77 @@
},
async load() {
const data = await this.api('list');
this.mine = data.mine;
this.mine = data.mine.map((pod) => ({ ...pod, subscribed: true }));
this.public = data.public;
if (this.selected) {
const current =
this.mine.find((p) => p.id === this.selected.id) ||
this.public.find((p) => p.id === this.selected.id);
this.selected = {
...this.selected,
...current,
subscribed: this.mine.some((p) => p.id === this.selected.id),
};
}
},
enter() {
if (location.hash !== '#podcasts')
Alpine.store('library')._beginNavigation('#podcasts');
Alpine.store('library').view = 'podcasts';
artwork(pod) {
const url = pod?.metadata?.image_url;
return url && !this.failedArtwork[url] ? url : null;
},
artworkFailed(pod) {
const url = pod?.metadata?.image_url;
if (url) this.failedArtwork[url] = true;
},
description(pod) {
const text = pod?.metadata?.description || '';
return !this.descriptionExpanded && text.length > 360
? text.slice(0, 360).trimEnd() + '…'
: text;
},
navigate(hash, view, options = {}) {
const library = Alpine.store('library');
library._beginNavigation(hash, options);
library.view = view;
library.currentArtist = null;
library.currentRelease = null;
library.currentPlaylist = null;
Alpine.store('mobile')?.closeLibrary();
const loading = this.task(async () => {
await this.load();
this.message = '';
});
this.ensurePolling();
},
ensurePolling() {
if (!this.poller)
this.poller = setInterval(() => {
if (Alpine.store('library').view === 'podcasts' && !this.busy)
if (
['podcasts', 'podcast_detail'].includes(Alpine.store('library').view) &&
!this.busy &&
!this.loading
)
this.update().catch(() => {});
}, 5000);
return loading;
},
async enter(options = {}) {
const token = ++this._navigation;
this.navigate('#podcasts', 'podcasts', options);
this.selected = null;
this.selectedId = null;
this.episodes = [];
this.message = '';
this.loading = true;
try {
await this.load();
} catch (error) {
if (token === this._navigation) this.message = error.message;
} finally {
if (token === this._navigation) {
this.loading = false;
Alpine.store('library')._afterNavigation(options);
}
}
},
async update() {
await this.load();
if (this.selected && !this.mine.some((p) => p.id === this.selected.id)) {
this.selected = null;
this.episodes = [];
}
if (this.selected) await this.loadEpisodes();
if (this.selected?.subscribed) await this.loadEpisodes();
else this.episodes = [];
},
async loadEpisodes(append = false) {
const id = this.selected.id;
@@ -149,29 +208,63 @@
this.message = '';
});
},
open(pod) {
this.selected = pod;
async open(pod, options = {}) {
const id = typeof pod === 'string' ? pod : pod.id;
const token = ++this._navigation;
this.selectedId = id;
this.descriptionExpanded = false;
const cached =
this.mine.find((p) => p.id === id) ||
this.public.find((p) => p.id === id) ||
(typeof pod === 'object' ? pod : null);
this.selected = cached
? {
...cached,
subscribed: this.mine.some((p) => p.id === id) || !!cached.subscribed,
}
: null;
this.episodes = [];
this.hasMore = false;
this.filter = '';
this.season = '';
this.task(async () => {
await this.loadEpisodes();
this.message = '';
});
this.message = '';
this.loading = true;
this.navigate('#podcast?id=' + encodeURIComponent(id), 'podcast_detail', options);
try {
await this.load();
if (token !== this._navigation) return;
const detail =
this.mine.find((p) => p.id === id) ||
this.public.find((p) => p.id === id) ||
this.selected ||
(await this.api('detail', { id }));
if (token !== this._navigation) return;
this.selected = { ...detail, subscribed: this.mine.some((p) => p.id === id) };
if (this.selected.subscribed) await this.loadEpisodes();
} catch (error) {
if (token === this._navigation)
this.message = error.message || this.text('notFound');
} finally {
if (token === this._navigation) {
this.loading = false;
Alpine.store('library')._afterNavigation(options);
}
}
},
openResult(pod) {
return this.open(pod);
},
subscribe(pod = this.selected) {
return this.task(async () => {
if (!pod.subscribed) await this.api('add', { url: pod.url });
await this.api('add', { url: pod.url || pod.metadata.feed_url });
await this.load();
this.selected = this.mine.find((p) => p.id === pod.id) || pod;
this.episodes = [];
this.hasMore = false;
this.filter = '';
this.season = '';
Alpine.store('library')._beginNavigation('#podcasts');
Alpine.store('library').view = 'podcasts';
await this.loadEpisodes();
if (this.selectedId === pod.id) {
this.selected = this.mine.find((p) => p.id === pod.id) || {
...pod,
subscribed: true,
};
await this.loadEpisodes();
}
this.message = '';
});
},
@@ -180,6 +273,8 @@
const result = await this.api('add', { url: url || this.url });
this.url = '';
await this.load();
this.adding = false;
if (result.id) await this.open(result.id);
this.message = result.warning || this.text('done');
});
},
@@ -188,8 +283,13 @@
this.task(async () => {
const result = await this.api('remove', { id: pod.id });
if (this.selected?.id === pod.id) {
++this._navigation;
this.loading = false;
this.selected = null;
this.selectedId = null;
this.episodes = [];
this.navigate('#podcasts', 'podcasts');
Alpine.store('library')._afterNavigation();
}
await this.load();
this.message = this.text(result.publication_pending ? 'pending' : 'done');
@@ -250,18 +350,28 @@
});
},
search() {
const query=this.query.trim();
const query = this.query.trim();
return this.task(async () => {
const data = await this.api('search', { query });
if(this.query.trim()!==query){this.message='';return;}
if (this.query.trim() !== query) {
this.message = '';
return;
}
this.hits = data.hits;
this.searched=true;
this.searched = true;
this.message = this.text('done');
});
},
resetSearch(){this.searched=false;this.hits=[];},
resetSearch() {
this.searched = false;
this.hits = [];
},
publicCards() {
return [...new Map((this.searched?this.hits:this.public).map((p) => [p.id, p])).values()];
return [
...new Map(
(this.searched ? this.hits : this.public).map((p) => [p.id, p]),
).values(),
];
},
seasons() {
return [
+15
View File
@@ -0,0 +1,15 @@
<button
type="button"
class="search-release-card podcast-tile"
@click="$store.podcasts.open(pod)"
:title="pod.metadata.title"
>
<div class="search-release-cover podcast-artwork">
{% include "player/podcast_artwork.html" %}
</div>
<div class="card-title" x-text="pod.metadata.title"></div>
<div
class="card-subtitle"
x-text="pod.metadata.author || $store.podcasts.text('podcasts')"
></div>
</button>
+39
View File
@@ -0,0 +1,39 @@
<style>
.podcast-nav { appearance:none; border:0; background:transparent; width:100%; font:inherit; text-align:left; }
.podcast-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; flex-wrap:wrap; margin-bottom:20px; }
.podcast-heading .section-title, .podcast-heading .release-actions { margin:0; }
.podcast-section { margin-top:32px; }
.podcast-section-title { font-size:20px; font-weight:700; margin:0 0 16px; }
.podcast-tile { appearance:none; border:0; color:var(--text-primary); font:inherit; text-align:left; min-width:0; }
.podcast-tile:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.podcast-tile .card-subtitle { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.podcast-artwork { color:var(--text-subdued); }
.podcast-artwork svg { width:48px; height:48px; }
.podcast-tile img { display:block; }
.search-release-cover.podcast-artwork svg { width:40px; height:40px; }
.podcast-detail-actions { display:contents; }
.podcast-toolbar { display:flex; align-items:center; flex-wrap:wrap; gap:12px; margin:16px 0; }
.podcast-toolbar input[type=text], .podcast-toolbar select { background:var(--bg-secondary); color:var(--text-primary); border:1px solid var(--border-color); border-radius:6px; padding:10px 12px; font:inherit; min-width:0; }
.podcast-toolbar input[type=text] { flex:1; min-width:160px; }
.podcast-toolbar label { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--text-secondary); }
.podcast-toolbar input[type=checkbox] { accent-color:var(--accent); }
.podcast-notice { margin:12px 0; font-size:13px; color:var(--text-secondary); overflow-wrap:anywhere; }
.podcast-detail .release-meta { min-width:0; flex:1; }
.podcast-detail .release-title { overflow-wrap:anywhere; }
.podcast-description { margin:0 0 28px; max-width:80ch; color:var(--text-secondary); font-size:14px; line-height:1.7; white-space:pre-line; overflow-wrap:anywhere; }
.podcast-description-section { margin-bottom:28px; }
.podcast-description-section .podcast-description { margin:0; }
.podcast-description-section .artist-top-tracks-toggle { margin-top:8px; padding-left:0; }
.podcast-episode { padding:16px 0; border-bottom:1px solid var(--border-color); }
.podcast-episode h3 { font-size:14px; font-weight:500; margin:0 0 6px; overflow-wrap:anywhere; }
.podcast-episode > div { font-size:12px; color:var(--text-subdued); }
.podcast-episode details { margin-top:8px; font-size:12px; color:var(--text-secondary); }
.podcast-episode summary { cursor:pointer; width:fit-content; }
.podcast-episode .podcast-description { margin:8px 0 0; }
.podcast-detail .release-action-btn:disabled, .podcast-toolbar button:disabled { opacity:.5; cursor:default; }
@media(max-width:600px) {
.podcast-heading { align-items:flex-start; gap:12px; }
.podcast-heading .release-actions { gap:8px; }
.podcast-toolbar input[type=text], .podcast-toolbar select { font-size:16px; min-height:44px; }
}
</style>
+198 -161
View File
@@ -1,174 +1,211 @@
<style>
.podcast-nav{appearance:none;border:0;background:transparent;width:100%;font:inherit;text-align:left}
.podcast-page{padding:20px;max-width:1100px;margin:auto}.podcast-toolbar{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin:16px 0}.podcast-toolbar input,.podcast-toolbar select{background:var(--bg-secondary,#171c28);color:inherit;border:1px solid var(--border,#384052);border-radius:8px;padding:10px;max-width:100%}.podcast-toolbar input[type=text]{flex:1;min-width:160px}.podcast-page button,.podcast-card button{border:1px solid var(--border,#384052);background:var(--bg-secondary,#171c28);color:inherit;border-radius:8px;padding:8px 12px;cursor:pointer}.podcast-page button:disabled,.podcast-card button:disabled{opacity:.5}.podcast-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(280px,100%),1fr));gap:14px;margin:16px 0 28px}.podcast-card,.podcast-episode{border:1px solid var(--border,#384052);border-radius:12px;padding:16px;overflow-wrap:anywhere}.podcast-card h3,.podcast-episode h3{margin:0 0 8px}.podcast-description{color:var(--text-secondary,#a2a9b8);white-space:pre-line;margin:8px 0}.podcast-episode{margin:10px 0}.podcast-notice{padding:12px 0;color:var(--accent,#67e8f9)}@media(max-width:600px){.podcast-page{padding:12px}.podcast-page button,.podcast-page input,.podcast-page select{min-height:44px;font-size:16px}}
</style>
<template x-if="$store.library.view === 'podcasts'">
<section class="podcast-page">
<h1 x-text="$store.podcasts.text('podcasts')"></h1>
<form class="podcast-toolbar" @submit.prevent="$store.podcasts.add()">
<section>
<div class="podcast-heading">
<h1 class="section-title" x-text="$store.podcasts.text('podcasts')"></h1>
<div class="release-actions">
<button
class="release-action-btn secondary"
@click="$store.podcasts.refreshAll()"
:disabled="$store.podcasts.busy || $store.podcasts.loading"
x-text="$store.podcasts.text('checkAll')"
></button>
<button
class="release-action-btn primary"
@click="$store.podcasts.adding=!$store.podcasts.adding"
:aria-expanded="$store.podcasts.adding"
aria-controls="podcast-add-feed"
x-text="$store.podcasts.text('add')"
></button>
</div>
</div>
<form
id="podcast-add-feed"
class="podcast-toolbar"
x-show="$store.podcasts.adding"
x-cloak
@submit.prevent="$store.podcasts.add()"
>
<input
type="text"
x-model="$store.podcasts.url"
placeholder="RSS / Atom URL"
aria-label="RSS / Atom URL"
required
/><button :disabled="$store.podcasts.busy" x-text="$store.podcasts.text('add')"></button
><button
type="button"
@click="$store.podcasts.refreshAll()"
/>
<button
class="release-action-btn primary"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('checkAll')"
></button>
</form>
<div
role="status"
aria-live="polite"
class="podcast-notice"
x-text="$store.podcasts.message"
></div>
<h2 x-text="$store.podcasts.text('mine')"></h2>
<p x-show="!$store.podcasts.mine.length" x-text="$store.podcasts.text('empty')"></p>
<div class="podcast-grid">
<template x-for="pod in $store.podcasts.mine" :key="pod.id"
><article class="podcast-card">
<h3>
<button
@click="$store.podcasts.open(pod)"
x-text="pod.metadata.title"
></button>
</h3>
<div x-text="pod.metadata.author"></div>
<div
class="podcast-description"
x-text="pod.episodes+' · '+pod.new_episodes+' '+$store.podcasts.text('unplayed')"
></div>
<div x-show="pod.error" x-text="pod.error"></div>
<div class="podcast-toolbar">
<button
@click="$store.podcasts.refresh(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('check')"
></button
><button
@click="$store.podcasts.share(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text(pod.shared?'unpublish':'publish')"
></button
><button
@click="$store.podcasts.remove(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('remove')"
></button>
</div></article
></template>
</div>
<template x-if="$store.podcasts.selected"
><section>
<h2 x-text="$store.podcasts.selected.metadata.title"></h2>
<p
class="podcast-description"
x-text="$store.podcasts.selected.metadata.description"
></p>
<div class="podcast-toolbar">
<input
type="text"
x-model="$store.podcasts.filter"
:placeholder="$store.podcasts.text('filter')"
:aria-label="$store.podcasts.text('filter')"
/><select
x-model="$store.podcasts.season"
:aria-label="$store.podcasts.text('season')"
>
<option value="" x-text="$store.podcasts.text('allSeasons')"></option>
<template x-for="season in $store.podcasts.seasons()" :key="season"
><option
:value="season"
x-text="$store.podcasts.text('season')+' '+season"
></option
></template></select
><label
><input type="checkbox" x-model="$store.podcasts.unplayedOnly" />
<span x-text="$store.podcasts.text('unplayedOnly')"></span
></label>
</div>
<p
x-show="!$store.podcasts.filteredEpisodes().length"
x-text="$store.podcasts.text('noEpisodes')"
></p>
<template x-for="episode in $store.podcasts.filteredEpisodes()" :key="episode.id"
><article class="podcast-episode">
<h3 x-text="episode.metadata.title"></h3>
<div x-text="$store.podcasts.date(episode.metadata.published_at_ms)"></div>
<details x-show="episode.metadata.description">
<summary x-text="$store.podcasts.text('description')"></summary>
<p
class="podcast-description"
x-text="episode.metadata.description"
></p>
</details>
<div class="podcast-toolbar">
<button
@click="$store.podcasts.play(episode)"
x-text="$store.podcasts.text(episode.position_ms&&!episode.completed?'resume':'play')"
></button
><button
@click="$store.podcasts.download(episode)"
:disabled="episode.cached||episode.downloading"
x-text="$store.podcasts.text(episode.cached?'saved':episode.downloading?'downloading':'download')"
></button
><button
@click="$store.podcasts.mark(episode)"
x-text="$store.podcasts.text(episode.completed?'markUnplayed':'markPlayed')"
></button
><button
x-show="episode.position_ms"
@click="$store.podcasts.restart(episode)"
x-text="$store.podcasts.text('restart')"
></button>
</div>
<div
role="status"
x-show="episode.error"
x-text="episode.error"
></div></article></template
><button
x-show="$store.podcasts.hasMore"
@click="$store.podcasts.more()"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('loadMore')"
></button></section
></template>
<h2 x-text="$store.podcasts.text($store.podcasts.searched?'results':'public')"></h2>
<form class="podcast-toolbar" @submit.prevent="$store.podcasts.search()">
<input
type="text"
x-model="$store.podcasts.query"
@input="$store.podcasts.resetSearch()"
:placeholder="$store.podcasts.text('searchNetwork')"
:aria-label="$store.podcasts.text('searchNetwork')"
minlength="2"
maxlength="200"
/><button
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('search')"
x-text="$store.podcasts.text('subscribe')"
></button>
</form>
<p
x-show="!$store.podcasts.publicCards().length"
x-text="$store.podcasts.text($store.podcasts.searched?'noMatches':'noPublic')"
class="podcast-notice"
role="status"
aria-live="polite"
x-show="$store.podcasts.message"
x-text="$store.podcasts.message"
></p>
<div class="podcast-grid">
<template x-for="pod in $store.podcasts.publicCards()" :key="pod.id"
><article class="podcast-card">
<h3 x-text="pod.metadata.title"></h3>
<div x-text="pod.metadata.author"></div>
<p class="podcast-description" x-text="pod.metadata.description"></p>
<h2 class="podcast-section-title" x-text="$store.podcasts.text('mine')"></h2>
<div
class="loading-spinner"
x-show="$store.podcasts.loading && !$store.podcasts.mine.length"
>
<div class="spinner"></div>
</div>
<div class="empty-state" x-show="!$store.podcasts.loading && !$store.podcasts.mine.length">
<p x-text="$store.podcasts.text('empty')"></p>
</div>
<div class="card-grid">
<template x-for="pod in $store.podcasts.mine" :key="pod.id"
>{% include "player/podcast_card.html" %}</template
>
</div>
<section class="podcast-section">
<h2
class="podcast-section-title"
x-text="$store.podcasts.text($store.podcasts.searched?'results':'public')"
></h2>
<form class="podcast-toolbar" @submit.prevent="$store.podcasts.search()">
<input
type="text"
x-model="$store.podcasts.query"
@input="$store.podcasts.resetSearch()"
:placeholder="$store.podcasts.text('searchNetwork')"
:aria-label="$store.podcasts.text('searchNetwork')"
minlength="2"
maxlength="200"
/>
<button
class="release-action-btn secondary"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('search')"
></button>
</form>
<div
class="empty-state"
x-show="!$store.podcasts.loading && !$store.podcasts.publicCards().length"
>
<p
x-text="$store.podcasts.text($store.podcasts.searched?'noMatches':'noPublic')"
></p>
</div>
<div class="card-grid">
<template x-for="pod in $store.podcasts.publicCards()" :key="pod.id"
>{% include "player/podcast_card.html" %}</template
>
</div>
</section>
</section>
</template>
<template x-if="$store.library.view === 'podcast_detail'">
<section class="podcast-detail">
<div class="breadcrumb">
<a
href="#podcasts"
@click.prevent="$store.podcasts.enter()"
x-text="$store.podcasts.text('podcasts')"
></a
><span>/</span>
<span
x-text="$store.podcasts.selected?.metadata.title || $store.podcasts.text($store.podcasts.loading?'working':'notFound')"
></span>
</div>
<div class="loading-spinner" x-show="$store.podcasts.loading && !$store.podcasts.selected">
<div class="spinner"></div>
</div>
<p
class="podcast-notice"
role="status"
aria-live="polite"
x-show="$store.podcasts.message"
x-text="$store.podcasts.message"
></p>
<template
x-for="pod in ($store.podcasts.selected ? [$store.podcasts.selected] : [])"
:key="pod.id"
>
<div>
<div class="release-header">
<div class="release-cover podcast-artwork">
{% include "player/podcast_artwork.html" %}
</div>
<div class="release-meta">
<h1 class="release-title" x-text="pod.metadata.title"></h1>
<div class="release-artists" x-text="pod.metadata.author"></div>
<div class="artist-stats" x-show="pod.episodes != null">
<span
x-text="(pod.episodes || 0) + ' ' + $store.podcasts.text('episodes')"
></span
><span
x-show="pod.subscribed && pod.new_episodes"
x-text="' · ' + pod.new_episodes + ' ' + $store.podcasts.text('unplayed')"
></span>
</div>
<div class="release-actions">
<template x-if="!pod.subscribed"
><button
class="release-action-btn primary"
@click="$store.podcasts.subscribe(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('subscribe')"
></button
></template>
<template x-if="pod.subscribed"
><div class="podcast-detail-actions">
<button
class="release-action-btn secondary"
@click="$store.podcasts.refresh(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('check')"
></button>
<button
class="release-action-btn secondary"
@click="$store.podcasts.share(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text(pod.shared?'unpublish':'publish')"
></button>
<button
class="release-action-btn secondary"
@click="$store.podcasts.remove(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text('remove')"
></button></div
></template>
</div>
</div>
</div>
<div class="podcast-description-section" x-show="pod.metadata.description">
<p
id="podcast-description"
class="podcast-description"
x-text="$store.podcasts.description(pod)"
></p>
<button
@click="$store.podcasts.openResult(pod)"
:disabled="$store.podcasts.busy"
x-text="$store.podcasts.text(pod.subscribed||$store.podcasts.mine.some(p=>p.id===pod.id)?'open':'subscribe')"
></button></article
></template>
</div></section
></template>
class="artist-top-tracks-toggle"
x-show="(pod.metadata.description || '').length>360"
@click="$store.podcasts.descriptionExpanded=!$store.podcasts.descriptionExpanded"
:aria-expanded="$store.podcasts.descriptionExpanded"
aria-controls="podcast-description"
x-text="$store.podcasts.text($store.podcasts.descriptionExpanded?'showLess':'showMore')"
></button>
</div>
<p class="podcast-notice" x-show="pod.error" x-text="pod.error"></p>
<template x-if="pod.subscribed"
><section>
<div class="loading-spinner" x-show="$store.podcasts.loading">
<div class="spinner"></div>
</div>
<div x-show="!$store.podcasts.loading">
{% include "player/podcast_episodes.html" %}
</div>
</section></template
>
<p
class="podcast-notice"
x-show="!pod.subscribed"
x-text="$store.podcasts.text('subscribeHint')"
></p>
</div>
</template>
</section>
</template>
+5 -1
View File
@@ -2670,7 +2670,11 @@ document.addEventListener('alpine:init', () => {
if (this.view !== 'artists' || this.artistsPage === 0) this.goArtists(options);
else if (options.restoreScroll) this._restoreScrollPosition(hash);
} else if (view === 'podcasts') {
Alpine.store('podcasts').enter();
Alpine.store('podcasts').enter(options);
} else if (view === 'podcast') {
const podcastId = new URLSearchParams(params).get('id');
if(podcastId)Alpine.store('podcasts').open(podcastId,options);
else Alpine.store('podcasts').enter(options);
} else if (view === 'uploads' && !id) {
if (this.view !== 'my_uploads' || this.artistsPage === 0) this.goMyUploads(options);
else if (options.restoreScroll) this._restoreScrollPosition(hash);
+12 -16
View File
@@ -75,7 +75,7 @@
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><path d="M17 8l-5-5-5 5"/><path d="M12 3v12"/></svg>
{{ t.player_my_uploads }}
</div>
<button class="sidebar-nav-item podcast-nav" :class="{active:$store.library.view==='podcasts'}" @click="$store.podcasts.enter()"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="2" width="6" height="13" rx="3"/><path d="M5 10v2a7 7 0 0014 0v-2M12 19v3M8 22h8"/></svg><span x-text="$store.podcasts.text('podcasts')"></span></button>
<button class="sidebar-nav-item podcast-nav" :class="{active:['podcasts','podcast_detail'].includes($store.library.view)}" @click="$store.podcasts.enter()"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="2" width="6" height="13" rx="3"/><path d="M5 10v2a7 7 0 0014 0v-2M12 19v3M8 22h8"/></svg><span x-text="$store.podcasts.text('podcasts')"></span></button>
</div>
<div class="sidebar-section">
<div class="sidebar-section-title">
@@ -188,7 +188,7 @@
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><path d="M17 8l-5-5-5 5"/><path d="M12 3v12"/></svg>
{{ t.player_my_uploads }}
</div>
<button class="sidebar-nav-item podcast-nav" :class="{active:$store.library.view==='podcasts'}" @click="$store.podcasts.enter()"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="2" width="6" height="13" rx="3"/><path d="M5 10v2a7 7 0 0014 0v-2M12 19v3M8 22h8"/></svg><span x-text="$store.podcasts.text('podcasts')"></span></button>
<button class="sidebar-nav-item podcast-nav" :class="{active:['podcasts','podcast_detail'].includes($store.library.view)}" @click="$store.podcasts.enter()"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="2" width="6" height="13" rx="3"/><path d="M5 10v2a7 7 0 0014 0v-2M12 19v3M8 22h8"/></svg><span x-text="$store.podcasts.text('podcasts')"></span></button>
</div>
<div class="mobile-drawer-section">
@@ -447,20 +447,6 @@
</div>
</template>
<!-- Artists section -->
<template x-if="($store.library.searchResults.podcasts || []).length">
<section class="search-section">
<h2 class="search-section-title" x-text="$store.podcasts.text('podcasts')"></h2>
<div class="podcast-grid">
<template x-for="pod in $store.library.searchResults.podcasts" :key="pod.id">
<article class="podcast-card">
<h3><button @click="$store.podcasts.openResult(pod)" x-text="pod.metadata.title"></button></h3>
<p class="podcast-description" x-text="pod.metadata.description"></p>
<button @click="$store.podcasts.openResult(pod)" :disabled="$store.podcasts.busy" x-text="$store.podcasts.text(pod.subscribed?'open':'subscribe')"></button>
</article>
</template>
</div>
</section>
</template>
<template x-if="$store.library.searchResults.artists.length > 0">
<div class="search-section">
<h2 class="search-section-title">{{ t.player_artists }}</h2>
@@ -565,6 +551,16 @@
</template>
</div>
</template>
<template x-if="($store.library.searchResults.podcasts || []).length">
<section class="search-section">
<h2 class="search-section-title" x-text="$store.podcasts.text('podcasts')"></h2>
<div class="search-releases-row">
<template x-for="pod in $store.library.searchResults.podcasts" :key="pod.id">
{% include "player/podcast_search_card.html" %}
</template>
</div>
</section>
</template>
<div class="search-section federation-search-section"
:class="{ 'similarity-federation-merged': $store.library.similaritySearchLabel }">
<h2 class="search-section-title" x-show="!$store.library.similaritySearchLabel">
+85
View File
@@ -0,0 +1,85 @@
// Render first: FURU_PODCAST_RENDER_FIXTURE=1 cargo test renders_podcast_navigation_and_views
// Uses the real rendered application with isolated API/feed fixtures; no user data.
const {chromium}=require(process.env.PLAYWRIGHT_MODULE||'playwright');
const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict');
const root=path.resolve(__dirname,'..');
const html=fs.readFileSync(path.join(root,'target/podcast-player-fixture.html'),'utf8');
const alpinePath=process.env.ALPINE_FIXTURE||path.join(root,'target/podcast-alpine.min.js');
const cover='https://feeds.example.test/cover.svg';
const description='A long RSS description, shown only on the detail page. '.repeat(150);
const mine=[
{id:'pod1:own',metadata:{title:'A podcast about sound',author:'Sound studio',description,image_url:cover},episodes:2,new_episodes:1,shared:false},
{id:'pod1:broken',metadata:{title:'A missing cover',author:'Test publisher',image_url:'https://feeds.example.test/missing.jpg'},episodes:0,new_episodes:0,shared:false},
{id:'pod1:none',metadata:{title:'No RSS artwork',author:null},episodes:0,new_episodes:0,shared:false},
];
const publicPod={id:'pod1:public',url:'https://feeds.example.test/public.xml',metadata:{title:'Public podcast',author:'Another publisher',description,image_url:cover},subscribed:false};
const episode={id:'ep1:one',metadata:{title:'First episode',podcast_id:'pod1:own',published_at_ms:1700000000000,duration_ms:60000},cached:false,downloading:false,position_ms:0,completed:false,error:null};
(async()=>{
const browser=await chromium.launch({headless:true,...(process.env.CHROME_PATH?{executablePath:process.env.CHROME_PATH}:{})});
try{
const page=await browser.newPage({viewport:{width:1440,height:1000}}),errors=[],actions=[];
page.on('pageerror',error=>errors.push(error.message));
await page.route('**/*',async route=>{
const url=new URL(route.request().url());
if(url.hostname==='cdn.jsdelivr.net'&&url.pathname.includes('alpine')&&fs.existsSync(alpinePath))return route.fulfill({contentType:'application/javascript',body:fs.readFileSync(alpinePath,'utf8')});
if(url.hostname==='feeds.example.test')return url.pathname==='/cover.svg'?route.fulfill({contentType:'image/svg+xml',body:'<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400"><rect width="400" height="400" fill="#244d43"/><circle cx="200" cy="175" r="85" fill="#d8ba78"/><text x="200" y="315" text-anchor="middle" fill="white" font-family="sans-serif" font-size="32">SOUND</text></svg>'}):route.fulfill({status:404,body:''});
if(url.hostname==='podcast-ui.test'&&url.pathname==='/')return route.fulfill({contentType:'text/html',body:html});
if(url.pathname==='/api/podcasts/action'){
const body=route.request().postDataJSON();actions.push(body);
if(body.action==='list')return route.fulfill({json:{mine,public:[publicPod]}});
if(body.action==='episodes')return route.fulfill({json:{episodes:[{...episode,metadata:{...episode.metadata,podcast_id:body.id}}],has_more:false}});
if(body.action==='add'){mine.push({...publicPod,episodes:1,new_episodes:1,shared:false});publicPod.subscribed=true;return route.fulfill({json:{ok:true,id:publicPod.id}});}
return route.fulfill({json:{ok:true}});
}
if(url.pathname==='/api/player/search')return route.fulfill({json:{artists:[{id:1,name:'A musician',image_url:cover,release_count:1,track_count:1}],releases:[],tracks:[],podcasts:[publicPod,mine[0]]}});
if(url.pathname.startsWith('/api/'))return route.fulfill({json:[]});
if(url.hostname==='cdn.jsdelivr.net')return route.continue();
return route.fulfill({status:404,body:''});
});
const settled=async view=>{await page.waitForFunction(v=>window.Alpine?.store('library')?.view===v&&!Alpine.store('podcasts').loading,view);};
await page.goto('http://podcast-ui.test/#podcasts');await settled('podcasts');
assert.equal(await page.locator('.card-grid .podcast-tile').count(),4);
assert.equal(await page.locator('.podcast-description').count(),0);
await page.waitForFunction(()=>document.querySelector('.podcast-tile img')?.naturalWidth>0);
await page.waitForFunction(()=>Alpine.store('podcasts').failedArtwork['https://feeds.example.test/missing.jpg']);
assert.equal(await page.locator('.podcast-tile[title="A missing cover"] svg').count(),1);
await page.screenshot({path:path.join(root,'target/podcast-ui-grid.png')});
await page.locator('.podcast-tile[title="A podcast about sound"]').click();await settled('podcast_detail');
assert.ok(page.url().endsWith('#podcast?id=pod1%3Aown'));
await page.getByRole('heading',{name:'First episode',exact:true}).waitFor();
assert.equal(await page.locator('.podcast-detail > template').count(),1);
assert.ok((await page.locator('.podcast-detail .podcast-description').first().innerText()).length<400);
await page.screenshot({path:path.join(root,'target/podcast-ui-detail.png')});
await page.getByRole('button',{name:'Show more',exact:true}).click();
assert.equal(await page.locator('.podcast-detail .podcast-description').first().innerText(),description.trim());
await page.getByRole('button',{name:'Show less',exact:true}).click();
await page.reload();await settled('podcast_detail');
await page.getByRole('heading',{name:'First episode',exact:true}).waitFor();
await page.goBack();await settled('podcasts');
await page.locator('.podcast-tile[title="Public podcast"]').click();await settled('podcast_detail');
assert.equal(actions.filter(a=>a.action==='add').length,0);
await page.getByRole('button',{name:'Subscribe',exact:true}).click();
await page.getByRole('button',{name:'Publish',exact:true}).waitFor();
assert.equal(actions.filter(a=>a.action==='add').length,1);
await page.evaluate(()=>Alpine.store('library').search('sound'));
await page.locator('.search-release-card.podcast-tile').first().waitFor();
const headings=await page.locator('.search-section-title').allTextContents();
assert.ok(headings.indexOf('Artists')<headings.indexOf('Podcasts'));
assert.equal(await page.locator('.search-section .podcast-description').count(),0);
const size=await page.locator('.search-release-card.podcast-tile').first().boundingBox();assert.ok(size.height<240&&size.width<=150);
await page.screenshot({path:path.join(root,'target/podcast-ui-search.png')});
await page.setViewportSize({width:390,height:844});
await page.goto('http://podcast-ui.test/#podcasts');await settled('podcasts');
await page.screenshot({path:path.join(root,'target/podcast-ui-mobile.png')});
await page.locator('.podcast-tile[title="A podcast about sound"]').click();await settled('podcast_detail');
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);
await page.screenshot({path:path.join(root,'target/podcast-ui-mobile-detail.png')});
assert.deepEqual(errors,[]);
console.log('PASS: cold list/detail hashes, back navigation, RSS artwork/fallbacks, explicit subscribe, compact ordered search, desktop/mobile');
} finally {await browser.close();}
})().catch(error=>{console.error(error);process.exitCode=1;});
+37 -2
View File
@@ -4,7 +4,7 @@ const {test} = require('node:test');
const vm = require('node:vm');
const source = readFileSync(`${__dirname}/../templates/player/podcast_scripts.html`, 'utf8').replace(/<\/?script>/g, '');
function setup(responder=()=>({})) {
const calls=[],stores={library:{view:'artists',_beginNavigation(){}},mobile:{closeLibrary(){}},player:{_playLocal(track,options){this.currentTrack=track;this.options=options;},seek(){}}};
const calls=[],stores={library:{view:'artists',_beginNavigation(){},_afterNavigation(){}},mobile:{closeLibrary(){}},player:{_playLocal(track,options){this.currentTrack=track;this.options=options;},seek(){}}};
vm.runInNewContext(source,{
document:{documentElement:{lang:'ru'},addEventListener(_,fn){fn();}},
Alpine:{store(name,value){if(value)stores[name]=value;return stores[name];}},
@@ -74,7 +74,7 @@ test('opening podcast navigation starts polling and search results open existing
const {store,stores,calls}=setup(body=>body.action==='list'?{mine:[podcast],public:[]}:body.action==='episodes'?{episodes:[],has_more:false}:{});
await store.enter();assert.equal(store.poller,1);assert.equal(stores.library.view,'podcasts');
stores.library.view='search';await store.openResult(podcast);
assert.equal(stores.library.view,'podcasts');assert.equal(store.selected.id,'show');
assert.equal(stores.library.view,'podcast_detail');assert.equal(store.selected.id,'show');
assert.equal(calls.filter(c=>c.action==='add').length,0);
});
@@ -84,3 +84,38 @@ test('podcast search displays matching results instead of retaining unrelated pu
assert.deepEqual(Array.from(store.publicCards(),p=>p.id),['matching']);
store.resetSearch();assert.deepEqual(Array.from(store.publicCards(),p=>p.id),['unrelated']);
});
test('public podcast cards preview details without subscribing; only the subscribe button adds the feed',async()=>{
const pod={id:'public',url:'https://example.test/feed',metadata:{title:'Public',image_url:'https://example.test/cover.jpg'}};
let subscribed=false;
const {store,stores,calls}=setup(body=>{
if(body.action==='add'){subscribed=true;return {id:pod.id};}
if(body.action==='list')return {mine:subscribed?[pod]:[],public:[pod]};
return {episodes:[],has_more:false};
});
await store.open(pod);assert.equal(stores.library.view,'podcast_detail');
assert.equal(store.selected.subscribed,false);assert.equal(calls.filter(c=>c.action==='add').length,0);
assert.equal(calls.filter(c=>c.action==='episodes').length,0);
await store.subscribe();assert.equal(store.selected.subscribed,true);
assert.equal(calls.filter(c=>c.action==='add').length,1);assert.equal(calls.filter(c=>c.action==='episodes').length,1);
assert.equal(store.artwork(pod),pod.metadata.image_url);store.artworkFailed(pod);assert.equal(store.artwork(pod),null);
});
test('back navigation wins over a slow detail request',async()=>{
let finish;
const {store,stores}=setup(body=>body.action==='detail'?new Promise(resolve=>{finish=resolve;}):{mine:[],public:[]});
const opened=store.open('slow');while(!finish)await new Promise(resolve=>setImmediate(resolve));
await store.enter();finish({id:'slow',metadata:{title:'Old'}});await opened;
assert.equal(stores.library.view,'podcasts');assert.equal(store.selected,null);assert.equal(store.loading,false);
});
test('hash routing restores both the podcast list and a selected podcast',()=>{
const script=readFileSync(`${__dirname}/../templates/player/scripts.html`,'utf8');
const start=script.indexOf(' _navigateFromHash(options = {}) {');const end=script.indexOf(' _scrollElement()',start);
const calls=[],location={hash:'#podcasts'};
const context=vm.createContext({GUEST:false,location,URLSearchParams,Alpine:{store(){return {enter(options){calls.push(['list',options]);},open(id,options){calls.push(['detail',id,options]);}};}}});
const library=vm.runInContext('({'+script.slice(start,end)+'})',context);library.goArtists=()=>{throw Error('unexpected artist navigation');};
library._navigateFromHash({fromHash:true});assert.equal(calls[0][0],'list');assert.equal(calls[0][1].fromHash,true);
location.hash='#podcast?id='+encodeURIComponent('pod1:fixture');library._navigateFromHash({fromHash:true});
assert.equal(calls[1][0],'detail');assert.equal(calls[1][1],'pod1:fixture');
});