feat(web-ui): pass the media error to MediaPlayer onError
onError now receives the element's MediaError, so an app can tell an unsupported source (code 4, MEDIA_ERR_SRC_NOT_SUPPORTED, as with AVI, WMV or ASF) from other failures. Handlers that take no argument are unaffected. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
170c7570e4
commit
5745995a34
2 files changed
+45
-2
No files matched your search
@@ -111,6 +111,44 @@ describe('MediaPlayer speed', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('MediaPlayer errors', () => {
|
||||
// MEDIA_ERR_SRC_NOT_SUPPORTED: the browser cannot demux or decode the source.
|
||||
const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
|
||||
|
||||
it('passes the element error to onError so an unsupported source can be told apart', async () => {
|
||||
const onError = vi.fn();
|
||||
render(MediaPlayer, { props: { kind: 'video', src: SOURCE, title: 'Clip', onError } });
|
||||
const element = videoElement();
|
||||
Object.defineProperty(element, 'error', { configurable: true, value: { code: MEDIA_ERR_SRC_NOT_SUPPORTED } });
|
||||
|
||||
await fireEvent.error(element);
|
||||
|
||||
expect(onError).toHaveBeenCalledTimes(1);
|
||||
expect(onError.mock.calls[0][0]).toMatchObject({ code: MEDIA_ERR_SRC_NOT_SUPPORTED });
|
||||
});
|
||||
|
||||
it('passes null when the element reports no error object', async () => {
|
||||
const onError = vi.fn();
|
||||
render(MediaPlayer, { props: { kind: 'video', src: SOURCE, title: 'Clip', onError } });
|
||||
|
||||
await fireEvent.error(videoElement());
|
||||
|
||||
expect(onError).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
it('reports audio sources the same way as video', async () => {
|
||||
const onError = vi.fn();
|
||||
render(MediaPlayer, { props: { kind: 'audio', src: 'https://media.example/track.wma', title: 'Track', onError } });
|
||||
const element = document.querySelector<HTMLAudioElement>('audio');
|
||||
if (!element) throw new Error('no audio element');
|
||||
Object.defineProperty(element, 'error', { configurable: true, value: { code: MEDIA_ERR_SRC_NOT_SUPPORTED } });
|
||||
|
||||
await fireEvent.error(element);
|
||||
|
||||
expect(onError.mock.calls[0][0]).toMatchObject({ code: MEDIA_ERR_SRC_NOT_SUPPORTED });
|
||||
});
|
||||
});
|
||||
|
||||
describe('MediaPlayer without controls', () => {
|
||||
it('renders the element with no player controls and leaves its src to the caller', () => {
|
||||
render(MediaPlayer, { props: { controls: false, kind: 'video' } });
|
||||
|
||||
Reference in new issue
Block a user