mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
refactor(player): E.24 — extract radio session + infinite-queue guards (#588)
Cluster of four small mutables in two modules:
- `src/store/radioSessionState.ts` — `radioFetching` (concurrent
fetch guard) + `currentRadioArtistId` (seed artist that survives
track advances) + `radioSessionSeenIds` (dedupe set including
HISTORY_KEEP-evicted entries, fixes issue #500).
- `src/store/infiniteQueueState.ts` — `infiniteQueueFetching`
concurrent fetch guard.
Sed-driven bulk rewrite for the >35 direct-access sites. The four
`= new Set()` resets become `clearRadioSessionSeenIds()` calls and
the `setRadioArtistId` / `enqueueRadio` actions read through
`getCurrentRadioArtistId()` instead of touching the mutable directly.
15 focused tests across the two modules.
playerStore 2867 → 2865 LOC.
This commit is contained in:
committed by
GitHub
parent
6355946610
commit
14bdcde33f
@@ -0,0 +1,76 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import {
|
||||
_resetRadioSessionStateForTest,
|
||||
addRadioSessionSeen,
|
||||
clearRadioSessionSeenIds,
|
||||
deleteRadioSessionSeen,
|
||||
getCurrentRadioArtistId,
|
||||
hasRadioSessionSeen,
|
||||
isRadioFetching,
|
||||
setCurrentRadioArtistId,
|
||||
setRadioFetching,
|
||||
} from './radioSessionState';
|
||||
|
||||
afterEach(() => {
|
||||
_resetRadioSessionStateForTest();
|
||||
});
|
||||
|
||||
describe('radioFetching', () => {
|
||||
it('starts false + round-trips through set/get', () => {
|
||||
expect(isRadioFetching()).toBe(false);
|
||||
setRadioFetching(true);
|
||||
expect(isRadioFetching()).toBe(true);
|
||||
setRadioFetching(false);
|
||||
expect(isRadioFetching()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('currentRadioArtistId', () => {
|
||||
it('starts null + round-trips', () => {
|
||||
expect(getCurrentRadioArtistId()).toBeNull();
|
||||
setCurrentRadioArtistId('artist-1');
|
||||
expect(getCurrentRadioArtistId()).toBe('artist-1');
|
||||
setCurrentRadioArtistId(null);
|
||||
expect(getCurrentRadioArtistId()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('radioSessionSeenIds', () => {
|
||||
it('starts empty', () => {
|
||||
expect(hasRadioSessionSeen('any')).toBe(false);
|
||||
});
|
||||
|
||||
it('add + has round-trip', () => {
|
||||
addRadioSessionSeen('t1');
|
||||
expect(hasRadioSessionSeen('t1')).toBe(true);
|
||||
expect(hasRadioSessionSeen('t2')).toBe(false);
|
||||
});
|
||||
|
||||
it('delete removes individual ids without affecting others', () => {
|
||||
addRadioSessionSeen('t1');
|
||||
addRadioSessionSeen('t2');
|
||||
deleteRadioSessionSeen('t1');
|
||||
expect(hasRadioSessionSeen('t1')).toBe(false);
|
||||
expect(hasRadioSessionSeen('t2')).toBe(true);
|
||||
});
|
||||
|
||||
it('clearRadioSessionSeenIds wipes the set', () => {
|
||||
addRadioSessionSeen('t1');
|
||||
addRadioSessionSeen('t2');
|
||||
clearRadioSessionSeenIds();
|
||||
expect(hasRadioSessionSeen('t1')).toBe(false);
|
||||
expect(hasRadioSessionSeen('t2')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_resetRadioSessionStateForTest', () => {
|
||||
it('resets all three pieces of state', () => {
|
||||
setRadioFetching(true);
|
||||
setCurrentRadioArtistId('artist-1');
|
||||
addRadioSessionSeen('t1');
|
||||
_resetRadioSessionStateForTest();
|
||||
expect(isRadioFetching()).toBe(false);
|
||||
expect(getCurrentRadioArtistId()).toBeNull();
|
||||
expect(hasRadioSessionSeen('t1')).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user