63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { PlayerControls } from './PlayerControls';
|
|
|
|
const noop = () => {};
|
|
|
|
function render(over: Partial<Parameters<typeof PlayerControls>[0]> = {}) {
|
|
return renderToStaticMarkup(
|
|
<PlayerControls
|
|
playing={false}
|
|
positionMs={30_000}
|
|
durationMs={120_000}
|
|
canControl
|
|
volumePct={50}
|
|
onTogglePlay={noop}
|
|
onSeekMs={noop}
|
|
onSeekBy={noop}
|
|
onVolume={noop}
|
|
{...over}
|
|
/>
|
|
);
|
|
}
|
|
|
|
describe('PlayerControls', () => {
|
|
it('shows transport, times and volume when controllable', () => {
|
|
const html = render();
|
|
expect(html).toContain('0:30');
|
|
expect(html).toContain('2:00');
|
|
expect(html).toContain('Back 10 seconds');
|
|
expect(html).toContain('Forward 10 seconds');
|
|
expect(html).not.toContain('disabled');
|
|
});
|
|
|
|
it('disables transport when canControl is false', () => {
|
|
const html = render({ canControl: false });
|
|
// Play/pause + the two ±10s buttons are disabled…
|
|
expect(html.match(/disabled/g)?.length).toBe(3);
|
|
// …but the volume bar (local) is still rendered.
|
|
expect(html).toContain('50%');
|
|
});
|
|
|
|
it('hides seek buttons and shows LIVE for live sources', () => {
|
|
const html = render({ live: true });
|
|
expect(html).not.toContain('Back 10 seconds');
|
|
expect(html).toContain('LIVE');
|
|
});
|
|
|
|
it('renders skip only when onSkip is given', () => {
|
|
expect(render()).not.toContain('Play next');
|
|
expect(render({ onSkip: noop })).toContain('Play next');
|
|
});
|
|
|
|
it('hides the local row when showLocal is false', () => {
|
|
expect(render({ showLocal: false })).not.toContain('Vol');
|
|
});
|
|
|
|
it('renders the unified settings slot in the local row', () => {
|
|
expect(render({ settings: <button>Settings gear</button> })).toContain(
|
|
'Settings gear'
|
|
);
|
|
});
|
|
});
|