From e4841afbaaf2aa63eeb8a80891dbf262791f26bf Mon Sep 17 00:00:00 2001 From: Asger Geel Weirsoee Date: Mon, 2 Mar 2026 03:49:29 +0000 Subject: [PATCH] test(issue-268): lock phone audio guard against playback regressions --- .../src/app/i18n-mvp-flow-smoke.spec.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/angular/src/app/i18n-mvp-flow-smoke.spec.ts b/frontend/angular/src/app/i18n-mvp-flow-smoke.spec.ts index 144fa3d..26adc77 100644 --- a/frontend/angular/src/app/i18n-mvp-flow-smoke.spec.ts +++ b/frontend/angular/src/app/i18n-mvp-flow-smoke.spec.ts @@ -38,7 +38,10 @@ describe('i18n MVP flow smoke (host/player + audio policy)', () => { host.ngOnDestroy(); }); - it('keeps audio routing policy primary-only (client has no audio output)', () => { + it('keeps audio routing policy primary-only (client has no audio output)', async () => { + const originalPlay = vi.fn().mockRejectedValue(new Error('original play')); + const mediaPrototype = { play: originalPlay }; + vi.stubGlobal('window', { location: { hash: '', search: '' }, history: { state: null, replaceState: vi.fn() }, @@ -46,16 +49,25 @@ describe('i18n MVP flow smoke (host/player + audio policy)', () => { sessionStorage: { getItem: vi.fn().mockReturnValue(null), setItem: vi.fn(), removeItem: vi.fn() }, addEventListener: vi.fn(), removeEventListener: vi.fn(), + HTMLMediaElement: { prototype: mediaPrototype }, }); vi.stubGlobal('navigator', { language: 'en-US', onLine: true }); + vi.stubGlobal('document', { querySelectorAll: vi.fn().mockReturnValue([]) }); const host = new HostShellComponent(); - const player = new PlayerShellComponent(); + host.ngOnInit(); - expect(host.clientHasNoAudioOutput).toBe(true); - expect(player.clientHasNoAudioOutput).toBe(true); + await expect(mediaPrototype.play()).rejects.toThrow('original play'); + + const player = new PlayerShellComponent(); + player.ngOnInit(); + + await expect(mediaPrototype.play()).resolves.toBeUndefined(); player.ngOnDestroy(); + + await expect(mediaPrototype.play()).rejects.toThrow('original play'); + host.ngOnDestroy(); }); });