feat(72): flag channels that will never play in the lineup

Surfaces the per-channel playout count the previous commit put on the API as
the fault state #72 calls "the important one": a channel with no playout can
never play, and until now the lineup gave no sign of it.

- "No playout" renders as a Badge with visible text rather than another
  single-letter marker like D/H. D/H flag states the user chose deliberately;
  this is a fault they need to notice and act on, and a tooltip-only glyph is
  invisible on touch and easy to miss in a long lineup.
- A "Problems" segmented filter answers the issue's actual goal — seeing the
  health of a LARGE lineup at a glance — by collapsing it to just the faults.
- `willNeverPlay` is one predicate shared by the badge, the count and the
  filter, so the three cannot disagree.

Mirror channels relay their source's playouts and the server folds those into
playoutCount, so a working mirror is not false-flagged (covered by a test).

Deliberately not approximated here, per the design pass: an empty schedule
behind an existing playout (EmptyScheduleHealthCheck only understands Classic
ProgramSchedule playouts — a badge driven by it would silently lie on Block,
Sequential, Scripted and ExternalJson channels) and broken/missing sources
(FileNotFound/Unavailable are server-wide counts with no channel attribution).
Both stay open on #72 rather than shipping a signal that is wrong for four of
the five schedule kinds.

The test fixture now sends playoutCount, matching the API, so the fault state
is opt-in per test instead of depending on an absent field.

Refs #72
This commit is contained in:
2026-07-17 17:51:26 +02:00
parent 1a40b4a8e6
commit 6cd5471500
2 changed files with 62 additions and 1 deletions
+40
View File
@@ -16,6 +16,9 @@ function channelRow(overrides: Record<string, unknown> = {}): Record<string, unk
language: 'en',
name: 'Retro Cartoons',
number: '5.1',
// The API always sends playoutCount; default to a healthy channel so only tests that opt in
// render the "No playout" fault state.
playoutCount: 1,
showInEpg: true,
sortNumber: 5.1,
streamingMode: 'HLS Direct',
@@ -174,6 +177,43 @@ describe('ChannelsScreen — load + render', () => {
expect(handle.fetchSpy).toHaveBeenCalledWith('/api/v1/channels/state', expect.any(Object));
});
// #72: a channel with no playout can never play. This is the fault state the issue calls
// "the important one" — it must be visible without hovering.
it('flags a channel with no playout and lets the lineup be filtered down to the faults', async () => {
mockApi({
channels: [
channelRow({ id: 1, name: 'Healthy', number: '1', playoutCount: 1 }),
channelRow({ id: 2, name: 'Broken', number: '2', playoutCount: 0 })
]
});
render(<ChannelsScreen />);
expect(await screen.findByRole('table', { name: 'Channels lineup' })).toBeInTheDocument();
// Visible text, not a title-only affordance.
expect(screen.getByText('No playout')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Problems 1' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'Problems 1' }));
expect(screen.getByText('Broken')).toBeInTheDocument();
expect(screen.queryByText('Healthy')).not.toBeInTheDocument();
});
it('does not flag a mirror channel that relays its source playouts', async () => {
// The server folds the mirror source's playouts into playoutCount, so a working mirror reports
// a non-zero count and must not be flagged. Guards the mirror half of the API contract.
mockApi({
channels: [channelRow({ id: 1, name: 'Mirror Of One', number: '9', playoutCount: 1 })]
});
render(<ChannelsScreen />);
expect(await screen.findByRole('table', { name: 'Channels lineup' })).toBeInTheDocument();
expect(screen.queryByText('No playout')).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Problems 0' })).toBeInTheDocument();
});
it('polls only channel state after the initial load', async () => {
const intervalHandlers: Array<() => void> = [];
vi.spyOn(window, 'setInterval').mockImplementation((handler) => {
+22 -1
View File
@@ -27,7 +27,16 @@ import {
import { navigateToPath } from '../routing';
import { usePrimaryAction } from '../primaryAction';
type ChannelViewFilter = 'all' | 'onair' | 'disabled';
type ChannelViewFilter = 'all' | 'onair' | 'disabled' | 'problems';
// #72: a channel with no playout can never play — the dominant "misconfigured lineup" case, and the
// only per-channel failure the API can answer cheaply today. A mirror channel relays its source's
// playouts, and the server already folds those into playoutCount, so mirrors are not false-flagged.
// Deliberately NOT covered here: an empty schedule behind an existing playout, and broken/missing
// sources — see #72 for why both are deferred rather than approximated.
function willNeverPlay(channel: ChannelSummary): boolean {
return channel.playoutCount === 0;
}
const streamingModeBadgeTones: Record<string, 'accent' | 'neutral'> = {
'HLS Direct': 'neutral',
@@ -193,6 +202,7 @@ export function ChannelsScreen() {
const statesById = stateByChannelId(query.data.channelStates);
const onAirCount = query.data.channelStates.filter((state) => state.onAir).length;
const disabledCount = channels.filter((channel) => !channel.isEnabled).length;
const problemCount = channels.filter(willNeverPlay).length;
const visibleChannels = channels.filter((channel) => {
if (filter === 'onair') {
return statesById.get(channel.id)?.onAir === true;
@@ -202,6 +212,10 @@ export function ChannelsScreen() {
return !channel.isEnabled;
}
if (filter === 'problems') {
return willNeverPlay(channel);
}
return true;
});
const groups = groupedChannels(visibleChannels);
@@ -396,6 +410,7 @@ export function ChannelsScreen() {
<button type="button" aria-pressed={filter === 'all'} onClick={() => changeFilter('all')}>All <code>{channels.length}</code></button>
<button type="button" aria-pressed={filter === 'onair'} onClick={() => changeFilter('onair')}>On air <code>{onAirCount}</code></button>
<button type="button" aria-pressed={filter === 'disabled'} onClick={() => changeFilter('disabled')}>Disabled <code>{disabledCount}</code></button>
<button type="button" aria-pressed={filter === 'problems'} onClick={() => changeFilter('problems')}>Problems <code>{problemCount}</code></button>
</div>
<span className="ctv-channels-spacer" />
<span className="ctv-channels-live"><StatusDot status="live" size={7} /><code>{onAirCount}</code> on air</span>
@@ -539,6 +554,12 @@ function ChannelTableRow({
<span className="ctv-channel-markers">
{!channel.isEnabled && <Marker title="Disabled">D</Marker>}
{!channel.showInEpg && <Marker title="Hidden from EPG">H</Marker>}
{/*
Spelled out rather than compressed to a letter marker like D/H: those flag states the
user chose deliberately, whereas this one is a fault they need to notice and act on.
A tooltip-only glyph would be invisible on touch and easy to miss in a long lineup.
*/}
{willNeverPlay(channel) && <Badge tone="error">No playout</Badge>}
</span>
<small>{channel.language || 'Language unset'}</small>
</div>