From bfa865c55c90295e1968990e43d45cfa155a922f Mon Sep 17 00:00:00 2001 From: 4gray Date: Fri, 19 Jun 2026 21:00:22 +0200 Subject: [PATCH] test(xtream): cover live auto-open state reset --- ...ive-stream-auto-open-state.service.spec.ts | 38 +++++++++++++++++++ .../live-stream-auto-open-state.service.ts | 3 ++ .../live-stream-layout.component.ts | 3 ++ 3 files changed, 44 insertions(+) create mode 100644 libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.spec.ts diff --git a/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.spec.ts b/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.spec.ts new file mode 100644 index 000000000..7f02f3b67 --- /dev/null +++ b/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.spec.ts @@ -0,0 +1,38 @@ +import { LiveStreamAutoOpenStateService } from './live-stream-auto-open-state.service'; + +describe('LiveStreamAutoOpenStateService', () => { + let service: LiveStreamAutoOpenStateService; + + beforeEach(() => { + service = new LiveStreamAutoOpenStateService(); + window.history.replaceState({}, document.title); + }); + + afterEach(() => { + window.history.replaceState({}, document.title); + }); + + it('captures a positive live item id from history state', () => { + window.history.replaceState( + { openXtreamLiveItemId: 101 }, + document.title + ); + + service.captureFromHistoryState(); + + expect(service.pendingItemId()).toBe(101); + }); + + it('clears the pending item id when history state has no live item id', () => { + window.history.replaceState( + { openXtreamLiveItemId: 101 }, + document.title + ); + service.captureFromHistoryState(); + + window.history.replaceState({}, document.title); + service.captureFromHistoryState(); + + expect(service.pendingItemId()).toBeNull(); + }); +}); diff --git a/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.ts b/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.ts index f4365ac9c..a7450527b 100644 --- a/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.ts +++ b/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-auto-open-state.service.ts @@ -12,7 +12,10 @@ export class LiveStreamAutoOpenStateService { ); if (Number.isFinite(requestedItemId) && requestedItemId > 0) { this.pendingItemId.set(requestedItemId); + return; } + + this.pendingItemId.set(null); } clearPendingItem(): void { diff --git a/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-layout.component.ts b/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-layout.component.ts index 2ae5a6402..cf5d8078e 100644 --- a/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-layout.component.ts +++ b/libs/portal/xtream/feature/src/lib/live-stream-layout/live-stream-layout.component.ts @@ -376,6 +376,9 @@ export class LiveStreamLayoutComponent implements OnInit, OnDestroy { startPlayback = !this.settingsStore.openStreamOnDoubleClick() ) { const streamUrl = this.xtreamStore.constructStreamUrl(item); + // Keep both root/recently-added playback and same-category replays in + // sync with the category rail. For already-selected channels this is a + // store no-op. this.selectLiveItemCategory(item); this.activePlayback.set({ streamUrl,