feat(60): activate channel preview on the channels list
Wires the ChannelPreviewPanel (Task 4) into ChannelsScreen: a single panel instance is rendered per screen and its `channel` prop is swapped via previewChannelId state rather than remounting per row. The Play button now reads the server-derived channel.preview.availability (Task 2) instead of being permanently disabled -- Unavailable stays disabled with the server's unavailableReason surfaced in the title; Available and ForcedHlsOnly both enable it, since the panel itself handles the forced-HLS opt-in and caveat. Also fixes App.test.tsx's #244 channel fixture, which lacked the now- required preview field and crashed once ChannelTableRow started reading it.
This commit is contained in:
@@ -260,6 +260,8 @@ describe('ChicoryTV SPA scaffold', () => {
|
||||
language: 'en',
|
||||
name: 'Retro Cartoons',
|
||||
number: '5.1',
|
||||
// Server-derived preview eligibility (Task 2/60): required on the ChannelResponseModel row.
|
||||
preview: { availability: 'Unavailable', manifestUrl: null, unavailableReason: null },
|
||||
showInEpg: true,
|
||||
sortNumber: 5.1,
|
||||
streamingMode: 'HLS Direct'
|
||||
|
||||
@@ -2,6 +2,31 @@ import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-li
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { ChannelsScreen } from './ChannelsScreen';
|
||||
|
||||
// The channel preview panel mounts HlsPlayer, which imports hls.js. jsdom has no MediaSource, so
|
||||
// hls.js must never touch the real implementation here — mocked wholesale, same shape as
|
||||
// channels/ChannelPreviewPanel.test.tsx.
|
||||
const hlsMock = {
|
||||
isSupported: true,
|
||||
loadSource: vi.fn(),
|
||||
attachMedia: vi.fn(),
|
||||
on: vi.fn(),
|
||||
destroy: vi.fn()
|
||||
};
|
||||
|
||||
vi.mock('hls.js', () => {
|
||||
class MockHls {
|
||||
static isSupported() {
|
||||
return hlsMock.isSupported;
|
||||
}
|
||||
static Events = { MANIFEST_PARSED: 'hlsManifestParsed', ERROR: 'hlsError' };
|
||||
loadSource = hlsMock.loadSource;
|
||||
attachMedia = hlsMock.attachMedia;
|
||||
on = hlsMock.on;
|
||||
destroy = hlsMock.destroy;
|
||||
}
|
||||
return { default: MockHls };
|
||||
});
|
||||
|
||||
function jsonResponse(body: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), { headers: { 'Content-Type': 'application/json' }, status });
|
||||
}
|
||||
@@ -19,6 +44,10 @@ function channelRow(overrides: Record<string, unknown> = {}): Record<string, unk
|
||||
// The API always sends playoutCount; default to a healthy channel so only tests that opt in
|
||||
// render the "No playout" fault state.
|
||||
playoutCount: 1,
|
||||
// Server-derived preview eligibility (Task 2). Defaults to the conservative "no legacy preview
|
||||
// support data" case most existing fixtures assume; tests that need a different availability
|
||||
// override this explicitly.
|
||||
preview: { availability: 'Unavailable', manifestUrl: null, unavailableReason: null },
|
||||
showInEpg: true,
|
||||
sortNumber: 5.1,
|
||||
streamingMode: 'HLS Direct',
|
||||
@@ -266,6 +295,67 @@ describe('ChannelsScreen — load + render', () => {
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Preview unavailable for Retro Cartoons' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('enables preview for an available channel and opens the panel', async () => {
|
||||
mockApi({
|
||||
channels: [
|
||||
channelRow({
|
||||
name: 'Vaporwave',
|
||||
preview: { availability: 'Available', manifestUrl: '/iptv/channel/12.1.m3u8', unavailableReason: null }
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
render(<ChannelsScreen />);
|
||||
|
||||
const play = await screen.findByRole('button', { name: 'Preview Vaporwave' });
|
||||
expect(play).toBeEnabled();
|
||||
|
||||
fireEvent.click(play);
|
||||
|
||||
expect(await screen.findByText('Preview: Vaporwave')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('disables preview and explains why when the server says unavailable', async () => {
|
||||
mockApi({
|
||||
channels: [
|
||||
channelRow({
|
||||
name: 'Vaporwave',
|
||||
preview: {
|
||||
availability: 'Unavailable',
|
||||
manifestUrl: null,
|
||||
unavailableReason: 'IPTV JWT authentication is enabled'
|
||||
}
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
render(<ChannelsScreen />);
|
||||
|
||||
const play = await screen.findByRole('button', { name: /IPTV JWT authentication is enabled/ });
|
||||
expect(play).toBeDisabled();
|
||||
});
|
||||
|
||||
it('offers preview for a transport-stream channel via the forced-hls path', async () => {
|
||||
mockApi({
|
||||
channels: [
|
||||
channelRow({
|
||||
name: 'Retro TV',
|
||||
preview: {
|
||||
availability: 'ForcedHlsOnly',
|
||||
manifestUrl: '/iptv/channel/12.2.m3u8?mode=segmenter',
|
||||
unavailableReason: null
|
||||
},
|
||||
streamingMode: 'MPEG-TS'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
render(<ChannelsScreen />);
|
||||
|
||||
const play = await screen.findByRole('button', { name: 'Preview Retro TV' });
|
||||
expect(play).toBeEnabled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ChannelsScreen — filtering + selection', () => {
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
} from '../api';
|
||||
import { navigateToPath } from '../routing';
|
||||
import { usePrimaryAction } from '../primaryAction';
|
||||
import { ChannelPreviewPanel } from './channels/ChannelPreviewPanel';
|
||||
|
||||
type ChannelViewFilter = 'all' | 'onair' | 'disabled' | 'noplayout';
|
||||
|
||||
@@ -193,6 +194,7 @@ export function ChannelsScreen() {
|
||||
const [mutationError, setMutationError] = useState<string | null>(null);
|
||||
const [mutating, setMutating] = useState(false);
|
||||
const [creatingBlank, setCreatingBlank] = useState(false);
|
||||
const [previewChannelId, setPreviewChannelId] = useState<null | number>(null);
|
||||
|
||||
// TopBar "Add Channel" primary action → the library-to-lineup builder.
|
||||
usePrimaryAction('channels', () => navigateToPath('/app/new-channel'));
|
||||
@@ -474,6 +476,7 @@ export function ChannelsScreen() {
|
||||
key={group}
|
||||
mutating={mutating}
|
||||
onDelete={deleteOne}
|
||||
onPreview={setPreviewChannelId}
|
||||
onToggle={toggleOne}
|
||||
selectedIds={selectedIds}
|
||||
statesById={statesById}
|
||||
@@ -487,6 +490,22 @@ export function ChannelsScreen() {
|
||||
<span><code>{groups.length}</code> groups</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{previewChannelId !== null &&
|
||||
(() => {
|
||||
const previewChannel = channels.find((channel) => channel.id === previewChannelId);
|
||||
if (!previewChannel) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<ChannelPreviewPanel
|
||||
channel={previewChannel}
|
||||
nowPlaying={statesById.get(previewChannelId)?.nowPlaying ?? null}
|
||||
onClose={() => setPreviewChannelId(null)}
|
||||
open
|
||||
/>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -496,6 +515,7 @@ function ChannelGroupRows({
|
||||
group,
|
||||
mutating,
|
||||
onDelete,
|
||||
onPreview,
|
||||
onToggle,
|
||||
selectedIds,
|
||||
statesById
|
||||
@@ -504,6 +524,7 @@ function ChannelGroupRows({
|
||||
group: string;
|
||||
mutating: boolean;
|
||||
onDelete: (channel: ChannelSummary) => void;
|
||||
onPreview: (channelId: number) => void;
|
||||
onToggle: (channelId: number) => void;
|
||||
selectedIds: Set<number>;
|
||||
statesById: Map<number, ChannelState>;
|
||||
@@ -521,6 +542,7 @@ function ChannelGroupRows({
|
||||
key={channel.id}
|
||||
mutating={mutating}
|
||||
onDelete={onDelete}
|
||||
onPreview={onPreview}
|
||||
onToggle={onToggle}
|
||||
selected={selectedIds.has(channel.id)}
|
||||
state={statesById.get(channel.id) ?? null}
|
||||
@@ -538,6 +560,7 @@ function ChannelTableRow({
|
||||
channel,
|
||||
mutating,
|
||||
onDelete,
|
||||
onPreview,
|
||||
onToggle,
|
||||
selected,
|
||||
state
|
||||
@@ -545,6 +568,7 @@ function ChannelTableRow({
|
||||
channel: ChannelSummary;
|
||||
mutating: boolean;
|
||||
onDelete: (channel: ChannelSummary) => void;
|
||||
onPreview: (channelId: number) => void;
|
||||
onToggle: (channelId: number) => void;
|
||||
selected: boolean;
|
||||
state: ChannelState | null;
|
||||
@@ -595,7 +619,18 @@ function ChannelTableRow({
|
||||
<td className="ctv-channel-ffmpeg">{channel.ffmpegProfile || 'Unassigned'}</td>
|
||||
<td>
|
||||
<div className="ctv-channel-actions">
|
||||
<IconButton disabled size="sm" title={`Preview unavailable for ${channel.name}`}>
|
||||
<IconButton
|
||||
disabled={channel.preview.availability === 'Unavailable'}
|
||||
onClick={() => onPreview(channel.id)}
|
||||
size="sm"
|
||||
title={
|
||||
channel.preview.availability === 'Unavailable'
|
||||
? channel.preview.unavailableReason
|
||||
? `Preview unavailable for ${channel.name} — ${channel.preview.unavailableReason}`
|
||||
: `Preview unavailable for ${channel.name}`
|
||||
: `Preview ${channel.name}`
|
||||
}
|
||||
>
|
||||
<Play aria-hidden="true" size={15} />
|
||||
</IconButton>
|
||||
<IconButton onClick={() => navigateToPath(`/app/edit-channel/${channel.id}`)} size="sm" title={`Edit ${channel.name}`}>
|
||||
|
||||
Reference in New Issue
Block a user