@therealtinhtute/baroiplayer 1.2.0 → 2.0.0-beta.1
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 +91 -73
- package/dist/components/icons/index.d.ts +36 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/AudioIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/AudioIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/BackwardIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/BackwardIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/CameraIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/CameraIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/CheckIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/CheckIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ForwardIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/ForwardIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/LoadingIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/LoadingIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PauseIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PauseIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PlayIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PlayIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/QualityIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/QualityIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SettingsIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SettingsIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SliderIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SliderIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SubtitleIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SubtitleIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/UnPiPIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/UnPiPIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-audio.d.ts +13 -0
- package/dist/components/variants/gradient/gradient-audio.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-controls.d.ts +4 -0
- package/dist/components/variants/gradient/gradient-controls.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-glyphs.d.ts +30 -0
- package/dist/components/variants/gradient/gradient-glyphs.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-video.d.ts +16 -0
- package/dist/components/variants/gradient/gradient-video.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +786 -6271
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +3 -0
- package/package.json +110 -108
- package/src/components/variants/gradient/gradient-audio.tsx +47 -0
- package/src/components/variants/gradient/gradient-controls.tsx +254 -0
- package/src/components/variants/gradient/gradient-glyphs.test.tsx +69 -0
- package/src/components/variants/gradient/gradient-glyphs.tsx +129 -0
- package/src/components/variants/gradient/gradient-skin.css +211 -0
- package/src/components/variants/gradient/gradient-video.tsx +70 -0
- package/src/index.ts +5 -198
- package/src/test/accessibility-utils.ts +0 -59
- package/dist/context/media.js +0 -2
- package/dist/context/media.js.map +0 -1
- package/dist/context/media.mjs +0 -15
- package/dist/context/media.mjs.map +0 -1
- package/dist/context/store.js +0 -2
- package/dist/context/store.js.map +0 -1
- package/dist/context/store.mjs +0 -5
- package/dist/context/store.mjs.map +0 -1
- package/dist/context-BYwDoSRX.js +0 -1172
- package/dist/context-BYwDoSRX.js.map +0 -1
- package/dist/context-eNS62_ac.cjs +0 -23
- package/dist/context-eNS62_ac.cjs.map +0 -1
- package/dist/core-events-B1iM2F46.cjs +0 -2
- package/dist/core-events-B1iM2F46.cjs.map +0 -1
- package/dist/core-events-DunPHKRE.js +0 -484
- package/dist/core-events-DunPHKRE.js.map +0 -1
- package/dist/core-plugins-By-4-kGs.cjs +0 -2
- package/dist/core-plugins-By-4-kGs.cjs.map +0 -1
- package/dist/core-plugins-DSBWcTuX.js +0 -821
- package/dist/core-plugins-DSBWcTuX.js.map +0 -1
- package/dist/core.js +0 -37
- package/dist/core.js.map +0 -1
- package/dist/core.mjs +0 -1233
- package/dist/core.mjs.map +0 -1
- package/dist/enhanced-components-B_l3cist.js +0 -1142
- package/dist/enhanced-components-B_l3cist.js.map +0 -1
- package/dist/enhanced-components-BspFs9OO.cjs +0 -2
- package/dist/enhanced-components-BspFs9OO.cjs.map +0 -1
- package/dist/hooks-BXwI8QG6.cjs +0 -4
- package/dist/hooks-BXwI8QG6.cjs.map +0 -1
- package/dist/hooks-Bpi-jDiO.js +0 -1816
- package/dist/hooks-Bpi-jDiO.js.map +0 -1
- package/dist/minimal-components-C4z900Ro.js +0 -1926
- package/dist/minimal-components-C4z900Ro.js.map +0 -1
- package/dist/minimal-components-v4qBp6jv.cjs +0 -2
- package/dist/minimal-components-v4qBp6jv.cjs.map +0 -1
- package/dist/minimal-components.css +0 -1
- package/dist/mona-loading.gif +0 -0
- package/dist/performance-monitor-C5k6FDXw.js +0 -301
- package/dist/performance-monitor-C5k6FDXw.js.map +0 -1
- package/dist/performance-monitor-lJmuUjQQ.cjs +0 -2
- package/dist/performance-monitor-lJmuUjQQ.cjs.map +0 -1
- package/dist/utils-CFOue_9K.cjs +0 -9
- package/dist/utils-CFOue_9K.cjs.map +0 -1
- package/dist/utils-Dzpl2ArK.js +0 -2844
- package/dist/utils-Dzpl2ArK.js.map +0 -1
- package/dist/utils.js +0 -2
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs +0 -11
- package/dist/utils.mjs.map +0 -1
- package/src/adapters/videojs-adapter.tsx +0 -470
- package/src/assets/mona-loading.gif +0 -0
- package/src/components/AnimateLoading.tsx +0 -107
- package/src/components/LoadingState.tsx +0 -239
- package/src/components/__tests__/media-player-accessibility.test.tsx +0 -510
- package/src/components/__tests__/media-player-react19.test.tsx +0 -457
- package/src/components/accessibility/keyboard-help-overlay.tsx +0 -207
- package/src/components/audio-player.tsx +0 -85
- package/src/components/basic/index.ts +0 -37
- package/src/components/enhanced/advanced-features.tsx +0 -311
- package/src/components/enhanced/debug-panel.tsx +0 -448
- package/src/components/enhanced/enhanced-controls.tsx +0 -597
- package/src/components/enhanced/enhanced-media-player.tsx +0 -566
- package/src/components/enhanced/error-handling.tsx +0 -338
- package/src/components/enhanced/index.ts +0 -39
- package/src/components/enhanced/media-player-enhanced.tsx +0 -383
- package/src/components/examples/basic-video-player.tsx +0 -50
- package/src/components/examples/custom-controls-example.tsx +0 -63
- package/src/components/examples/enhanced-controls-example.tsx +0 -100
- package/src/components/examples/enhanced-media-player-example.tsx +0 -302
- package/src/components/examples/loading-states-demo.tsx +0 -142
- package/src/components/examples/react-19-demo.tsx +0 -353
- package/src/components/examples/volume-orientation-demo.tsx +0 -106
- package/src/components/icon-demo.tsx +0 -196
- package/src/components/legacy.tsx +0 -87
- package/src/components/media-metadata-display.tsx +0 -99
- package/src/components/media-player-audio.tsx +0 -39
- package/src/components/media-player-controls.tsx +0 -223
- package/src/components/media-player-error.tsx +0 -163
- package/src/components/media-player-fullscreen.tsx +0 -109
- package/src/components/media-player-hls.tsx +0 -111
- package/src/components/media-player-loading.tsx +0 -76
- package/src/components/media-player-play.tsx +0 -75
- package/src/components/media-player-root.tsx +0 -338
- package/src/components/media-player-seek.tsx +0 -168
- package/src/components/media-player-time.tsx +0 -99
- package/src/components/media-player-tooltip.tsx +0 -58
- package/src/components/media-player-video.tsx +0 -54
- package/src/components/media-player-volume.tsx +0 -155
- package/src/components/media-player.tsx +0 -292
- package/src/components/media-suspense.tsx +0 -344
- package/src/components/player-settings-form.tsx +0 -158
- package/src/components/react-player-wrapper.tsx +0 -651
- package/src/components/simple-video-player.tsx +0 -62
- package/src/components/ui/blur-poster.tsx +0 -93
- package/src/components/ui/empty-state.tsx +0 -91
- package/src/components/ui/enhanced-seek-bar.tsx +0 -254
- package/src/components/ui/error-state.tsx +0 -124
- package/src/components/ui/fullscreen-button.tsx +0 -81
- package/src/components/ui/loading-skeleton.tsx +0 -107
- package/src/components/ui/media-resource-preloader.tsx +0 -458
- package/src/components/ui/offline-message.tsx +0 -98
- package/src/components/ui/play-button.tsx +0 -99
- package/src/components/ui/seek-bar.tsx +0 -191
- package/src/components/ui/time-display.tsx +0 -61
- package/src/components/ui/volume-control.tsx +0 -190
- package/src/components/unified/base-media-player.tsx +0 -252
- package/src/components/unified/media-player.tsx +0 -75
- package/src/components/variants/minimal/AccessibleMinimalPlayer.tsx +0 -587
- package/src/components/variants/minimal/EnhancedMinimalMediaPlayer.tsx +0 -573
- package/src/components/variants/minimal/MinimalControls.tsx +0 -124
- package/src/components/variants/minimal/MinimalLoading.tsx +0 -28
- package/src/components/variants/minimal/MinimalMediaPlayer.tsx +0 -318
- package/src/components/variants/minimal/MinimalOverlay.tsx +0 -58
- package/src/components/variants/minimal/MinimalPlayButton.tsx +0 -56
- package/src/components/variants/minimal/MinimalSeekBar.tsx +0 -140
- package/src/components/variants/minimal/MinimalVolumeControl.tsx +0 -75
- package/src/components/variants/minimal/SimpleMinimalPlayer.tsx +0 -206
- package/src/components/variants/minimal/components/CenterPlayButton.tsx +0 -22
- package/src/components/variants/minimal/components/ControlBar.tsx +0 -142
- package/src/components/variants/minimal/components/EnhancedSettingsMenu.tsx +0 -412
- package/src/components/variants/minimal/components/PlaybackControls.tsx +0 -46
- package/src/components/variants/minimal/components/RightControls.tsx +0 -164
- package/src/components/variants/minimal/components/SeekBar.tsx +0 -127
- package/src/components/variants/minimal/components/SettingsDropdown.tsx +0 -68
- package/src/components/variants/minimal/components/SubtitleDisplay.tsx +0 -21
- package/src/components/variants/minimal/components/TimeDisplay.tsx +0 -15
- package/src/components/variants/minimal/components/VideoElement.tsx +0 -33
- package/src/components/variants/minimal/components/VolumeControl.tsx +0 -220
- package/src/components/variants/minimal/index.ts +0 -23
- package/src/components/video-player.tsx +0 -100
- package/src/context/__tests__/media-store.test.ts +0 -509
- package/src/context/error-handling.ts +0 -398
- package/src/context/media-context.tsx +0 -254
- package/src/context/media-provider.tsx +0 -264
- package/src/context/media-store.ts +0 -387
- package/src/context/persistence.ts +0 -462
- package/src/core/events/event-system.ts +0 -448
- package/src/core/events/hooks.ts +0 -325
- package/src/core/events/index.ts +0 -22
- package/src/core/events/middleware.ts +0 -286
- package/src/core/index.ts +0 -22
- package/src/core/optimization/bundle-optimizer.tsx +0 -312
- package/src/core/performance/cicd.ts +0 -98
- package/src/core/performance/index.ts +0 -38
- package/src/core/performance/media-loading-optimizer.ts +0 -544
- package/src/core/performance/performance-budgets.ts +0 -437
- package/src/core/performance/performance-monitor.tsx +0 -488
- package/src/core/performance/performance-testing.ts +0 -461
- package/src/core/plugins/__tests__/registry.test.ts +0 -595
- package/src/core/plugins/base-plugin.ts +0 -225
- package/src/core/plugins/enhanced-plugin-system.ts +0 -435
- package/src/core/plugins/examples/analytics-plugin.ts +0 -241
- package/src/core/plugins/index.ts +0 -39
- package/src/core/plugins/registry.ts +0 -546
- package/src/core/plugins/types.ts +0 -169
- package/src/core/plugins/utils.ts +0 -317
- package/src/core/progressive-loading.tsx +0 -331
- package/src/core/providers/enhanced-hls-provider.ts +0 -307
- package/src/core/providers/lazy-provider.tsx +0 -14
- package/src/core/providers/service-provider.tsx +0 -164
- package/src/core/utils.tsx +0 -34
- package/src/features/media-session/media-session-manager.ts +0 -411
- package/src/features/picture-in-picture/pip-manager.ts +0 -428
- package/src/features/playlist/playlist-manager.ts +0 -626
- package/src/features/subtitles/subtitle-manager.ts +0 -435
- package/src/features/subtitles/subtitle-parser.ts +0 -284
- package/src/features/thumbnails/thumbnail-generator.ts +0 -528
- package/src/hooks/__tests__/currentTime-fix.test.ts +0 -149
- package/src/hooks/__tests__/use-media-player.test.ts +0 -712
- package/src/hooks/__tests__/use-media-state.test.tsx +0 -316
- package/src/hooks/accessibility/index.ts +0 -27
- package/src/hooks/accessibility/use-accessibility-preferences.ts +0 -190
- package/src/hooks/accessibility/use-focus-management.ts +0 -183
- package/src/hooks/accessibility/use-keyboard-shortcuts.ts +0 -152
- package/src/hooks/accessibility/use-screen-reader.ts +0 -212
- package/src/hooks/core/index.ts +0 -47
- package/src/hooks/legacy.ts +0 -21
- package/src/hooks/use-buffer-health.ts +0 -218
- package/src/hooks/use-enhanced-media-player.ts +0 -575
- package/src/hooks/use-focus-trap.tsx +0 -162
- package/src/hooks/use-intelligent-preloading.ts +0 -387
- package/src/hooks/use-keyboard-controls.ts +0 -115
- package/src/hooks/use-keyboard-shortcuts.ts +0 -255
- package/src/hooks/use-media-actions.ts +0 -184
- package/src/hooks/use-media-metadata.ts +0 -91
- package/src/hooks/use-media-optimistic.ts +0 -264
- package/src/hooks/use-media-player.ts +0 -343
- package/src/hooks/use-media-state.ts +0 -194
- package/src/hooks/use-memory-optimization.ts +0 -360
- package/src/hooks/use-network-status.ts +0 -124
- package/src/hooks/use-optimistic-controls.ts +0 -95
- package/src/hooks/use-optimized-media.ts +0 -283
- package/src/hooks/use-smart-preload.ts +0 -229
- package/src/hooks/use-touch-gestures.ts +0 -461
- package/src/hooks/useEnhancedSubtitles.ts +0 -258
- package/src/hooks/useKeyboardShortcuts.ts +0 -106
- package/src/hooks/useMediaControls.ts +0 -52
- package/src/hooks/useScreenshot.ts +0 -61
- package/src/hooks/useSubtitles.ts +0 -91
- package/src/hooks/useVideoPlayer.ts +0 -278
- package/src/icons/components/FullscreenIcon.tsx +0 -36
- package/src/icons/components/SettingsIcon.tsx +0 -37
- package/src/icons/components/animated/LoadingIcon.tsx +0 -27
- package/src/icons/components/animated/PlayPauseIcon.tsx +0 -42
- package/src/icons/components/media/PauseIcon.tsx +0 -38
- package/src/icons/components/media/PlayIcon.tsx +0 -37
- package/src/icons/components/volume/VolumeIcon.tsx +0 -38
- package/src/icons/components/volume/VolumeOffIcon.tsx +0 -38
- package/src/icons/index.ts +0 -56
- package/src/icons/provider.tsx +0 -58
- package/src/icons/types.ts +0 -60
- package/src/index-enhanced.ts +0 -35
- package/src/index-legacy.ts +0 -324
- package/src/index.css +0 -102
- package/src/lib/__tests__/async-utils.test.ts +0 -291
- package/src/lib/async-utils.ts +0 -194
- package/src/lib/deprecation.ts +0 -51
- package/src/lib/format-time.ts +0 -37
- package/src/lib/index.ts +0 -4
- package/src/lib/utils.ts +0 -6
- package/src/styles/globals.css +0 -462
- package/src/styles/minimal-player.css +0 -621
- package/src/styles/pixel-art.css +0 -41
- package/src/styles/videojs.css +0 -100
- package/src/types/events.ts +0 -47
- package/src/types/formats.ts +0 -79
- package/src/types/index.ts +0 -203
- package/src/types/videojs-plugins.d.ts +0 -14
|
@@ -1,509 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
|
2
|
-
import { MediaActionTypes, initialMediaState } from "../media-context"
|
|
3
|
-
import {
|
|
4
|
-
type EnhancedMediaStore,
|
|
5
|
-
type OptimisticMediaAction,
|
|
6
|
-
createEnhancedMediaStore
|
|
7
|
-
} from "../media-store"
|
|
8
|
-
|
|
9
|
-
describe("createEnhancedMediaStore", () => {
|
|
10
|
-
let store: EnhancedMediaStore
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
// Clear localStorage
|
|
14
|
-
localStorage.clear()
|
|
15
|
-
vi.clearAllMocks()
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
localStorage.clear()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe("Basic Store Functionality", () => {
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
store = createEnhancedMediaStore()
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it("should initialize with initial state", () => {
|
|
28
|
-
const state = store.getState()
|
|
29
|
-
expect(state).toEqual(initialMediaState)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it("should initialize with custom state", () => {
|
|
33
|
-
const customState = {
|
|
34
|
-
...initialMediaState,
|
|
35
|
-
volume: 0.5,
|
|
36
|
-
isMuted: true
|
|
37
|
-
}
|
|
38
|
-
const customStore = createEnhancedMediaStore(customState)
|
|
39
|
-
expect(customStore.getState()).toEqual(customState)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it("should subscribe to state changes", () => {
|
|
43
|
-
const callback = vi.fn()
|
|
44
|
-
const unsubscribe = store.subscribe(callback)
|
|
45
|
-
|
|
46
|
-
store.setState({ volume: 0.5 })
|
|
47
|
-
|
|
48
|
-
expect(callback).toHaveBeenCalled()
|
|
49
|
-
|
|
50
|
-
unsubscribe()
|
|
51
|
-
callback.mockClear()
|
|
52
|
-
|
|
53
|
-
store.setState({ volume: 0.7 })
|
|
54
|
-
expect(callback).not.toHaveBeenCalled()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it("should update state with setState", () => {
|
|
58
|
-
store.setState({ volume: 0.8, isMuted: true })
|
|
59
|
-
|
|
60
|
-
const state = store.getState()
|
|
61
|
-
expect(state.volume).toBe(0.8)
|
|
62
|
-
expect(state.isMuted).toBe(true)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it("should dispatch actions", () => {
|
|
66
|
-
store.dispatch({
|
|
67
|
-
type: MediaActionTypes.SET_VOLUME,
|
|
68
|
-
payload: 0.6
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const state = store.getState()
|
|
72
|
-
expect(state.volume).toBe(0.6)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it("should handle multiple subscribers", () => {
|
|
76
|
-
const callback1 = vi.fn()
|
|
77
|
-
const callback2 = vi.fn()
|
|
78
|
-
const callback3 = vi.fn()
|
|
79
|
-
|
|
80
|
-
store.subscribe(callback1)
|
|
81
|
-
store.subscribe(callback2)
|
|
82
|
-
store.subscribe(callback3)
|
|
83
|
-
|
|
84
|
-
store.setState({ isPlaying: true })
|
|
85
|
-
|
|
86
|
-
expect(callback1).toHaveBeenCalledTimes(1)
|
|
87
|
-
expect(callback2).toHaveBeenCalledTimes(1)
|
|
88
|
-
expect(callback3).toHaveBeenCalledTimes(1)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it("should allow unsubscribing specific callbacks", () => {
|
|
92
|
-
const callback1 = vi.fn()
|
|
93
|
-
const callback2 = vi.fn()
|
|
94
|
-
|
|
95
|
-
const unsubscribe1 = store.subscribe(callback1)
|
|
96
|
-
store.subscribe(callback2)
|
|
97
|
-
|
|
98
|
-
unsubscribe1()
|
|
99
|
-
|
|
100
|
-
store.setState({ volume: 0.5 })
|
|
101
|
-
|
|
102
|
-
expect(callback1).not.toHaveBeenCalled()
|
|
103
|
-
expect(callback2).toHaveBeenCalled()
|
|
104
|
-
})
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
describe("Optimistic Updates", () => {
|
|
108
|
-
beforeEach(() => {
|
|
109
|
-
store = createEnhancedMediaStore()
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it("should return optimistic state", () => {
|
|
113
|
-
const optimisticState = store.getOptimisticState()
|
|
114
|
-
expect(optimisticState).toEqual(initialMediaState)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
it("should handle optimistic actions", async () => {
|
|
118
|
-
const optimisticAction: OptimisticMediaAction = {
|
|
119
|
-
type: MediaActionTypes.SET_VOLUME,
|
|
120
|
-
payload: 0.7,
|
|
121
|
-
optimistic: true
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
await store.dispatchOptimistic(optimisticAction)
|
|
125
|
-
|
|
126
|
-
const optimisticState = store.getOptimisticState()
|
|
127
|
-
expect(optimisticState.volume).toBe(0.7)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it("should eventually commit optimistic updates to actual state", async () => {
|
|
131
|
-
const optimisticAction: OptimisticMediaAction = {
|
|
132
|
-
type: MediaActionTypes.SET_VOLUME,
|
|
133
|
-
payload: 0.5,
|
|
134
|
-
optimistic: true
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
await store.dispatchOptimistic(optimisticAction)
|
|
138
|
-
|
|
139
|
-
// Wait for optimistic update to commit
|
|
140
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
141
|
-
|
|
142
|
-
const actualState = store.getState()
|
|
143
|
-
expect(actualState.volume).toBe(0.5)
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it("should track action state during optimistic updates", async () => {
|
|
147
|
-
const optimisticAction: OptimisticMediaAction = {
|
|
148
|
-
type: MediaActionTypes.SET_PLAYING,
|
|
149
|
-
payload: true,
|
|
150
|
-
optimistic: true
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const promise = store.dispatchOptimistic(optimisticAction)
|
|
154
|
-
|
|
155
|
-
// Check pending state during execution
|
|
156
|
-
const actionStateDuring = store.getActionState()
|
|
157
|
-
expect(actionStateDuring.pending).toBe(true)
|
|
158
|
-
|
|
159
|
-
await promise
|
|
160
|
-
|
|
161
|
-
const actionStateAfter = store.getActionState()
|
|
162
|
-
expect(actionStateAfter.pending).toBe(false)
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
describe("State Persistence", () => {
|
|
167
|
-
it("should persist state to localStorage", async () => {
|
|
168
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
169
|
-
enabled: true,
|
|
170
|
-
key: "test-media-state",
|
|
171
|
-
debounceMs: 10
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
store.setState({ volume: 0.75, isMuted: true })
|
|
175
|
-
|
|
176
|
-
// Wait for debounced persist
|
|
177
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
178
|
-
|
|
179
|
-
const stored = localStorage.getItem("test-media-state")
|
|
180
|
-
expect(stored).toBeTruthy()
|
|
181
|
-
|
|
182
|
-
const parsed = JSON.parse(stored!)
|
|
183
|
-
expect(parsed.volume).toBe(0.75)
|
|
184
|
-
expect(parsed.isMuted).toBe(true)
|
|
185
|
-
expect(parsed.timestamp).toBeDefined()
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
it("should rehydrate state from localStorage", async () => {
|
|
189
|
-
const persistedData = {
|
|
190
|
-
volume: 0.9,
|
|
191
|
-
isMuted: false,
|
|
192
|
-
timestamp: Date.now()
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
localStorage.setItem("test-media-state", JSON.stringify(persistedData))
|
|
196
|
-
|
|
197
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
198
|
-
enabled: true,
|
|
199
|
-
key: "test-media-state"
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
await store.rehydrateFromStorage()
|
|
203
|
-
|
|
204
|
-
const state = store.getState()
|
|
205
|
-
expect(state.volume).toBe(0.9)
|
|
206
|
-
expect(state.isMuted).toBe(false)
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
it("should not rehydrate expired state", async () => {
|
|
210
|
-
const expiredData = {
|
|
211
|
-
volume: 0.5,
|
|
212
|
-
timestamp: Date.now() - 8 * 24 * 60 * 60 * 1000 // 8 days old
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
localStorage.setItem("test-media-state", JSON.stringify(expiredData))
|
|
216
|
-
|
|
217
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
218
|
-
enabled: true,
|
|
219
|
-
key: "test-media-state"
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
await store.rehydrateFromStorage()
|
|
223
|
-
|
|
224
|
-
const state = store.getState()
|
|
225
|
-
expect(state.volume).toBe(initialMediaState.volume)
|
|
226
|
-
expect(localStorage.getItem("test-media-state")).toBeNull()
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
it("should clear persisted state", () => {
|
|
230
|
-
localStorage.setItem("test-media-state", JSON.stringify({ volume: 0.5 }))
|
|
231
|
-
|
|
232
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
233
|
-
enabled: true,
|
|
234
|
-
key: "test-media-state"
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
store.clearPersistedState()
|
|
238
|
-
|
|
239
|
-
expect(localStorage.getItem("test-media-state")).toBeNull()
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
it("should handle persistence errors gracefully", async () => {
|
|
243
|
-
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
|
|
244
|
-
|
|
245
|
-
// Mock localStorage to throw error
|
|
246
|
-
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
|
|
247
|
-
throw new Error("Storage full")
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
251
|
-
enabled: true,
|
|
252
|
-
key: "test-media-state",
|
|
253
|
-
debounceMs: 10
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
store.setState({ volume: 0.5 })
|
|
257
|
-
|
|
258
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
259
|
-
|
|
260
|
-
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
261
|
-
"Failed to persist media state:",
|
|
262
|
-
expect.any(Error)
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
consoleWarnSpy.mockRestore()
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
it("should only persist configured keys", async () => {
|
|
269
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
270
|
-
enabled: true,
|
|
271
|
-
key: "test-media-state",
|
|
272
|
-
persist: ["volume"], // Only persist volume
|
|
273
|
-
debounceMs: 10
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
store.setState({
|
|
277
|
-
volume: 0.6,
|
|
278
|
-
isMuted: true,
|
|
279
|
-
currentTime: 50
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
283
|
-
|
|
284
|
-
const stored = localStorage.getItem("test-media-state")
|
|
285
|
-
const parsed = JSON.parse(stored!)
|
|
286
|
-
|
|
287
|
-
expect(parsed.volume).toBe(0.6)
|
|
288
|
-
expect(parsed.isMuted).toBeUndefined()
|
|
289
|
-
expect(parsed.currentTime).toBeUndefined()
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
it("should debounce persistence calls", async () => {
|
|
293
|
-
const setItemSpy = vi.spyOn(Storage.prototype, "setItem")
|
|
294
|
-
|
|
295
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
296
|
-
enabled: true,
|
|
297
|
-
key: "test-media-state",
|
|
298
|
-
debounceMs: 100
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
// Multiple rapid updates
|
|
302
|
-
store.setState({ volume: 0.1 })
|
|
303
|
-
store.setState({ volume: 0.2 })
|
|
304
|
-
store.setState({ volume: 0.3 })
|
|
305
|
-
store.setState({ volume: 0.4 })
|
|
306
|
-
store.setState({ volume: 0.5 })
|
|
307
|
-
|
|
308
|
-
// Should not persist immediately
|
|
309
|
-
expect(setItemSpy).not.toHaveBeenCalled()
|
|
310
|
-
|
|
311
|
-
// Wait for debounce
|
|
312
|
-
await new Promise((resolve) => setTimeout(resolve, 150))
|
|
313
|
-
|
|
314
|
-
// Should persist only once
|
|
315
|
-
expect(setItemSpy).toHaveBeenCalledTimes(1)
|
|
316
|
-
|
|
317
|
-
const stored = localStorage.getItem("test-media-state")
|
|
318
|
-
const parsed = JSON.parse(stored!)
|
|
319
|
-
expect(parsed.volume).toBe(0.5) // Latest value
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
it("should update persistence config", async () => {
|
|
323
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
324
|
-
enabled: true,
|
|
325
|
-
key: "test-media-state",
|
|
326
|
-
persist: ["volume"],
|
|
327
|
-
debounceMs: 10
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
// Update config
|
|
331
|
-
store.setPersistenceConfig({
|
|
332
|
-
persist: ["volume", "isMuted"],
|
|
333
|
-
debounceMs: 20
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
store.setState({ volume: 0.7, isMuted: true })
|
|
337
|
-
|
|
338
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
339
|
-
|
|
340
|
-
const stored = localStorage.getItem("test-media-state")
|
|
341
|
-
const parsed = JSON.parse(stored!)
|
|
342
|
-
|
|
343
|
-
expect(parsed.volume).toBe(0.7)
|
|
344
|
-
expect(parsed.isMuted).toBe(true)
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
it("should disable persistence when configured", async () => {
|
|
348
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
349
|
-
enabled: false,
|
|
350
|
-
key: "test-media-state"
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
store.setState({ volume: 0.8 })
|
|
354
|
-
|
|
355
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
356
|
-
|
|
357
|
-
expect(localStorage.getItem("test-media-state")).toBeNull()
|
|
358
|
-
})
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
describe("Action State Tracking", () => {
|
|
362
|
-
beforeEach(() => {
|
|
363
|
-
store = createEnhancedMediaStore()
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
it("should initialize with empty action state", () => {
|
|
367
|
-
const actionState = store.getActionState()
|
|
368
|
-
|
|
369
|
-
expect(actionState).toEqual({
|
|
370
|
-
pending: false,
|
|
371
|
-
error: null,
|
|
372
|
-
lastAction: null,
|
|
373
|
-
retryCount: 0
|
|
374
|
-
})
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
it("should track last action", async () => {
|
|
378
|
-
const action: OptimisticMediaAction = {
|
|
379
|
-
type: MediaActionTypes.SET_VOLUME,
|
|
380
|
-
payload: 0.5,
|
|
381
|
-
optimistic: true
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
await store.dispatchOptimistic(action)
|
|
385
|
-
|
|
386
|
-
const actionState = store.getActionState()
|
|
387
|
-
expect(actionState.lastAction).toEqual(action)
|
|
388
|
-
})
|
|
389
|
-
|
|
390
|
-
it("should track retry count", async () => {
|
|
391
|
-
const failingAction: OptimisticMediaAction = {
|
|
392
|
-
type: MediaActionTypes.SET_VOLUME,
|
|
393
|
-
payload: 0.5,
|
|
394
|
-
optimistic: true,
|
|
395
|
-
retryCount: 3
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
await store.dispatchOptimistic(failingAction)
|
|
399
|
-
|
|
400
|
-
const actionState = store.getActionState()
|
|
401
|
-
expect(actionState.retryCount).toBeGreaterThan(0)
|
|
402
|
-
})
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
describe("Edge Cases", () => {
|
|
406
|
-
beforeEach(() => {
|
|
407
|
-
store = createEnhancedMediaStore()
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
it("should handle rapid state updates", () => {
|
|
411
|
-
const callback = vi.fn()
|
|
412
|
-
store.subscribe(callback)
|
|
413
|
-
|
|
414
|
-
for (let i = 0; i < 100; i++) {
|
|
415
|
-
store.setState({ currentTime: i })
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
expect(callback).toHaveBeenCalledTimes(100)
|
|
419
|
-
expect(store.getState().currentTime).toBe(99)
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
it("should handle concurrent optimistic updates", async () => {
|
|
423
|
-
const actions = [
|
|
424
|
-
{ type: MediaActionTypes.SET_VOLUME, payload: 0.5, optimistic: true },
|
|
425
|
-
{ type: MediaActionTypes.SET_PLAYING, payload: true, optimistic: true },
|
|
426
|
-
{ type: MediaActionTypes.SET_MUTED, payload: true, optimistic: true }
|
|
427
|
-
] as OptimisticMediaAction[]
|
|
428
|
-
|
|
429
|
-
await Promise.all(actions.map((action) => store.dispatchOptimistic(action)))
|
|
430
|
-
|
|
431
|
-
const state = store.getState()
|
|
432
|
-
expect(state.volume).toBe(0.5)
|
|
433
|
-
expect(state.isPlaying).toBe(true)
|
|
434
|
-
expect(state.isMuted).toBe(true)
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
it("should handle invalid JSON during rehydration", async () => {
|
|
438
|
-
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
|
|
439
|
-
|
|
440
|
-
localStorage.setItem("test-media-state", "invalid json{")
|
|
441
|
-
|
|
442
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
443
|
-
enabled: true,
|
|
444
|
-
key: "test-media-state"
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
await store.rehydrateFromStorage()
|
|
448
|
-
|
|
449
|
-
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
450
|
-
"Failed to rehydrate media state:",
|
|
451
|
-
expect.any(Error)
|
|
452
|
-
)
|
|
453
|
-
|
|
454
|
-
consoleWarnSpy.mockRestore()
|
|
455
|
-
})
|
|
456
|
-
|
|
457
|
-
it("should not persist in non-browser environment", async () => {
|
|
458
|
-
const originalWindow = global.window
|
|
459
|
-
|
|
460
|
-
// Simulate SSR environment
|
|
461
|
-
;(global as any).window = undefined
|
|
462
|
-
|
|
463
|
-
store = createEnhancedMediaStore(initialMediaState, {
|
|
464
|
-
enabled: true,
|
|
465
|
-
key: "test-media-state",
|
|
466
|
-
debounceMs: 10
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
store.setState({ volume: 0.5 })
|
|
470
|
-
|
|
471
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
472
|
-
|
|
473
|
-
// Restore window
|
|
474
|
-
global.window = originalWindow
|
|
475
|
-
|
|
476
|
-
// No error should be thrown, just silently skip persistence
|
|
477
|
-
expect(true).toBe(true)
|
|
478
|
-
})
|
|
479
|
-
})
|
|
480
|
-
|
|
481
|
-
describe("Memory Management", () => {
|
|
482
|
-
it("should properly cleanup subscriptions", () => {
|
|
483
|
-
store = createEnhancedMediaStore()
|
|
484
|
-
|
|
485
|
-
const callbacks = Array.from({ length: 1000 }, () => vi.fn())
|
|
486
|
-
const unsubscribers = callbacks.map((cb) => store.subscribe(cb))
|
|
487
|
-
|
|
488
|
-
// Unsubscribe all
|
|
489
|
-
unsubscribers.forEach((unsub) => unsub())
|
|
490
|
-
|
|
491
|
-
store.setState({ volume: 0.5 })
|
|
492
|
-
|
|
493
|
-
// No callbacks should be called
|
|
494
|
-
callbacks.forEach((cb) => expect(cb).not.toHaveBeenCalled())
|
|
495
|
-
})
|
|
496
|
-
|
|
497
|
-
it("should handle state updates after all subscribers removed", () => {
|
|
498
|
-
store = createEnhancedMediaStore()
|
|
499
|
-
|
|
500
|
-
const unsub = store.subscribe(vi.fn())
|
|
501
|
-
unsub()
|
|
502
|
-
|
|
503
|
-
// Should not throw
|
|
504
|
-
expect(() => {
|
|
505
|
-
store.setState({ volume: 0.5 })
|
|
506
|
-
}).not.toThrow()
|
|
507
|
-
})
|
|
508
|
-
})
|
|
509
|
-
})
|