mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
ddead24678
Two small file-private helpers move into dedicated modules under src/store/: - `waveformRefreshGen.ts` — the per-track generation counter that guards against applying a stale waveform read after the cache was invalidated. Exposes `bumpWaveformRefreshGen` (existing) + `getWaveformRefreshGen` (new accessor that replaces the two direct reads at `refreshWaveformForTrack`). - `hotCacheTouch.ts` — `touchHotCacheOnPlayback` with its empty-id guards, called from every `audio_play` entry point. Both file-private; no caller-side changes outside playerStore's own imports. 8 focused tests pin the generation-increment + isolation contract and the touch helper's empty-id guards. playerStore 3302 → 3291 LOC.
33 lines
900 B
TypeScript
33 lines
900 B
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
const { touchPlayedMock } = vi.hoisted(() => ({
|
|
touchPlayedMock: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('./hotCacheStore', () => ({
|
|
useHotCacheStore: { getState: () => ({ touchPlayed: touchPlayedMock }) },
|
|
}));
|
|
|
|
import { touchHotCacheOnPlayback } from './hotCacheTouch';
|
|
|
|
beforeEach(() => {
|
|
touchPlayedMock.mockClear();
|
|
});
|
|
|
|
describe('touchHotCacheOnPlayback', () => {
|
|
it('forwards a populated id pair to the hot-cache store', () => {
|
|
touchHotCacheOnPlayback('t1', 'srv');
|
|
expect(touchPlayedMock).toHaveBeenCalledWith('t1', 'srv');
|
|
});
|
|
|
|
it('skips when the trackId is empty', () => {
|
|
touchHotCacheOnPlayback('', 'srv');
|
|
expect(touchPlayedMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('skips when the serverId is empty', () => {
|
|
touchHotCacheOnPlayback('t1', '');
|
|
expect(touchPlayedMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|