@simba-dev/react-native-media-player 2.0.1 → 3.0.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.
- package/README.md +317 -560
- package/android/src/main/cpp/main.cpp +117 -17
- package/android/src/main/java/com/simba/player/PipManager.kt +13 -0
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +177 -6
- package/android/src/main/java/com/simba/player/mpv/PipAutoEnterPolicy.kt +54 -0
- package/package.json +11 -2
- package/src/components/PlayerProvider.tsx +5 -5
- package/src/index.ts +25 -12
- package/android/src/test/java/com/simba/player/PipActionReceiverTest.kt +0 -123
- package/android/src/test/java/com/simba/player/PipManagerTest.kt +0 -281
- package/android/src/test/java/com/simba/player/TestApplication.kt +0 -26
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleNullInstanceTest.kt +0 -117
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -212
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewRegistryTest.kt +0 -120
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewTest.kt +0 -249
- package/scripts/override_react_methods.js +0 -184
- package/scripts/override_react_methods.py +0 -150
- package/src/bridge/__tests__/MpvPlayerModule.test.ts +0 -163
- package/src/bridge/__tests__/debugMode.test.ts +0 -138
- package/src/bridge/__tests__/errorContract.test.ts +0 -175
- package/src/bridge/__tests__/loadAndPlay.startPosition.test.tsx +0 -142
- package/src/components/PlayerRoot.tsx +0 -124
- package/src/components/PlayerSurface.tsx +0 -62
- package/src/components/__tests__/PlayerProvider.performance.test.tsx +0 -242
- package/src/components/__tests__/PlayerProvider.progressContext.test.tsx +0 -194
- package/src/components/__tests__/PlayerProvider.test.tsx +0 -558
- package/src/components/__tests__/PlayerRoot.test.tsx +0 -71
- package/src/components/__tests__/SimbaVideo.test.tsx +0 -164
- package/src/hooks/__tests__/resolveStreamType.test.ts +0 -159
- package/src/hooks/__tests__/useLaunchPlayback.test.tsx +0 -278
- package/src/hooks/__tests__/useResumeThumbnail.test.ts +0 -154
- package/src/stores/__tests__/playerQueueSelectionStore.test.ts +0 -73
- package/src/stores/__tests__/playerQueueStore.test.ts +0 -171
- package/src/types/__tests__/config.test.ts +0 -188
- package/src/types/__tests__/player.pipAnswer.test.tsx +0 -87
- package/src/types/__tests__/player.pipArity.test.tsx +0 -74
- package/src/types/__tests__/player.test.tsx +0 -1365
- package/src/types/__tests__/playerLoading.test.ts +0 -170
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for the public `captureFrame` wrapper
|
|
3
|
-
* (`src/hooks/useResumeThumbnail.ts`).
|
|
4
|
-
*
|
|
5
|
-
* What is testable at the JS level is the wrapper's own contract,
|
|
6
|
-
* not the extraction itself — the pixels come from
|
|
7
|
-
* `MediaMetadataRetriever` on a native background thread and are
|
|
8
|
-
* exercised on-device:
|
|
9
|
-
*
|
|
10
|
-
* - `null` (never a rejection) is passed through for "no frame
|
|
11
|
-
* available" — the live stream / unsupported container /
|
|
12
|
-
* unreachable URL / past-the-end cases,
|
|
13
|
-
* - a resolved absolute path is passed through unchanged,
|
|
14
|
-
* - programmer error rejects with the documented `E_*` codes
|
|
15
|
-
* BEFORE any bridge call happens,
|
|
16
|
-
* - omitted options are filled in with the poster-sized defaults,
|
|
17
|
-
* and the options object is ALWAYS sent (the codegen'd TurboModule
|
|
18
|
-
* signature is positional, so an absent 3rd argument is an arity
|
|
19
|
-
* hazard rather than a clean null),
|
|
20
|
-
* - a partial options object only overrides what it names.
|
|
21
|
-
*
|
|
22
|
-
* The bridge itself is the global `NativeModules.MpvPlayerModule`
|
|
23
|
-
* mock installed in `jest.setup.ts`; `getMpvPlayerModule()` returns
|
|
24
|
-
* that instance because the mock satisfies `resolveBridge()`.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { NativeModules } from 'react-native';
|
|
28
|
-
import {
|
|
29
|
-
captureFrame,
|
|
30
|
-
DEFAULT_FRAME_WIDTH,
|
|
31
|
-
DEFAULT_FRAME_HEIGHT,
|
|
32
|
-
DEFAULT_FRAME_QUALITY,
|
|
33
|
-
} from '../useResumeThumbnail';
|
|
34
|
-
|
|
35
|
-
const nativeCaptureFrame = NativeModules.MpvPlayerModule
|
|
36
|
-
.captureFrame as jest.Mock;
|
|
37
|
-
|
|
38
|
-
describe('captureFrame', () => {
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
nativeCaptureFrame.mockClear();
|
|
41
|
-
nativeCaptureFrame.mockResolvedValue(null);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('the null contract', () => {
|
|
45
|
-
it('resolves null without throwing when no frame is available', async () => {
|
|
46
|
-
await expect(captureFrame('https://cdn.test/a.mkv', 42_000)).resolves.toBeNull();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('does not reject — null is the documented fallback signal', async () => {
|
|
50
|
-
// A rejection here would force every consumer into a try/catch
|
|
51
|
-
// and would break the no-op bridge hosts (jest / web preview),
|
|
52
|
-
// which resolve null rather than throw.
|
|
53
|
-
const result = await captureFrame('file:///movies/a.mp4', 0).catch(
|
|
54
|
-
(e: unknown) => `rejected: ${String(e)}`,
|
|
55
|
-
);
|
|
56
|
-
expect(result).toBeNull();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('passes a resolved absolute path through unchanged', async () => {
|
|
60
|
-
const path = '/data/user/0/com.simba/files/simba-resume-thumbs/frame_1_30000.jpg';
|
|
61
|
-
nativeCaptureFrame.mockResolvedValue(path);
|
|
62
|
-
await expect(captureFrame('file:///movies/a.mp4', 31_000)).resolves.toBe(path);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('programmer errors', () => {
|
|
67
|
-
it('rejects a blank uri with E_INVALID_URI and never touches the bridge', async () => {
|
|
68
|
-
await expect(captureFrame(' ', 1000)).rejects.toMatchObject({
|
|
69
|
-
code: 'E_INVALID_URI',
|
|
70
|
-
});
|
|
71
|
-
expect(nativeCaptureFrame).not.toHaveBeenCalled();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('rejects a negative positionMs with E_INVALID_POSITION', async () => {
|
|
75
|
-
await expect(captureFrame('file:///a.mp4', -1)).rejects.toMatchObject({
|
|
76
|
-
code: 'E_INVALID_POSITION',
|
|
77
|
-
});
|
|
78
|
-
expect(nativeCaptureFrame).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it.each([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY])(
|
|
82
|
-
'rejects the non-finite positionMs %p',
|
|
83
|
-
async (bad) => {
|
|
84
|
-
await expect(captureFrame('file:///a.mp4', bad)).rejects.toMatchObject({
|
|
85
|
-
code: 'E_INVALID_POSITION',
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
it('accepts positionMs === 0 (start of media is a valid frame)', async () => {
|
|
91
|
-
await expect(captureFrame('file:///a.mp4', 0)).resolves.toBeNull();
|
|
92
|
-
expect(nativeCaptureFrame).toHaveBeenCalledTimes(1);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('options', () => {
|
|
97
|
-
it('applies the poster-sized defaults when options are omitted', async () => {
|
|
98
|
-
await captureFrame('file:///a.mp4', 5000);
|
|
99
|
-
expect(nativeCaptureFrame).toHaveBeenCalledWith('file:///a.mp4', 5000, {
|
|
100
|
-
width: DEFAULT_FRAME_WIDTH,
|
|
101
|
-
height: DEFAULT_FRAME_HEIGHT,
|
|
102
|
-
quality: DEFAULT_FRAME_QUALITY,
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('always sends an options object, even when none were supplied', async () => {
|
|
107
|
-
await captureFrame('file:///a.mp4', 5000);
|
|
108
|
-
const args = nativeCaptureFrame.mock.calls[0] as unknown[];
|
|
109
|
-
// The codegen'd TurboModule signature is
|
|
110
|
-
// (uri, positionMs, options, promise) — a missing 3rd argument is
|
|
111
|
-
// an arity mismatch on some RN versions, not a clean null.
|
|
112
|
-
expect(args).toHaveLength(3);
|
|
113
|
-
expect(args[2]).toEqual(expect.any(Object));
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('only overrides the fields the caller actually names', async () => {
|
|
117
|
-
await captureFrame('file:///a.mp4', 5000, { height: 720 });
|
|
118
|
-
expect(nativeCaptureFrame).toHaveBeenCalledWith('file:///a.mp4', 5000, {
|
|
119
|
-
width: DEFAULT_FRAME_WIDTH,
|
|
120
|
-
height: 720,
|
|
121
|
-
quality: DEFAULT_FRAME_QUALITY,
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('forwards an explicit width of 0 (the aspect-preserving escape hatch)', async () => {
|
|
126
|
-
await captureFrame('file:///portrait.mp4', 5000, { width: 0 });
|
|
127
|
-
expect(nativeCaptureFrame).toHaveBeenCalledWith(
|
|
128
|
-
'file:///portrait.mp4',
|
|
129
|
-
5000,
|
|
130
|
-
expect.objectContaining({ width: 0 }),
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('floors a fractional positionMs before crossing the bridge', async () => {
|
|
135
|
-
await captureFrame('file:///a.mp4', 1234.99);
|
|
136
|
-
expect(nativeCaptureFrame).toHaveBeenCalledWith(
|
|
137
|
-
'file:///a.mp4',
|
|
138
|
-
1234,
|
|
139
|
-
expect.any(Object),
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe('the defaults themselves', () => {
|
|
145
|
-
it('uses a 16:9 box and a sane JPEG quality', () => {
|
|
146
|
-
// 640x360 is exactly 16:9, so landscape sources scale without
|
|
147
|
-
// distortion; quality 80 keeps a rail-sized frame in the tens of
|
|
148
|
-
// kB rather than the hundreds.
|
|
149
|
-
expect(DEFAULT_FRAME_WIDTH / DEFAULT_FRAME_HEIGHT).toBeCloseTo(16 / 9, 5);
|
|
150
|
-
expect(DEFAULT_FRAME_HEIGHT).toBe(360);
|
|
151
|
-
expect(DEFAULT_FRAME_QUALITY).toBe(80);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for `src/stores/playerQueueSelectionStore.ts`.
|
|
3
|
-
*
|
|
4
|
-
* The selection store holds the indices of queue items the
|
|
5
|
-
* user has multi-tapped, plus two pure helpers that return the
|
|
6
|
-
* indices sorted for batch ops (`removeSelected` descending,
|
|
7
|
-
* `moveSelectedToTop` ascending). Pinning these prevents the
|
|
8
|
-
* "sort order flipped" regression that would silently corrupt
|
|
9
|
-
* the queue array when the caller iterates `removeSelected`'s
|
|
10
|
-
* output in order to splice.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {usePlayerQueueSelectionStore} from '../playerQueueSelectionStore';
|
|
14
|
-
|
|
15
|
-
describe('playerQueueSelectionStore', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
usePlayerQueueSelectionStore.setState({selectedIndices: []});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('setSelection replaces the selection array', () => {
|
|
21
|
-
usePlayerQueueSelectionStore.getState().setSelection([1, 3, 5]);
|
|
22
|
-
expect(usePlayerQueueSelectionStore.getState().selectedIndices).toEqual([
|
|
23
|
-
1, 3, 5,
|
|
24
|
-
]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('clearSelection empties the selection', () => {
|
|
28
|
-
usePlayerQueueSelectionStore.getState().setSelection([0, 1]);
|
|
29
|
-
usePlayerQueueSelectionStore.getState().clearSelection();
|
|
30
|
-
expect(usePlayerQueueSelectionStore.getState().selectedIndices).toEqual(
|
|
31
|
-
[],
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('removeSelected returns indices sorted DESCENDING', () => {
|
|
36
|
-
usePlayerQueueSelectionStore.getState().setSelection([3, 1, 5]);
|
|
37
|
-
expect(usePlayerQueueSelectionStore.getState().removeSelected()).toEqual([
|
|
38
|
-
5, 3, 1,
|
|
39
|
-
]);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('removeSelected does not mutate the stored selection', () => {
|
|
43
|
-
usePlayerQueueSelectionStore.getState().setSelection([2, 0, 4]);
|
|
44
|
-
usePlayerQueueSelectionStore.getState().removeSelected();
|
|
45
|
-
expect(usePlayerQueueSelectionStore.getState().selectedIndices).toEqual([
|
|
46
|
-
2, 0, 4,
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('moveSelectedToTop returns indices sorted ASCENDING', () => {
|
|
51
|
-
usePlayerQueueSelectionStore.getState().setSelection([4, 1, 3]);
|
|
52
|
-
expect(
|
|
53
|
-
usePlayerQueueSelectionStore.getState().moveSelectedToTop(),
|
|
54
|
-
).toEqual([1, 3, 4]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('moveSelectedToTop does not mutate the stored selection', () => {
|
|
58
|
-
usePlayerQueueSelectionStore.getState().setSelection([4, 1, 3]);
|
|
59
|
-
usePlayerQueueSelectionStore.getState().moveSelectedToTop();
|
|
60
|
-
expect(usePlayerQueueSelectionStore.getState().selectedIndices).toEqual([
|
|
61
|
-
4, 1, 3,
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('handles empty selection gracefully', () => {
|
|
66
|
-
expect(usePlayerQueueSelectionStore.getState().removeSelected()).toEqual(
|
|
67
|
-
[],
|
|
68
|
-
);
|
|
69
|
-
expect(
|
|
70
|
-
usePlayerQueueSelectionStore.getState().moveSelectedToTop(),
|
|
71
|
-
).toEqual([]);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for `src/stores/playerQueueStore.ts`.
|
|
3
|
-
*
|
|
4
|
-
* The queue store is a pure zustand store. Its actions are
|
|
5
|
-
* synchronous, side-effect-free, and operate on a local array —
|
|
6
|
-
* no React, no bridge. This file pins the public surface
|
|
7
|
-
* (add/prepend/remove/reorder/clear/shuffle + history) so that
|
|
8
|
-
* V14/V15/V16 phase renames (e.g. `playFromQueue` →
|
|
9
|
-
* `removeFromQueueByIndex` in Phase 72) don't silently regress.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import {usePlayerQueueStore, type PlayerQueueItem} from '../playerQueueStore';
|
|
13
|
-
|
|
14
|
-
const sample = (overrides: Partial<PlayerQueueItem> = {}): PlayerQueueItem => ({
|
|
15
|
-
uri: `file:///sample-${Math.random().toString(36).slice(2)}.mp4`,
|
|
16
|
-
title: 'Sample',
|
|
17
|
-
duration: 1000,
|
|
18
|
-
...overrides,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('playerQueueStore', () => {
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
// Reset between tests — the store is module-level, so its state
|
|
24
|
-
// persists across tests within a single jest worker.
|
|
25
|
-
usePlayerQueueStore.setState({queue: [], playbackHistory: []});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('queue actions', () => {
|
|
29
|
-
it('addToQueue appends to the tail', () => {
|
|
30
|
-
const a = sample({title: 'A'});
|
|
31
|
-
const b = sample({title: 'B'});
|
|
32
|
-
usePlayerQueueStore.getState().addToQueue(a);
|
|
33
|
-
usePlayerQueueStore.getState().addToQueue(b);
|
|
34
|
-
const {queue} = usePlayerQueueStore.getState();
|
|
35
|
-
expect(queue).toHaveLength(2);
|
|
36
|
-
expect(queue[0]).toEqual(a);
|
|
37
|
-
expect(queue[1]).toEqual(b);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('prependToQueue inserts at the head', () => {
|
|
41
|
-
const a = sample({title: 'A'});
|
|
42
|
-
const b = sample({title: 'B'});
|
|
43
|
-
usePlayerQueueStore.getState().addToQueue(a);
|
|
44
|
-
usePlayerQueueStore.getState().prependToQueue(b);
|
|
45
|
-
const {queue} = usePlayerQueueStore.getState();
|
|
46
|
-
expect(queue.map(i => i.title)).toEqual(['B', 'A']);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('removeFromQueue splices the item at the index', () => {
|
|
50
|
-
const a = sample({title: 'A'});
|
|
51
|
-
const b = sample({title: 'B'});
|
|
52
|
-
const c = sample({title: 'C'});
|
|
53
|
-
usePlayerQueueStore.setState({queue: [a, b, c]});
|
|
54
|
-
usePlayerQueueStore.getState().removeFromQueue(1);
|
|
55
|
-
expect(usePlayerQueueStore.getState().queue.map(i => i.title)).toEqual([
|
|
56
|
-
'A',
|
|
57
|
-
'C',
|
|
58
|
-
]);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('removeFromQueue is a no-op for out-of-range indices', () => {
|
|
62
|
-
const a = sample({title: 'A'});
|
|
63
|
-
usePlayerQueueStore.setState({queue: [a]});
|
|
64
|
-
usePlayerQueueStore.getState().removeFromQueue(-1);
|
|
65
|
-
usePlayerQueueStore.getState().removeFromQueue(99);
|
|
66
|
-
expect(usePlayerQueueStore.getState().queue).toHaveLength(1);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('reorderQueue accepts the positional (fromIndex, toIndex) shape', () => {
|
|
70
|
-
const a = sample({title: 'A'});
|
|
71
|
-
const b = sample({title: 'B'});
|
|
72
|
-
const c = sample({title: 'C'});
|
|
73
|
-
usePlayerQueueStore.setState({queue: [a, b, c]});
|
|
74
|
-
usePlayerQueueStore.getState().reorderQueue(0, 2);
|
|
75
|
-
expect(usePlayerQueueStore.getState().queue.map(i => i.title)).toEqual([
|
|
76
|
-
'B',
|
|
77
|
-
'C',
|
|
78
|
-
'A',
|
|
79
|
-
]);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('reorderQueue accepts the {fromIndex, toIndex} object shape', () => {
|
|
83
|
-
const a = sample({title: 'A'});
|
|
84
|
-
const b = sample({title: 'B'});
|
|
85
|
-
const c = sample({title: 'C'});
|
|
86
|
-
usePlayerQueueStore.setState({queue: [a, b, c]});
|
|
87
|
-
usePlayerQueueStore.getState().reorderQueue({fromIndex: 2, toIndex: 0});
|
|
88
|
-
expect(usePlayerQueueStore.getState().queue.map(i => i.title)).toEqual([
|
|
89
|
-
'C',
|
|
90
|
-
'A',
|
|
91
|
-
'B',
|
|
92
|
-
]);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('reorderQueue is a no-op when fromIndex === toIndex or out of range', () => {
|
|
96
|
-
const a = sample({title: 'A'});
|
|
97
|
-
const b = sample({title: 'B'});
|
|
98
|
-
usePlayerQueueStore.setState({queue: [a, b]});
|
|
99
|
-
usePlayerQueueStore.getState().reorderQueue(0, 0);
|
|
100
|
-
usePlayerQueueStore.getState().reorderQueue(-1, 0);
|
|
101
|
-
usePlayerQueueStore.getState().reorderQueue(0, 5);
|
|
102
|
-
expect(usePlayerQueueStore.getState().queue.map(i => i.title)).toEqual([
|
|
103
|
-
'A',
|
|
104
|
-
'B',
|
|
105
|
-
]);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('clearQueue empties the queue but preserves history', () => {
|
|
109
|
-
const a = sample({title: 'A'});
|
|
110
|
-
usePlayerQueueStore.getState().addToQueue(a);
|
|
111
|
-
usePlayerQueueStore.getState().addToPlaybackHistory(a);
|
|
112
|
-
usePlayerQueueStore.getState().clearQueue();
|
|
113
|
-
const {queue, playbackHistory} = usePlayerQueueStore.getState();
|
|
114
|
-
expect(queue).toEqual([]);
|
|
115
|
-
expect(playbackHistory).toHaveLength(1);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('shuffleQueue permutes the queue in place', () => {
|
|
119
|
-
const items = Array.from({length: 10}, (_, i) => sample({title: `T${i}`}));
|
|
120
|
-
usePlayerQueueStore.setState({queue: items});
|
|
121
|
-
usePlayerQueueStore.getState().shuffleQueue();
|
|
122
|
-
const {queue} = usePlayerQueueStore.getState();
|
|
123
|
-
// Same elements, just reordered
|
|
124
|
-
expect(queue.map(i => i.title).sort()).toEqual(
|
|
125
|
-
items.map(i => i.title).sort(),
|
|
126
|
-
);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('removeFromQueueByIndex (Phase 72 rename of playFromQueue) splices the queue', () => {
|
|
130
|
-
const a = sample({title: 'A'});
|
|
131
|
-
const b = sample({title: 'B'});
|
|
132
|
-
const c = sample({title: 'C'});
|
|
133
|
-
usePlayerQueueStore.setState({queue: [a, b, c]});
|
|
134
|
-
usePlayerQueueStore.getState().removeFromQueueByIndex(1);
|
|
135
|
-
expect(usePlayerQueueStore.getState().queue.map(i => i.title)).toEqual([
|
|
136
|
-
'A',
|
|
137
|
-
'C',
|
|
138
|
-
]);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('removeFromQueueByIndex is a no-op for invalid index', () => {
|
|
142
|
-
const a = sample({title: 'A'});
|
|
143
|
-
usePlayerQueueStore.setState({queue: [a]});
|
|
144
|
-
usePlayerQueueStore.getState().removeFromQueueByIndex(99);
|
|
145
|
-
expect(usePlayerQueueStore.getState().queue).toHaveLength(1);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('playback history', () => {
|
|
150
|
-
it('addToPlaybackHistory appends to the tail', () => {
|
|
151
|
-
const a = sample({title: 'A'});
|
|
152
|
-
const b = sample({title: 'B'});
|
|
153
|
-
usePlayerQueueStore.getState().addToPlaybackHistory(a);
|
|
154
|
-
usePlayerQueueStore.getState().addToPlaybackHistory(b);
|
|
155
|
-
const {playbackHistory} = usePlayerQueueStore.getState();
|
|
156
|
-
expect(playbackHistory).toHaveLength(2);
|
|
157
|
-
expect(playbackHistory[0]).toEqual(a);
|
|
158
|
-
expect(playbackHistory[1]).toEqual(b);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('clearPlaybackHistory empties the history but preserves queue', () => {
|
|
162
|
-
const a = sample({title: 'A'});
|
|
163
|
-
usePlayerQueueStore.getState().addToQueue(a);
|
|
164
|
-
usePlayerQueueStore.getState().addToPlaybackHistory(a);
|
|
165
|
-
usePlayerQueueStore.getState().clearPlaybackHistory();
|
|
166
|
-
const {queue, playbackHistory} = usePlayerQueueStore.getState();
|
|
167
|
-
expect(playbackHistory).toEqual([]);
|
|
168
|
-
expect(queue).toHaveLength(1);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for `src/types/config.ts` — the public configuration API.
|
|
3
|
-
*
|
|
4
|
-
* Spec §Phase 34 covers:
|
|
5
|
-
* - 34.5 PlayerProvider applies config — exercised in
|
|
6
|
-
* `PlayerProvider.test.tsx`. Here we test the resolver logic
|
|
7
|
-
* directly: `resolvePlayerConfig` is the pure function that
|
|
8
|
-
* PlayerProvider delegates to.
|
|
9
|
-
*
|
|
10
|
-
* Why this is the foundation test file:
|
|
11
|
-
* - `resolvePlayerConfig` is the most-pure, most-testable function
|
|
12
|
-
* in the module (no React, no bridge, no async).
|
|
13
|
-
* - The defaults (`DEFAULT_THEME`, `DEFAULT_PLAYER_CONFIG`) are the
|
|
14
|
-
* contract that every consumer app implicitly relies on. Pinning
|
|
15
|
-
* them prevents accidental breaking changes.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
DEFAULT_PLAYER_CONFIG,
|
|
20
|
-
DEFAULT_THEME,
|
|
21
|
-
resolvePlayerConfig,
|
|
22
|
-
} from '../config';
|
|
23
|
-
import type { PlayerConfig } from '../config';
|
|
24
|
-
|
|
25
|
-
describe('resolvePlayerConfig', () => {
|
|
26
|
-
it('returns full defaults when called with undefined', () => {
|
|
27
|
-
const resolved = resolvePlayerConfig(undefined);
|
|
28
|
-
expect(resolved).toEqual(DEFAULT_PLAYER_CONFIG);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('returns full defaults when called with empty object', () => {
|
|
32
|
-
const resolved = resolvePlayerConfig({});
|
|
33
|
-
expect(resolved).toEqual(DEFAULT_PLAYER_CONFIG);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('preserves top-level theme overrides', () => {
|
|
37
|
-
const resolved = resolvePlayerConfig({
|
|
38
|
-
theme: { accent: '#FF00FF' },
|
|
39
|
-
});
|
|
40
|
-
expect(resolved.theme.accent).toBe('#FF00FF');
|
|
41
|
-
// Other theme fields fall back to DEFAULT_THEME.
|
|
42
|
-
expect(resolved.theme.background).toBe(DEFAULT_THEME.background);
|
|
43
|
-
expect(resolved.theme.text).toBe(DEFAULT_THEME.text);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('preserves nested pip config', () => {
|
|
47
|
-
const resolved = resolvePlayerConfig({
|
|
48
|
-
pip: { enabled: false, autoEnterOnLeave: false },
|
|
49
|
-
});
|
|
50
|
-
expect(resolved.pip).toEqual({ enabled: false, autoEnterOnLeave: false });
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('preserves audio config', () => {
|
|
54
|
-
const resolved = resolvePlayerConfig({
|
|
55
|
-
audio: { backgroundPlayback: false, respectAudioFocus: false },
|
|
56
|
-
});
|
|
57
|
-
expect(resolved.audio).toEqual({
|
|
58
|
-
backgroundPlayback: false,
|
|
59
|
-
respectAudioFocus: false,
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('preserves hardwareDecoding union type', () => {
|
|
64
|
-
const cases: Array<PlayerConfig['hardwareDecoding']> = [
|
|
65
|
-
'auto',
|
|
66
|
-
'mediacodec',
|
|
67
|
-
'no',
|
|
68
|
-
];
|
|
69
|
-
for (const value of cases) {
|
|
70
|
-
const resolved = resolvePlayerConfig({ hardwareDecoding: value });
|
|
71
|
-
expect(resolved.hardwareDecoding).toBe(value);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('preserves notifications config', () => {
|
|
76
|
-
const resolved = resolvePlayerConfig({
|
|
77
|
-
notifications: { enabled: true, channelId: 'my_app_media' },
|
|
78
|
-
});
|
|
79
|
-
expect(resolved.notifications).toEqual({
|
|
80
|
-
enabled: true,
|
|
81
|
-
channelId: 'my_app_media',
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('preserves subtitle config', () => {
|
|
86
|
-
const resolved = resolvePlayerConfig({
|
|
87
|
-
subtitle: { preferredLanguages: ['en', 'es'], fontSize: 22 },
|
|
88
|
-
});
|
|
89
|
-
expect(resolved.subtitle.preferredLanguages).toEqual(['en', 'es']);
|
|
90
|
-
expect(resolved.subtitle.fontSize).toBe(22);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('preserves debug config', () => {
|
|
94
|
-
const resolved = resolvePlayerConfig({ debug: { verboseLogging: true } });
|
|
95
|
-
expect(resolved.debug.verboseLogging).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('merges partial config without mutating the input', () => {
|
|
99
|
-
// Spec §Phase 34.5: PlayerProvider must not mutate the consumer's
|
|
100
|
-
// config object — defensive against React re-renders that pass the
|
|
101
|
-
// same prop reference.
|
|
102
|
-
const config: PlayerConfig = {
|
|
103
|
-
theme: { accent: '#ABCDEF' },
|
|
104
|
-
};
|
|
105
|
-
const before = JSON.stringify(config);
|
|
106
|
-
resolvePlayerConfig(config);
|
|
107
|
-
const after = JSON.stringify(config);
|
|
108
|
-
expect(after).toBe(before);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('returns an object that passes structural equality', () => {
|
|
112
|
-
// The PlayerProvider uses `JSON.stringify(resolved)` as the
|
|
113
|
-
// dependency key for its `useEffect`. Verify that two equivalent
|
|
114
|
-
// configs produce identical JSON.
|
|
115
|
-
const a = resolvePlayerConfig({ pip: { enabled: false } });
|
|
116
|
-
const b = resolvePlayerConfig({ pip: { enabled: false } });
|
|
117
|
-
expect(JSON.stringify(a)).toBe(JSON.stringify(b));
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('returns a value that is structurally equal to DEFAULT_PLAYER_CONFIG for empty input', () => {
|
|
121
|
-
// The current implementation always returns a fresh object even
|
|
122
|
-
// when called with `{}` or `undefined` — there's no reference-
|
|
123
|
-
// equality shortcut. PlayerProvider's setConfig effect therefore
|
|
124
|
-
// runs once on mount regardless. We pin the contract here so a
|
|
125
|
-
// future optimisation (returning DEFAULT_PLAYER_CONFIG by
|
|
126
|
-
// reference for empty input) is a deliberate choice, not an
|
|
127
|
-
// accidental side effect.
|
|
128
|
-
const resolved = resolvePlayerConfig({});
|
|
129
|
-
expect(resolved).toStrictEqual(DEFAULT_PLAYER_CONFIG);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('DEFAULT_THEME', () => {
|
|
134
|
-
it('exposes the documented dark theme', () => {
|
|
135
|
-
// Lock the values so consumers can rely on them (and so the
|
|
136
|
-
// a consumer's visual baseline doesn't drift accidentally).
|
|
137
|
-
// `icon` is intentionally absent — it's an optional override in
|
|
138
|
-
// PlayerTheme (see types/config.ts).
|
|
139
|
-
expect(DEFAULT_THEME).toEqual({
|
|
140
|
-
accent: '#FFD700',
|
|
141
|
-
background: '#121216',
|
|
142
|
-
text: '#FFFFFF',
|
|
143
|
-
textSecondary: 'rgba(255,255,255,0.6)',
|
|
144
|
-
surface: 'rgba(255,255,255,0.1)',
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('all colors are strings (no undefined)', () => {
|
|
149
|
-
for (const [key, value] of Object.entries(DEFAULT_THEME)) {
|
|
150
|
-
expect(typeof value).toBe('string');
|
|
151
|
-
expect(value.length).toBeGreaterThan(0);
|
|
152
|
-
// Use the value so jest doesn't warn about unused.
|
|
153
|
-
void key;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('DEFAULT_PLAYER_CONFIG', () => {
|
|
159
|
-
it('every documented sub-config is populated', () => {
|
|
160
|
-
// Lock the shape — a refactor that drops a sub-config would
|
|
161
|
-
// silently break consumers expecting the field.
|
|
162
|
-
// Note: the defaults match resolvePlayerConfig's hard-coded
|
|
163
|
-
// defaults in src/types/config.ts. If those defaults change, both
|
|
164
|
-
// this test and the implementation must change together.
|
|
165
|
-
expect(DEFAULT_PLAYER_CONFIG).toEqual({
|
|
166
|
-
theme: DEFAULT_THEME,
|
|
167
|
-
pip: { enabled: true, autoEnterOnLeave: true },
|
|
168
|
-
audio: { backgroundPlayback: true, respectAudioFocus: true },
|
|
169
|
-
subtitle: { preferredLanguages: [], fontSize: 16 },
|
|
170
|
-
notifications: { enabled: true, channelId: 'simba_player_media' },
|
|
171
|
-
hardwareDecoding: 'auto',
|
|
172
|
-
debug: { verboseLogging: false },
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('pip is enabled by default (opt-out is the design)', () => {
|
|
177
|
-
// V12 spec: PiP is on by default; consumers explicitly disable it.
|
|
178
|
-
expect(DEFAULT_PLAYER_CONFIG.pip.enabled).toBe(true);
|
|
179
|
-
expect(DEFAULT_PLAYER_CONFIG.pip.autoEnterOnLeave).toBe(true);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('audio backgroundPlayback is ON by default (matches Spotify / Apple Music)', () => {
|
|
183
|
-
// V12 spec: matches AudioConfig.backgroundPlayback's docstring —
|
|
184
|
-
// opt-out is the design so audio apps behave like mainstream
|
|
185
|
-
// players out of the box.
|
|
186
|
-
expect(DEFAULT_PLAYER_CONFIG.audio.backgroundPlayback).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The PiP command must RELAY the OS's answer.
|
|
3
|
-
*
|
|
4
|
-
* ## The defect
|
|
5
|
-
*
|
|
6
|
-
* The native `enterPip` returned `Unit` and swallowed every failure:
|
|
7
|
-
*
|
|
8
|
-
* - no activity → silent `return`
|
|
9
|
-
* - SDK < N → silent `return`
|
|
10
|
-
* - `enterPictureInPictureMode` returned false → the boolean was DISCARDED
|
|
11
|
-
* - it threw → caught, logged, swallowed
|
|
12
|
-
*
|
|
13
|
-
* A REFUSED PiP request was therefore indistinguishable from a successful
|
|
14
|
-
* one, at the JS boundary.
|
|
15
|
-
*
|
|
16
|
-
* That matters because of what the caller does with the request. The app
|
|
17
|
-
* suppresses its fullscreen chrome when PiP is up, so a refused request
|
|
18
|
-
* that went unreported left the app in "PiP" mode with no transport bar, no
|
|
19
|
-
* top bar, and no way out — the same latch the unmount bug produced,
|
|
20
|
-
* reached by a different road.
|
|
21
|
-
*
|
|
22
|
-
* `Activity.enterPictureInPictureMode(PictureInPictureParams)` returns the
|
|
23
|
-
* OS's own answer, so the fix is to stop throwing it away.
|
|
24
|
-
*
|
|
25
|
-
* ## What this asserts
|
|
26
|
-
*
|
|
27
|
-
* The RESULT, not just that the bridge was called. A test that only checked
|
|
28
|
-
* "enterPip was called" would pass with the old `void` contract and the
|
|
29
|
-
* bug would survive — which is exactly the mistake the arity test
|
|
30
|
-
* (`player.pipArity.test.tsx`) was written to avoid.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import {NativeModules} from 'react-native';
|
|
34
|
-
import {renderHook} from '@testing-library/react-native';
|
|
35
|
-
import {usePlayer} from '../player';
|
|
36
|
-
|
|
37
|
-
function enterPipMock(): jest.Mock {
|
|
38
|
-
return (NativeModules.MpvPlayerModule as unknown as Record<string, jest.Mock>)
|
|
39
|
-
.enterPip;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('commands.enterPip — the native answer is relayed', () => {
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
enterPipMock().mockClear();
|
|
45
|
-
// The shared setup mock answers `true` (a successful entry). Each
|
|
46
|
-
// test that cares sets the answer it needs.
|
|
47
|
-
enterPipMock().mockReturnValue(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('returns true when the OS accepted the request', async () => {
|
|
51
|
-
const {result} = await renderHook(() => usePlayer());
|
|
52
|
-
|
|
53
|
-
expect(result.current.commands.enterPip()).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('returns false when the OS REFUSED the request', async () => {
|
|
57
|
-
// No activity, PiP not permitted, bad params — the native side now
|
|
58
|
-
// answers `false` instead of swallowing the failure.
|
|
59
|
-
enterPipMock().mockReturnValue(false);
|
|
60
|
-
const {result} = await renderHook(() => usePlayer());
|
|
61
|
-
|
|
62
|
-
expect(result.current.commands.enterPip()).toBe(false);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('does not swallow a refusal — the result is the caller\'s only signal', async () => {
|
|
66
|
-
enterPipMock().mockReturnValue(false);
|
|
67
|
-
const {result} = await renderHook(() => usePlayer());
|
|
68
|
-
|
|
69
|
-
const answer = result.current.commands.enterPip();
|
|
70
|
-
|
|
71
|
-
// A falsy-but-present answer is what the caller branches on. A
|
|
72
|
-
// `undefined` (the old `void` contract) is indistinguishable from
|
|
73
|
-
// "the native module is missing", so the assertion is on `false`
|
|
74
|
-
// specifically, not on falsiness.
|
|
75
|
-
expect(answer).not.toBeUndefined();
|
|
76
|
-
expect(answer).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('still calls the bridge with TWO arguments while answering', async () => {
|
|
80
|
-
const {result} = await renderHook(() => usePlayer());
|
|
81
|
-
result.current.commands.enterPip('Chapter 3', '45 %');
|
|
82
|
-
|
|
83
|
-
const enterPip = enterPipMock();
|
|
84
|
-
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
85
|
-
expect(enterPip).toHaveBeenCalledWith('Chapter 3', '45 %');
|
|
86
|
-
});
|
|
87
|
-
});
|