@simba-dev/react-native-media-player 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +317 -560
  2. package/android/src/main/cpp/main.cpp +117 -17
  3. package/android/src/main/java/com/simba/player/PipManager.kt +13 -0
  4. package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +187 -8
  5. package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +11 -1
  6. package/android/src/main/java/com/simba/player/mpv/MpvRenderViewRegistry.kt +132 -0
  7. package/android/src/main/java/com/simba/player/mpv/PipAutoEnterPolicy.kt +54 -0
  8. package/android/src/main/java/com/simba/player/mpv/PlayerSurface.kt +41 -1
  9. package/package.json +11 -2
  10. package/src/bridge/MpvPlayerModule.ts +7 -1
  11. package/src/bridge/NativeMpvPlayer.ts +3 -3
  12. package/src/types/player.ts +7 -1
  13. package/android/src/test/java/com/simba/player/PipActionReceiverTest.kt +0 -123
  14. package/android/src/test/java/com/simba/player/PipManagerTest.kt +0 -281
  15. package/android/src/test/java/com/simba/player/TestApplication.kt +0 -26
  16. package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleNullInstanceTest.kt +0 -117
  17. package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -212
  18. package/android/src/test/java/com/simba/player/mpv/MpvRenderViewTest.kt +0 -249
  19. package/scripts/override_react_methods.js +0 -184
  20. package/scripts/override_react_methods.py +0 -150
  21. package/src/bridge/__tests__/MpvPlayerModule.test.ts +0 -110
  22. package/src/bridge/__tests__/debugMode.test.ts +0 -138
  23. package/src/bridge/__tests__/errorContract.test.ts +0 -175
  24. package/src/bridge/__tests__/loadAndPlay.startPosition.test.tsx +0 -142
  25. package/src/components/__tests__/PlayerProvider.performance.test.tsx +0 -242
  26. package/src/components/__tests__/PlayerProvider.progressContext.test.tsx +0 -194
  27. package/src/components/__tests__/PlayerProvider.test.tsx +0 -558
  28. package/src/components/__tests__/PlayerRoot.test.tsx +0 -71
  29. package/src/components/__tests__/SimbaVideo.test.tsx +0 -164
  30. package/src/hooks/__tests__/resolveStreamType.test.ts +0 -159
  31. package/src/hooks/__tests__/useLaunchPlayback.test.tsx +0 -278
  32. package/src/hooks/__tests__/useResumeThumbnail.test.ts +0 -154
  33. package/src/stores/__tests__/playerQueueSelectionStore.test.ts +0 -73
  34. package/src/stores/__tests__/playerQueueStore.test.ts +0 -171
  35. package/src/types/__tests__/config.test.ts +0 -188
  36. package/src/types/__tests__/player.pipAnswer.test.tsx +0 -87
  37. package/src/types/__tests__/player.pipArity.test.tsx +0 -74
  38. package/src/types/__tests__/player.test.tsx +0 -1365
  39. package/src/types/__tests__/playerLoading.test.ts +0 -170
@@ -1,558 +0,0 @@
1
- /**
2
- * Unit tests for `src/components/PlayerProvider.tsx`.
3
- *
4
- * Spec §Phase 34:
5
- * - 34.5 PlayerProvider applies config — covered below.
6
- *
7
- * Test surface:
8
- * - usePlayerConfig returns the resolved config (with defaults
9
- * applied)
10
- * - usePlayerConfig throws outside provider (programmer-error guard)
11
- * - useTheme returns the theme slice (with defaults)
12
- * - useTheme throws outside provider
13
- * - useRenderControls returns null when no renderControls prop is
14
- * provided, the provided function otherwise
15
- * - useRenderControls does NOT throw outside provider (falls back to
16
- * null so a consumer's controls can render)
17
- * - Provider passes resolved config to native bridge via setConfig
18
- * on mount and when the config prop changes
19
- * - Provider does NOT call setConfig when config prop is reference-
20
- * equal but unchanged
21
- *
22
- * The MpvPlayerModule bridge mock is installed globally in
23
- * `jest.setup.ts` (it extends the @react-native/jest-preset's own
24
- * `NativeModules` mock rather than overriding it).
25
- */
26
-
27
- import React from 'react';
28
- import { NativeModules, Text } from 'react-native';
29
- import { act, render, renderHook } from '@testing-library/react-native';
30
- import {
31
- PlayerProvider,
32
- usePlayerConfig,
33
- useTheme,
34
- useRenderControls,
35
- } from '../PlayerProvider';
36
- import { DEFAULT_PLAYER_CONFIG, DEFAULT_THEME } from '../../types/config';
37
- import {usePlayer, usePlayerProgress} from '../../types/player';
38
-
39
- // Helper to clear all bridge mock call counts between tests.
40
- function clearBridgeMocks() {
41
- for (const key of Object.keys(NativeModules.MpvPlayerModule)) {
42
- const fn = (NativeModules.MpvPlayerModule as Record<string, jest.Mock>)[key];
43
- if (typeof fn?.mockClear === 'function') {
44
- fn.mockClear();
45
- }
46
- }
47
- }
48
-
49
- // ── usePlayerConfig ──────────────────────────────────────────────────────
50
-
51
- describe('usePlayerConfig inside PlayerProvider', () => {
52
- it('returns the resolved config', async () => {
53
- const wrapper = ({ children }: { children: React.ReactNode }) => (
54
- <PlayerProvider>{children}</PlayerProvider>
55
- );
56
- const { result } = await renderHook(() => usePlayerConfig(), { wrapper });
57
- expect(result.current).toEqual(DEFAULT_PLAYER_CONFIG);
58
- });
59
-
60
- it('returns a config with overrides applied', async () => {
61
- const wrapper = ({ children }: { children: React.ReactNode }) => (
62
- <PlayerProvider config={{ theme: { accent: '#FF0000' } }}>
63
- {children}
64
- </PlayerProvider>
65
- );
66
- const { result } = await renderHook(() => usePlayerConfig(), { wrapper });
67
- expect(result.current.theme.accent).toBe('#FF0000');
68
- // Other theme fields fall back to DEFAULT_THEME.
69
- expect(result.current.theme.background).toBe(DEFAULT_THEME.background);
70
- });
71
-
72
- it('full config override is reflected in the context', async () => {
73
- const wrapper = ({ children }: { children: React.ReactNode }) => (
74
- <PlayerProvider
75
- config={{
76
- pip: { enabled: false, autoEnterOnLeave: false },
77
- audio: { backgroundPlayback: true, respectAudioFocus: false },
78
- }}
79
- >
80
- {children}
81
- </PlayerProvider>
82
- );
83
- const { result } = await renderHook(() => usePlayerConfig(), { wrapper });
84
- expect(result.current.pip.enabled).toBe(false);
85
- expect(result.current.audio.backgroundPlayback).toBe(true);
86
- });
87
- });
88
-
89
- describe('usePlayerConfig outside PlayerProvider', () => {
90
- it('throws a clear error message', async () => {
91
- // Spec: programmer-error guard. Without a provider, the hook
92
- // throws — we want the message to mention PlayerProvider so the
93
- // consumer can self-diagnose.
94
- const consoleErrorSpy = jest
95
- .spyOn(console, 'error')
96
- .mockImplementation(() => {});
97
- await expect(renderHook(() => usePlayerConfig())).rejects.toThrow(
98
- /PlayerProvider/,
99
- );
100
- consoleErrorSpy.mockRestore();
101
- });
102
- });
103
-
104
- // ── useTheme ─────────────────────────────────────────────────────────────
105
-
106
- describe('useTheme inside PlayerProvider', () => {
107
- it('returns the theme slice of the resolved config', async () => {
108
- const wrapper = ({ children }: { children: React.ReactNode }) => (
109
- <PlayerProvider>{children}</PlayerProvider>
110
- );
111
- const { result } = await renderHook(() => useTheme(), { wrapper });
112
- expect(result.current).toEqual(DEFAULT_THEME);
113
- });
114
-
115
- it('reflects theme overrides', async () => {
116
- const wrapper = ({ children }: { children: React.ReactNode }) => (
117
- <PlayerProvider config={{ theme: { accent: '#123456' } }}>
118
- {children}
119
- </PlayerProvider>
120
- );
121
- const { result } = await renderHook(() => useTheme(), { wrapper });
122
- expect(result.current.accent).toBe('#123456');
123
- });
124
- });
125
-
126
- describe('useTheme outside PlayerProvider', () => {
127
- it('throws a clear error message', async () => {
128
- const consoleErrorSpy = jest
129
- .spyOn(console, 'error')
130
- .mockImplementation(() => {});
131
- await expect(renderHook(() => useTheme())).rejects.toThrow(/PlayerProvider/);
132
- consoleErrorSpy.mockRestore();
133
- });
134
- });
135
-
136
- // ── useRenderControls ────────────────────────────────────────────────────
137
-
138
- describe('useRenderControls', () => {
139
- it('returns null when no renderControls prop is provided', async () => {
140
- const wrapper = ({ children }: { children: React.ReactNode }) => (
141
- <PlayerProvider>{children}</PlayerProvider>
142
- );
143
- const { result } = await renderHook(() => useRenderControls(), { wrapper });
144
- expect(result.current).toBeNull();
145
- });
146
-
147
- it('returns the provided renderControls function', async () => {
148
- const myRenderControls = () => <Text>custom</Text>;
149
- const wrapper = ({ children }: { children: React.ReactNode }) => (
150
- <PlayerProvider renderControls={myRenderControls}>
151
- {children}
152
- </PlayerProvider>
153
- );
154
- const { result } = await renderHook(() => useRenderControls(), { wrapper });
155
- expect(result.current).toBe(myRenderControls);
156
- });
157
-
158
- it('returns null when called outside a provider (does NOT throw)', async () => {
159
- // Important behavioural difference from usePlayerConfig/useTheme:
160
- // useRenderControls is non-throwing so a consumer's controls can render
161
- // unconditionally. (If a consumer renders their own controls
162
- // without a Provider, they get no chrome, not a crash.)
163
- const { result } = await renderHook(() => useRenderControls());
164
- expect(result.current).toBeNull();
165
- });
166
- });
167
-
168
- // ── setConfig bridge call ────────────────────────────────────────────────
169
-
170
- describe('PlayerProvider → native bridge', () => {
171
- beforeEach(() => {
172
- clearBridgeMocks();
173
- });
174
-
175
- it('calls setConfig on mount', async () => {
176
- await render(
177
- <PlayerProvider config={{ pip: { enabled: false } }}>
178
- <Text>child</Text>
179
- </PlayerProvider>,
180
- );
181
- expect(NativeModules.MpvPlayerModule.setConfig).toHaveBeenCalled();
182
- // The first arg is the JSON-stringified ResolvedPlayerConfig.
183
- const callArgs = (
184
- NativeModules.MpvPlayerModule.setConfig as jest.Mock
185
- ).mock.calls[0];
186
- expect(typeof callArgs[0]).toBe('string');
187
- const parsed = JSON.parse(callArgs[0]);
188
- expect(parsed.pip.enabled).toBe(false);
189
- });
190
-
191
- it('calls setConfig when the config prop changes', async () => {
192
- const { rerender } = await render(
193
- <PlayerProvider config={{ pip: { enabled: true } }}>
194
- <Text>child</Text>
195
- </PlayerProvider>,
196
- );
197
- (NativeModules.MpvPlayerModule.setConfig as jest.Mock).mockClear();
198
-
199
- await rerender(
200
- <PlayerProvider config={{ pip: { enabled: false } }}>
201
- <Text>child</Text>
202
- </PlayerProvider>,
203
- );
204
- expect(NativeModules.MpvPlayerModule.setConfig).toHaveBeenCalledTimes(1);
205
- const parsed = JSON.parse(
206
- (NativeModules.MpvPlayerModule.setConfig as jest.Mock).mock.calls[0][0],
207
- );
208
- expect(parsed.pip.enabled).toBe(false);
209
- });
210
-
211
- it('calls setConfig with the resolved config (not the partial input)', async () => {
212
- // Phase 21 design: Provider always sends a fully-resolved config
213
- // to the native side so the Kotlin layer never has to merge
214
- // defaults. Verify the bridge receives the resolved shape.
215
- await render(
216
- <PlayerProvider config={{ theme: { accent: '#ABCDEF' } }}>
217
- <Text>child</Text>
218
- </PlayerProvider>,
219
- );
220
- const callArgs = (
221
- NativeModules.MpvPlayerModule.setConfig as jest.Mock
222
- ).mock.calls[0];
223
- const parsed = JSON.parse(callArgs[0]);
224
- // The accent override is present …
225
- expect(parsed.theme.accent).toBe('#ABCDEF');
226
- // … and so are the other defaults (proving the merge happened).
227
- expect(parsed.theme.background).toBe(DEFAULT_THEME.background);
228
- expect(parsed.pip.enabled).toBe(true);
229
- });
230
-
231
- it('does not crash when JSON.stringify is given a non-circular config', async () => {
232
- // Smoke test: confirm the setConfig path completes without
233
- // throwing. (A test for circular-reference behaviour is out of
234
- // scope for Phase 34 — see Phase 39 hardening.)
235
- const consoleWarnSpy = jest
236
- .spyOn(console, 'warn')
237
- .mockImplementation(() => {});
238
- await render(
239
- <PlayerProvider>
240
- <Text>child</Text>
241
- </PlayerProvider>,
242
- );
243
- expect(NativeModules.MpvPlayerModule.setConfig).toHaveBeenCalled();
244
- consoleWarnSpy.mockRestore();
245
- });
246
- });
247
-
248
- // ── Children rendering ───────────────────────────────────────────────────
249
-
250
- describe('PlayerProvider renders children', () => {
251
- it('renders children inside the provider tree', async () => {
252
- const { getByText } = await render(
253
- <PlayerProvider>
254
- <Text>hello world</Text>
255
- </PlayerProvider>,
256
- );
257
- expect(getByText('hello world')).toBeTruthy();
258
- });
259
-
260
- it('does NOT wrap children in an extra View (transparent wrapper)', async () => {
261
- // PlayerProvider is two stacked context Providers around the
262
- // children — no View, no styling. Verifying this prevents a
263
- // regression where someone wraps children in a <View
264
- // style={{ flex: 1 }}> which would break layouts that put
265
- // PlayerProvider inside a flex container expecting a transparent
266
- // wrapper. We assert the parent is NOT a 'View' element.
267
- const { getByText } = await render(
268
- <PlayerProvider>
269
- <Text>child-only</Text>
270
- </PlayerProvider>,
271
- );
272
- const textNode = getByText('child-only');
273
- // The Text has a parent (the inner Context.Provider's fragment),
274
- // but that parent is a Context.Provider host, NOT a View. If a
275
- // future refactor accidentally wraps children in <View>, the
276
- // parent type will be 'View' and this assertion will fail.
277
- expect(textNode.parent?.type).not.toBe('View');
278
- });
279
- });
280
-
281
- // -- mpv property observation (regression) --------------------------------
282
-
283
- /**
284
- * Regression origin: nothing in the library or the consumer app ever
285
- * called `observeProperty`. mpv only reports a property through
286
- * `mpv_observe_property`, so every branch of the native
287
- * `onMpvPropertyChanged` handler was unreachable and the state it feeds
288
- * kept its `DEFAULT_PROGRESS` value forever.
289
- *
290
- * Position / duration / volume / speed masked the bug because they are
291
- * ALSO polled at 1 Hz. `seekable`, `isSeeking`, `isBuffering` and
292
- * `cacheRanges` have no such fallback, so in the consumer app the seek
293
- * bar rendered permanently disabled ("Live stream - not seekable"), the
294
- * buffering spinner never appeared, and the buffered-range fill was
295
- * never painted - on a plain, seekable, 1-hour file.
296
- */
297
- describe('mpv property observation', () => {
298
- const wrapper = ({ children }: { children: React.ReactNode }) => (
299
- <PlayerProvider>{children}</PlayerProvider>
300
- );
301
-
302
- it('observes every property that backs an event with no polling fallback', async () => {
303
- clearBridgeMocks();
304
- const { unmount } = await renderHook(() => usePlayerProgress(), { wrapper });
305
-
306
- const observed = (
307
- NativeModules.MpvPlayerModule.observeProperty as jest.Mock
308
- ).mock.calls.map((call: unknown[]) => call[0]);
309
-
310
- // These are the ones that are invisible until they are wrong:
311
- // nothing polls them, so a missing registration is silent.
312
- //
313
- // `mute` is in this group for a measured reason. `PlayerState
314
- // .isMuted` is documented as "`onPropertyChanged('mute')` +
315
- // hydration" and `applyPlayerEvent` really does handle
316
- // `case 'mute'` — but mpv only emits PROPERTY_CHANGE for names
317
- // passed to `mpv_observe_property`, and `mute` was not one of them.
318
- // So `commands.setMuted(true)` muted the audio while no event ever
319
- // reached JS, `state.isMuted` stayed `false`, and a mute button
320
- // rendered from that state looked inert: the glyph never changed
321
- // and the label never changed. Found on device (emulator-5554)
322
- // with SIMBA W8.3 — tapping "Mute" left the accessible label
323
- // reading "Mute".
324
- //
325
- // Hydration did not save it: `hydratePlayerState` reads
326
- // `getMuted()` once, which covers a cold start but not a provider
327
- // that mounts mid-session. Hence the separate level seed as well.
328
- expect(observed).toEqual(
329
- expect.arrayContaining([
330
- 'seekable',
331
- 'seeking',
332
- 'paused-for-cache',
333
- 'demuxer-cache-state',
334
- 'mute',
335
- // v1.9.3 — the title gap. `PlayerState.title` is documented as
336
- // coming from mpv `media-title`, and `applyPlayerEvent` handles
337
- // both `case 'media-title'` and `case 'metadata'` — but neither
338
- // name was ever registered, so no event could ever arrive and
339
- // every consumer rendered the DEFAULT_STATE placeholder
340
- // "Simba Player" regardless of what was playing.
341
- //
342
- // Mutation-check: comment either line out and this assertion is
343
- // the thing that fails.
344
- 'media-title',
345
- 'metadata',
346
- ]),
347
- );
348
-
349
- await unmount();
350
- });
351
-
352
- it('seeds `mute` as a LEVEL at mount, not only from the event stream', async () => {
353
- // SPEC invariant I10: an edge-triggered event is not a level. mpv
354
- // fires PROPERTY_CHANGE when `mute` CHANGES, so a provider mounted
355
- // while the player is already muted never sees the event — the same
356
- // gap that left `seekable` stuck at its default until W7 read it
357
- // once at mount.
358
- //
359
- // The test emits NO event and still expects the correct value, which
360
- // is the only shape that proves a SEED exists. A test that emits
361
- // the event would pass whether or not the seed is there.
362
- clearBridgeMocks();
363
- (NativeModules.MpvPlayerModule.getProperty as jest.Mock).mockImplementation(
364
- (name: string) => (name === 'mute' ? 'true' : 'null'),
365
- );
366
-
367
- const { result, unmount } = await renderHook(() => usePlayer(), {
368
- wrapper,
369
- });
370
-
371
- expect(result.current.state.isMuted).toBe(true);
372
-
373
- await unmount();
374
- });
375
-
376
- it('does not coerce a non-boolean `mute` property to false', async () => {
377
- // The bridge serialises MPV_FORMAT_FLAG to the JSON literals
378
- // `true` / `false`. Anything else — "null" for an unavailable
379
- // property, "" for the NOOP bridge — is not a value, and coercing it
380
- // to `false` would silently claim the player is unmuted when it may
381
- // not be. This is the same guard the `seekable` seed has.
382
- clearBridgeMocks();
383
- (NativeModules.MpvPlayerModule.getProperty as jest.Mock).mockImplementation(
384
- () => 'null',
385
- );
386
-
387
- const { result, unmount } = await renderHook(() => usePlayer(), {
388
- wrapper,
389
- });
390
-
391
- expect(result.current.state.isMuted).toBe(false);
392
-
393
- await unmount();
394
- });
395
-
396
- it('observes the properties that back the polled events too', async () => {
397
- // Lower latency than the 1 Hz poll, and `pause` / `eof-reached` are
398
- // only reachable this way for a state change that happens between
399
- // two polls.
400
- clearBridgeMocks();
401
- const { unmount } = await renderHook(() => usePlayerProgress(), { wrapper });
402
-
403
- const observed = (
404
- NativeModules.MpvPlayerModule.observeProperty as jest.Mock
405
- ).mock.calls.map((call: unknown[]) => call[0]);
406
-
407
- expect(observed).toEqual(
408
- expect.arrayContaining([
409
- 'time-pos',
410
- 'duration',
411
- 'volume',
412
- 'speed',
413
- 'pause',
414
- 'eof-reached',
415
- 'idle-active',
416
- 'cache-buffering-state',
417
- ]),
418
- );
419
-
420
- await unmount();
421
- });
422
-
423
- it('unobserves every property it registered, on unmount', async () => {
424
- clearBridgeMocks();
425
- const { unmount } = await renderHook(() => usePlayerProgress(), { wrapper });
426
-
427
- const observed = (
428
- NativeModules.MpvPlayerModule.observeProperty as jest.Mock
429
- ).mock.calls.map((call: unknown[]) => call[0]);
430
-
431
- await unmount();
432
-
433
- const unobserved = (
434
- NativeModules.MpvPlayerModule.unobserveProperty as jest.Mock
435
- ).mock.calls.map((call: unknown[]) => call[0]);
436
-
437
- // Leaving a registration behind means mpv keeps writing into a
438
- // callback whose React state is gone.
439
- expect(unobserved.sort()).toEqual(observed.sort());
440
- });
441
-
442
- it('keeps the last known cache ranges when a refresh returns empty', async () => {
443
- clearBridgeMocks();
444
- const { result, unmount } = await renderHook(() => usePlayerProgress(), {
445
- wrapper,
446
- });
447
-
448
- // DEFAULT_PROGRESS starts with no ranges; nothing has been emitted.
449
- expect(result.current.cacheRanges).toEqual([]);
450
-
451
- await unmount();
452
- });
453
- });
454
-
455
- // -- `seekable` is edge-only, so mount must read the level -----------------
456
-
457
- /**
458
- * mpv delivers `seekable` as a LEVEL value but only reports it as an
459
- * EDGE: MPV_EVENT_PROPERTY_CHANGE fires once, at the instant the flag
460
- * flips. A provider that mounts after that flip never sees the event.
461
- *
462
- * Measured on device, that meant `progress.seekable` stayed false
463
- * forever and every consumer's seek bar rendered permanently disabled
464
- * on ordinary seekable files. `onCacheState` — which changes
465
- * continuously — arrived 827 times over the same window, which is what
466
- * proved the subscription path itself was fine and isolated the fault
467
- * to the missed edge.
468
- *
469
- * These tests pin the compensating level read. They use NO emitted
470
- * event at all: the provider must know `seekable` on its own.
471
- */
472
- describe('PlayerProvider seekable seeding', () => {
473
- const seekableProp = (
474
- NativeModules.MpvPlayerModule as unknown as {
475
- getProperty: jest.Mock;
476
- }
477
- ).getProperty;
478
-
479
- const wrapper = ({ children }: { children: React.ReactNode }) => (
480
- <PlayerProvider>{children}</PlayerProvider>
481
- );
482
-
483
- beforeEach(() => {
484
- clearBridgeMocks();
485
- seekableProp.mockReturnValue('');
486
- });
487
-
488
- afterEach(() => {
489
- seekableProp.mockReturnValue('');
490
- });
491
-
492
- it('reads seekable at mount even though no event was ever emitted', async () => {
493
- // The regression: the flag is already true in mpv, but the edge was
494
- // consumed before this provider existed.
495
- seekableProp.mockImplementation((name: string) =>
496
- name === 'seekable' ? 'true' : 'null',
497
- );
498
-
499
- const { result, unmount } = await renderHook(() => usePlayerProgress(), {
500
- wrapper,
501
- });
502
-
503
- expect(result.current.seekable).toBe(true);
504
- // And it must be read, not inferred.
505
- expect(seekableProp).toHaveBeenCalledWith('seekable');
506
-
507
- await unmount();
508
- });
509
-
510
- it('leaves seekable false when mpv reports it false', async () => {
511
- seekableProp.mockImplementation((name: string) =>
512
- name === 'seekable' ? 'false' : 'null',
513
- );
514
-
515
- const { result, unmount } = await renderHook(() => usePlayerProgress(), {
516
- wrapper,
517
- });
518
-
519
- expect(result.current.seekable).toBe(false);
520
-
521
- await unmount();
522
- });
523
-
524
- it('does not coerce an unreadable property into a value', async () => {
525
- // `getProperty` returns "" on the NOOP bridge and "null" from the
526
- // native side for an unavailable property. Neither is a boolean,
527
- // and silently mapping them to false would be a guess - the same
528
- // class of defect as inventing a title. They must simply be
529
- // ignored, leaving DEFAULT_PROGRESS in place.
530
- seekableProp.mockReturnValue('null');
531
-
532
- const { result, unmount } = await renderHook(() => usePlayerProgress(), {
533
- wrapper,
534
- });
535
-
536
- expect(result.current.seekable).toBe(false);
537
- expect(result.current.cacheRanges).toEqual([]);
538
-
539
- await unmount();
540
- });
541
-
542
- it('survives a bridge whose getProperty throws', async () => {
543
- // Hydration is best-effort everywhere else in this effect, so the
544
- // seed must not be the one call that takes the provider down.
545
- seekableProp.mockImplementation(() => {
546
- throw new Error('no mpv instance yet');
547
- });
548
-
549
- const { result, unmount } = await renderHook(() => usePlayerProgress(), {
550
- wrapper,
551
- });
552
-
553
- expect(result.current).toBeDefined();
554
- expect(result.current.seekable).toBe(false);
555
-
556
- await unmount();
557
- });
558
- });
@@ -1,71 +0,0 @@
1
- /**
2
- * Unit tests for `src/components/PlayerRoot.tsx`.
3
- *
4
- * v2.0.0 (the app's register item 28) — **the library draws no chrome.**
5
- *
6
- * `DefaultControls` was removed, so `<PlayerRoot>` has no fallback: with
7
- * no `renderControls`, it renders the surface and NOTHING else. Before
8
- * 2.0.0 it fell back to a 564-line control bundle the library shipped,
9
- * which meant the library always had a chrome implementation a consumer
10
- * could end up using by accident.
11
- *
12
- * Test surface:
13
- * - no `renderControls` → the surface, and no second child
14
- * - `renderControls` → the consumer's controls, over the surface
15
- * - the package does not export a default control bundle
16
- *
17
- * The first test is the "must not" test: it fails if a chrome fallback
18
- * ever comes back, because a fallback is a second child of the root.
19
- */
20
-
21
- import React from 'react';
22
- import { Text } from 'react-native';
23
- import { render, screen } from '@testing-library/react-native';
24
- import { PlayerRoot } from '../PlayerRoot';
25
- import { PlayerProvider } from '../PlayerProvider';
26
-
27
- describe('PlayerRoot', () => {
28
- it('renders the surface and nothing else when the consumer supplies no controls', async () => {
29
- await render(
30
- <PlayerProvider>
31
- <PlayerRoot />
32
- </PlayerProvider>,
33
- );
34
-
35
- const tree = screen.toJSON();
36
- expect(tree).not.toBeNull();
37
-
38
- // The host tree is a plain View tree, so the root is the tree's
39
- // root node. `children` is typed loosely on purpose: the
40
- // `test-renderer` version has changed this shape before.
41
- const root = tree as unknown as { type: string; children: unknown };
42
- expect(root.type).toBe('View');
43
-
44
- // Exactly ONE child: the surface. A chrome fallback would be a
45
- // second child, and this is what kills the mutation.
46
- const children = Array.isArray(root.children) ? root.children : [];
47
- expect(children).toHaveLength(1);
48
- });
49
-
50
- it('renders the controls the consumer supplied, over the surface', async () => {
51
- await render(
52
- <PlayerProvider renderControls={() => <Text>my controls</Text>}>
53
- <PlayerRoot />
54
- </PlayerProvider>,
55
- );
56
-
57
- expect(screen.getByText('my controls')).toBeTruthy();
58
-
59
- const tree = screen.toJSON();
60
- expect(tree).not.toBeNull();
61
- const root = tree as unknown as { children: unknown };
62
- const children = Array.isArray(root.children) ? root.children : [];
63
- expect(children).toHaveLength(2);
64
- });
65
-
66
- it('does not export a default control bundle', async () => {
67
- const lib = require('../../index') as Record<string, unknown>;
68
- expect(Object.keys(lib)).not.toContain('DefaultControls');
69
- expect(lib.DefaultControls).toBeUndefined();
70
- });
71
- });