@simba-dev/react-native-media-player 1.22.0 → 2.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/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +25 -3
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +3 -4
- package/src/bridge/NativeMpvPlayer.ts +19 -0
- package/src/components/PlayerProvider.tsx +72 -43
- package/src/components/PlayerRoot.tsx +23 -46
- package/src/components/PlayerSurface.tsx +27 -37
- package/src/components/SimbaVideo.tsx +20 -10
- package/src/components/__tests__/PlayerProvider.test.tsx +4 -4
- package/src/components/__tests__/PlayerRoot.test.tsx +71 -0
- package/src/index.ts +19 -5
- package/src/types/__tests__/config.test.ts +1 -1
- package/src/types/__tests__/player.test.tsx +6 -6
- package/src/types/player.ts +3 -3
- package/src/components/DefaultControls.tsx +0 -564
- package/src/components/__tests__/DefaultControls.test.tsx +0 -253
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for `src/components/DefaultControls.tsx`.
|
|
3
|
-
*
|
|
4
|
-
* Spec §Phase 34.7: Test DefaultControls renders correctly.
|
|
5
|
-
*
|
|
6
|
-
* Test surface:
|
|
7
|
-
* - Renders inside a PlayerProvider without crashing
|
|
8
|
-
* - Top bar shows the title (from prop) and subtitle
|
|
9
|
-
* - Transport buttons are present (skip back, play/pause, skip forward)
|
|
10
|
-
* - Play/pause button toggles based on state.isPlaying
|
|
11
|
-
* - Skip buttons call the bridge
|
|
12
|
-
* - Close button calls onPause (or commands.pause fallback)
|
|
13
|
-
* - formatTime is correctly applied for the time labels
|
|
14
|
-
*
|
|
15
|
-
* What we DON'T test (deferred):
|
|
16
|
-
* - PanResponder drag-to-seek (Phase 39 instrumented test)
|
|
17
|
-
* - Auto-hide opacity tween (Phase 39 — needs fake timers + Animated
|
|
18
|
-
* mock with manual frame advancement)
|
|
19
|
-
* - Scrubber position-to-time math (covered indirectly via the
|
|
20
|
-
* positionFromX logic in the source; pure-function tests for
|
|
21
|
-
* that math live in Phase 39 if/when we extract it).
|
|
22
|
-
*
|
|
23
|
-
* The MpvPlayerModule bridge mock is installed globally in
|
|
24
|
-
* `jest.setup.ts`.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import React from 'react';
|
|
28
|
-
import { NativeModules } from 'react-native';
|
|
29
|
-
import { fireEvent, render } from '@testing-library/react-native';
|
|
30
|
-
import { PlayerProvider } from '../PlayerProvider';
|
|
31
|
-
import { DefaultControls } from '../DefaultControls';
|
|
32
|
-
|
|
33
|
-
// Helper to clear all bridge mock call counts between tests.
|
|
34
|
-
function clearBridgeMocks() {
|
|
35
|
-
for (const key of Object.keys(NativeModules.MpvPlayerModule)) {
|
|
36
|
-
const fn = (NativeModules.MpvPlayerModule as Record<string, jest.Mock>)[key];
|
|
37
|
-
if (typeof fn?.mockClear === 'function') {
|
|
38
|
-
fn.mockClear();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe('DefaultControls', () => {
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
clearBridgeMocks();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// ── Renders ───────────────────────────────────────────────────────────
|
|
49
|
-
|
|
50
|
-
it('renders without crashing inside a PlayerProvider', async () => {
|
|
51
|
-
const { getByLabelText } = await render(
|
|
52
|
-
<PlayerProvider>
|
|
53
|
-
<DefaultControls />
|
|
54
|
-
</PlayerProvider>,
|
|
55
|
-
);
|
|
56
|
-
expect(getByLabelText('Simba Player controls')).toBeTruthy();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders the top bar close button', async () => {
|
|
60
|
-
const { getByLabelText } = await render(
|
|
61
|
-
<PlayerProvider>
|
|
62
|
-
<DefaultControls />
|
|
63
|
-
</PlayerProvider>,
|
|
64
|
-
);
|
|
65
|
-
expect(getByLabelText('Close player')).toBeTruthy();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('renders the skip-back and skip-forward transport buttons', async () => {
|
|
69
|
-
const { getByLabelText } = await render(
|
|
70
|
-
<PlayerProvider>
|
|
71
|
-
<DefaultControls />
|
|
72
|
-
</PlayerProvider>,
|
|
73
|
-
);
|
|
74
|
-
expect(getByLabelText('Skip back 10 seconds')).toBeTruthy();
|
|
75
|
-
expect(getByLabelText('Skip forward 10 seconds')).toBeTruthy();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('renders the play button in the "Play" state initially', async () => {
|
|
79
|
-
// Phase 24 default state: isPlaying = false.
|
|
80
|
-
const { getByLabelText } = await render(
|
|
81
|
-
<PlayerProvider>
|
|
82
|
-
<DefaultControls />
|
|
83
|
-
</PlayerProvider>,
|
|
84
|
-
);
|
|
85
|
-
expect(getByLabelText('Play')).toBeTruthy();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('renders the scrubber with adjustable accessibility role', async () => {
|
|
89
|
-
const { getByLabelText } = await render(
|
|
90
|
-
<PlayerProvider>
|
|
91
|
-
<DefaultControls />
|
|
92
|
-
</PlayerProvider>,
|
|
93
|
-
);
|
|
94
|
-
expect(getByLabelText('Seek bar')).toBeTruthy();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// ── Title / subtitle ───────────────────────────────────────────────────
|
|
98
|
-
|
|
99
|
-
it('shows the title from props', async () => {
|
|
100
|
-
const { getByText } = await render(
|
|
101
|
-
<PlayerProvider>
|
|
102
|
-
<DefaultControls title="My Episode" />
|
|
103
|
-
</PlayerProvider>,
|
|
104
|
-
);
|
|
105
|
-
expect(getByText('My Episode')).toBeTruthy();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('falls back to player state title when no prop is given', async () => {
|
|
109
|
-
// DefaultControls derives `effectiveTitle = title ?? state.title`.
|
|
110
|
-
// state.title is 'Simba Player' by default (the placeholder shown
|
|
111
|
-
// until the first onFileLoaded event arrives; see player.ts).
|
|
112
|
-
const { getByText } = await render(
|
|
113
|
-
<PlayerProvider>
|
|
114
|
-
<DefaultControls />
|
|
115
|
-
</PlayerProvider>,
|
|
116
|
-
);
|
|
117
|
-
// The placeholder "Simba Player" should appear.
|
|
118
|
-
expect(getByText('Simba Player')).toBeTruthy();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('shows the subtitle from props', async () => {
|
|
122
|
-
const { getByText } = await render(
|
|
123
|
-
<PlayerProvider>
|
|
124
|
-
<DefaultControls title="Song" subtitle="Artist • Album" />
|
|
125
|
-
</PlayerProvider>,
|
|
126
|
-
);
|
|
127
|
-
expect(getByText('Artist • Album')).toBeTruthy();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// ── Transport buttons → bridge ────────────────────────────────────────
|
|
131
|
-
|
|
132
|
-
it('skip-back button calls commands.skipBackward(10) on the bridge', async () => {
|
|
133
|
-
const { getByLabelText } = await render(
|
|
134
|
-
<PlayerProvider>
|
|
135
|
-
<DefaultControls />
|
|
136
|
-
</PlayerProvider>,
|
|
137
|
-
);
|
|
138
|
-
fireEvent.press(getByLabelText('Skip back 10 seconds'));
|
|
139
|
-
expect(NativeModules.MpvPlayerModule.seekBackward).toHaveBeenCalledWith(10);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('skip-forward button calls commands.skipForward(10) on the bridge', async () => {
|
|
143
|
-
const { getByLabelText } = await render(
|
|
144
|
-
<PlayerProvider>
|
|
145
|
-
<DefaultControls />
|
|
146
|
-
</PlayerProvider>,
|
|
147
|
-
);
|
|
148
|
-
fireEvent.press(getByLabelText('Skip forward 10 seconds'));
|
|
149
|
-
expect(NativeModules.MpvPlayerModule.seekForward).toHaveBeenCalledWith(10);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('play button calls commands.play on the bridge when not playing', async () => {
|
|
153
|
-
const { getByLabelText } = await render(
|
|
154
|
-
<PlayerProvider>
|
|
155
|
-
<DefaultControls />
|
|
156
|
-
</PlayerProvider>,
|
|
157
|
-
);
|
|
158
|
-
fireEvent.press(getByLabelText('Play'));
|
|
159
|
-
expect(NativeModules.MpvPlayerModule.play).toHaveBeenCalledTimes(1);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('close (✕) button calls commands.pause (the close action)', async () => {
|
|
163
|
-
// Phase 24 design: the close button (✕) is mapped to onPause
|
|
164
|
-
// (the consumer's hook for "the user dismissed the player"),
|
|
165
|
-
// which falls back to commands.pause when no prop is given.
|
|
166
|
-
const { getByLabelText } = await render(
|
|
167
|
-
<PlayerProvider>
|
|
168
|
-
<DefaultControls />
|
|
169
|
-
</PlayerProvider>,
|
|
170
|
-
);
|
|
171
|
-
fireEvent.press(getByLabelText('Close player'));
|
|
172
|
-
expect(NativeModules.MpvPlayerModule.pause).toHaveBeenCalled();
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// ── Props override fallback commands ───────────────────────────────────
|
|
176
|
-
|
|
177
|
-
it('uses onPlay prop instead of commands.play when provided', async () => {
|
|
178
|
-
const onPlay = jest.fn();
|
|
179
|
-
const { getByLabelText } = await render(
|
|
180
|
-
<PlayerProvider>
|
|
181
|
-
<DefaultControls onPlay={onPlay} />
|
|
182
|
-
</PlayerProvider>,
|
|
183
|
-
);
|
|
184
|
-
fireEvent.press(getByLabelText('Play'));
|
|
185
|
-
expect(onPlay).toHaveBeenCalledTimes(1);
|
|
186
|
-
// The fallback bridge call should NOT fire when onPlay is given.
|
|
187
|
-
expect(NativeModules.MpvPlayerModule.play).not.toHaveBeenCalled();
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('uses onPause prop instead of commands.pause when provided', async () => {
|
|
191
|
-
const onPause = jest.fn();
|
|
192
|
-
const { getByLabelText } = await render(
|
|
193
|
-
<PlayerProvider>
|
|
194
|
-
<DefaultControls onPause={onPause} />
|
|
195
|
-
</PlayerProvider>,
|
|
196
|
-
);
|
|
197
|
-
fireEvent.press(getByLabelText('Close player'));
|
|
198
|
-
expect(onPause).toHaveBeenCalledTimes(1);
|
|
199
|
-
expect(NativeModules.MpvPlayerModule.pause).not.toHaveBeenCalled();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// ── formatTime helper (indirect via render) ────────────────────────────
|
|
203
|
-
|
|
204
|
-
it('formats position/duration time labels as M:SS by default', async () => {
|
|
205
|
-
// Phase 24: usePlayerProgress returns {positionMs: 0, durationMs: 0}
|
|
206
|
-
// so both time labels render "0:00".
|
|
207
|
-
const { getAllByText } = await render(
|
|
208
|
-
<PlayerProvider>
|
|
209
|
-
<DefaultControls />
|
|
210
|
-
</PlayerProvider>,
|
|
211
|
-
);
|
|
212
|
-
// Two labels: one for position, one for duration.
|
|
213
|
-
const labels = getAllByText('0:00');
|
|
214
|
-
expect(labels.length).toBe(2);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
// ── Accessibility ──────────────────────────────────────────────────────
|
|
218
|
-
|
|
219
|
-
it('exposes accessibilityLabel on the root container', async () => {
|
|
220
|
-
const { getByLabelText } = await render(
|
|
221
|
-
<PlayerProvider>
|
|
222
|
-
<DefaultControls />
|
|
223
|
-
</PlayerProvider>,
|
|
224
|
-
);
|
|
225
|
-
expect(getByLabelText('Simba Player controls')).toBeTruthy();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('scrubber exposes min/max/now accessibilityValue', async () => {
|
|
229
|
-
const { getByLabelText } = await render(
|
|
230
|
-
<PlayerProvider>
|
|
231
|
-
<DefaultControls />
|
|
232
|
-
</PlayerProvider>,
|
|
233
|
-
);
|
|
234
|
-
const scrubber = getByLabelText('Seek bar');
|
|
235
|
-
// RNTL exposes accessibilityValue as a prop on the rendered
|
|
236
|
-
// element. Phase 24 wires {min: 0, max: 0, now: 0} for the
|
|
237
|
-
// 0-duration default.
|
|
238
|
-
expect(scrubber.props.accessibilityValue).toEqual({
|
|
239
|
-
min: 0,
|
|
240
|
-
max: 0,
|
|
241
|
-
now: 0,
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// ── Pure-function: formatTime ─────────────────────────────────────────────
|
|
247
|
-
// We don't import formatTime directly (it's not exported), but the
|
|
248
|
-
// behaviour is fully testable via the rendered output above. The
|
|
249
|
-
// "M:SS" format with `0:00` for zero/negative is the documented
|
|
250
|
-
// contract.
|
|
251
|
-
//
|
|
252
|
-
// A more thorough test would export formatTime for unit testing
|
|
253
|
-
// (deferred to Phase 39 if extraction is desirable).
|