refactor(spa): extract playouts screen
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 11s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 11s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 17s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 4m49s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 6m21s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 11s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 11s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 17s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 4m49s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 6m21s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Move the Playouts UI, route wrapper, helpers, and detailed behavior tests into a colocated screen module while preserving App-level navigation coverage. Refs #245 Co-Authored-By: OpenAI Codex <codex@openai.com>
This commit is contained in:
@@ -54,6 +54,7 @@ keep append-only from accreting stale, contradictory, or unreadably-large histor
|
||||
- [2026-07-11 — Channel editor: bare-create entry point + external-logo mutual exclusion (#212)](#2026-07-11--channel-editor-bare-create-entry-point--external-logo-mutual-exclusion-212)
|
||||
- [2026-07-11 — EntityLocker: atomic flags + single-owner release discipline, no owner tokens (#231)](#2026-07-11--entitylocker-atomic-flags--single-owner-release-discipline-no-owner-tokens-231)
|
||||
- [2026-07-11 — Channels screen extraction (#244): single-file screen, no sibling helper dir (epic #243 phase 1)](#2026-07-11--channels-screen-extraction-244-single-file-screen-no-sibling-helper-dir-epic-243-phase-1)
|
||||
- [2026-07-14 — Playouts screen extraction (#245): screen-owned route wrapper (epic #243 phase 2)](#2026-07-14--playouts-screen-extraction-245-screen-owned-route-wrapper-epic-243-phase-2)
|
||||
- [2026-07-11 — Media-source management REST write API + SPA (#202)](#2026-07-11--media-source-management-rest-write-api--spa-202)
|
||||
- [2026-07-11 — Legacy→SPA redirect matcher: exact map + ordered segment-template patterns (#204)](#2026-07-11--legacyspa-redirect-matcher-exact-map--ordered-segment-template-patterns-204)
|
||||
- [2026-07-11 — Blazor removal auth posture: no new exposure beyond phase (a); real auth deferred to #197 (#206)](#2026-07-11--blazor-removal-auth-posture-no-new-exposure-beyond-phase-a-real-auth-deferred-to-197-206)
|
||||
@@ -1788,3 +1789,23 @@ explicit `Api:CorsAllowedOrigins` machine-client path continues to work. It is a
|
||||
server-side HTTP clients, so Jellyfin's `/iptv/*` requests are unaffected; same-origin SPA artwork and
|
||||
IPTV requests remain allowed. This is defense in depth for browser embedding and does not replace CORS
|
||||
or authentication. Refs #330 #319 #314.
|
||||
|
||||
## 2026-07-14 — Playouts screen extraction (#245): screen-owned route wrapper (epic #243 phase 2)
|
||||
|
||||
Second bounded extraction under the App.tsx modularization epic (#243): the Playouts domain moved from
|
||||
`web/src/App.tsx` into `web/src/screens/PlayoutsScreen.tsx`, including its loading/error/empty states,
|
||||
dialogs, mutations, timeline/filter helpers, and the existing `PlayoutsRouteScreen`. The dedicated
|
||||
`PlayoutScheduleEditors.tsx` modules remain separate. This is a pure structural move: no API, route, CSS,
|
||||
or runtime behavior changed; `App.tsx` retains only the import and `<PlayoutsRouteScreen />` dispatch.
|
||||
|
||||
**The unguarded route wrapper moves with the screen.** Playouts owns two sibling sub-path editors and,
|
||||
per `spa-conventions.md` §2, must keep its local pathname state plus `popstate` listener because App's
|
||||
allow-sub-path route object is reference-stable. Colocating the wrapper keeps that screen-specific route
|
||||
ownership beside the base screen while App-level tests retain the cross-route navigation assertions.
|
||||
|
||||
**Temporal mutation behavior stays verbatim.** `mutatingRef`, `runMutation`, and the explicit
|
||||
`query.refresh()` after a 409 moved as one unit. The extraction deliberately does not add mount/current
|
||||
guards to these pre-existing promise completions; changing those semantics belongs to a separate issue.
|
||||
Detailed behavior tests now render `PlayoutsScreen` directly with a scoped fetch mock, including the
|
||||
zero-playout Add Playout affordance, lock/409 handling, refresh/poll ownership, action and kind gates, and
|
||||
dialog flows. Refs #245 #243.
|
||||
|
||||
@@ -33,13 +33,14 @@ for the base path and every sub-path under it. `App`'s state update is
|
||||
`setActiveRoute(routeFromLocation())`; React's `useState` setter bails via `Object.is` when the new
|
||||
value is reference-equal to the old one — so navigating from `/app/blocks` to `/app/blocks/42` (or
|
||||
between `/app/blocks/42` and `/app/blocks/17`) **never re-invokes `ScreenContent`** at the `App`
|
||||
level. See the comment block directly above `PlayoutsRouteScreen` in `App.tsx` (~line 3540) for the
|
||||
canonical explanation, and its implementation (`useState(() => window.location.pathname)` +
|
||||
level. See the comment block directly above `PlayoutsRouteScreen` in
|
||||
`screens/PlayoutsScreen.tsx` for the canonical explanation, and its implementation
|
||||
(`useState(() => window.location.pathname)` +
|
||||
`useEffect` with a `popstate` listener local to the wrapper component) for the fix.
|
||||
|
||||
Exemplars of screens that already do this correctly: `BlocksScreen.tsx`, `TemplatesScreen.tsx`,
|
||||
`DecosScreen.tsx`, `DecoTemplatesScreen.tsx`, and the `PlayoutsRouteScreen` wrapper in `App.tsx`
|
||||
(which owns two sibling sub-paths, `/playouts/{id}/alternate-schedules` and
|
||||
`DecosScreen.tsx`, `DecoTemplatesScreen.tsx`, and the `PlayoutsRouteScreen` wrapper colocated in
|
||||
`PlayoutsScreen.tsx` (which owns two sibling sub-paths, `/playouts/{id}/alternate-schedules` and
|
||||
`/playouts/{id}/templates`, dispatching internally via `parsePlayoutSubRoute`).
|
||||
|
||||
**Exception — a guarded sub-path route defers pathname ownership to App.** When a sub-path route's
|
||||
@@ -251,7 +252,7 @@ is gone. The SPA seams now are:
|
||||
- Every screen with meaningful logic gets a screen test; every API client module gets a
|
||||
param-mapping / URL-building test (e.g. `logs.test.ts` next to `logs.ts`).
|
||||
- `web/src/App.test.tsx` covers navigation + the route table, including regressions like the
|
||||
sub-path bug in §2 (see the tests around `PlayoutsRouteScreen`, ~line 1682+, that click into
|
||||
sub-path bug in §2 (see the tests around `PlayoutsRouteScreen` that click into
|
||||
`/app/playouts/{id}/...` sub-paths and assert the correct sub-screen rendered).
|
||||
- **Nav-label test-selector care**: `getByRole('link'/'button', { name: /Regex/ })` matches by
|
||||
substring by default — a loose regex can match more than one nav item. Verified example: the
|
||||
@@ -260,7 +261,8 @@ is gone. The SPA seams now are:
|
||||
contain "System". Anchor (`^`/`$`) or use exact strings in `getByRole` name matchers whenever a
|
||||
new label could be a substring of (or share a substring with) an existing one — check
|
||||
`App.tsx`'s nav `label:` list for collisions before picking a new label.
|
||||
- **Extracted-screen tests own their own fetch mock** (Schedules #207, Channels #244): when a
|
||||
- **Extracted-screen tests own their own fetch mock** (Schedules #207, Channels #244, Playouts
|
||||
#245): when a
|
||||
screen is pulled out of `App.tsx` into `web/src/screens/<Name>Screen.tsx`, its colocated
|
||||
`<Name>Screen.test.tsx` builds a **self-contained** `vi.spyOn(window, 'fetch')` mock scoped to
|
||||
that screen's own endpoints (plus local `jsonResponse`/fixture-factory helpers) and renders the
|
||||
@@ -269,7 +271,7 @@ is gone. The SPA seams now are:
|
||||
screen (route to it, assert it mounted and hit its own endpoint) plus genuinely cross-cutting
|
||||
shell concerns (route table, sub-path ownership §2, the unsaved-changes/popstate guard §8, the
|
||||
TopBar action wiring). Detailed screen behavior lives in the screen's own test file. See
|
||||
`ChannelsScreen.test.tsx` / `SchedulesScreen.test.tsx` for the shape.
|
||||
`ChannelsScreen.test.tsx` / `SchedulesScreen.test.tsx` / `PlayoutsScreen.test.tsx` for the shape.
|
||||
|
||||
## 7. Verification gate — run before every commit touching `web/`
|
||||
|
||||
|
||||
+6
-628
@@ -646,34 +646,10 @@ describe('ChicoryTV SPA scaffold', () => {
|
||||
expect((await screen.findAllByRole('button', { name: 'Add schedule' })).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('renders the Playouts monitor from live playout and channel state APIs', async () => {
|
||||
it('routes to the extracted Playouts screen and mounts its query', async () => {
|
||||
mockDashboardApi({
|
||||
channelStates: [
|
||||
{
|
||||
channelId: 1,
|
||||
channelNumber: '5.1',
|
||||
onAir: true,
|
||||
nowPlaying: {
|
||||
finishUtc: '2026-07-05T20:30:00Z',
|
||||
startUtc: '2026-07-05T20:00:00Z',
|
||||
title: 'Saturday Morning Cartoons'
|
||||
}
|
||||
}
|
||||
],
|
||||
playoutDetails: playout({ id: 20, playoutMode: 'Continuous', scheduleFile: '/config/schedules/retro.json' }),
|
||||
playoutItems: [
|
||||
playoutItem({ title: 'Saturday Morning Cartoons', start: '2026-07-05T20:00:00Z', finish: '2026-07-05T20:30:00Z' }),
|
||||
playoutItem({ title: 'Station ID', start: '2026-07-05T20:30:00Z', finish: '2026-07-05T20:31:00Z', duration: '00:01:00' }),
|
||||
playoutItem({ title: 'Moon Patrol', start: '2026-07-05T20:31:00Z', finish: '2026-07-05T21:00:00Z' })
|
||||
],
|
||||
playoutWarningsCount: 3,
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1', scheduleName: 'Prime Time Cartoons' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24', scheduleName: 'News Rotation' })
|
||||
],
|
||||
totalCount: 2
|
||||
}
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
@@ -681,20 +657,7 @@ describe('ChicoryTV SPA scaffold', () => {
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
expect(screen.getByText('2 playouts loaded')).toBeInTheDocument();
|
||||
expect(screen.getByText('3 warnings')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('Saturday Morning Cartoons').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('Moon Patrol').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('Station ID').length).toBeGreaterThan(0);
|
||||
// Real items carry fillerKind 'None' and must not be badged as filler.
|
||||
expect(screen.queryByText('Filler')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Metadata preview only')).toBeInTheDocument();
|
||||
expect(screen.getByDisplayValue('Continuous')).toBeInTheDocument();
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20/items', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/warnings/count', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/channels/state', expect.any(Object));
|
||||
});
|
||||
|
||||
it('renders the extracted Libraries screen from live media source and scan status APIs (#202)', async () => {
|
||||
@@ -720,109 +683,14 @@ describe('ChicoryTV SPA scaffold', () => {
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/libraries/scan-status', expect.any(Object));
|
||||
});
|
||||
|
||||
it('toggles Show filler to refetch playout items with showFiller=true and badge filler rows', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [
|
||||
playoutItem({ title: 'Saturday Morning Cartoons', start: '2026-07-05T20:00:00Z', finish: '2026-07-05T20:30:00Z' }),
|
||||
playoutItem({ title: 'Station ID', start: '2026-07-05T20:30:00Z', finish: '2026-07-05T20:31:00Z', duration: '00:01:00', fillerKind: 'PreRoll' })
|
||||
],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
// Toggle off: the filler item is not requested, so no Filler badge renders.
|
||||
expect(screen.queryByText('Station ID')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('Filler')).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('switch', { name: 'Show filler' }));
|
||||
|
||||
expect((await screen.findAllByText('Station ID')).length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('Filler')).toBeInTheDocument();
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20/items?showFiller=true', expect.any(Object));
|
||||
});
|
||||
|
||||
it('fetches the Playouts screen data exactly once on mount and only polls channel state', async () => {
|
||||
const intervalHandlers: Array<() => void> = [];
|
||||
vi.spyOn(window, 'setInterval').mockImplementation((handler: TimerHandler) => {
|
||||
if (typeof handler === 'function') {
|
||||
intervalHandlers.push(handler as () => void);
|
||||
}
|
||||
|
||||
return intervalHandlers.length;
|
||||
});
|
||||
vi.spyOn(window, 'clearInterval').mockImplementation(() => undefined);
|
||||
mockDashboardApi({
|
||||
channelStates: [
|
||||
{ channelId: 1, channelNumber: '5.1', onAir: true, nowPlaying: null }
|
||||
],
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
// The Dashboard also fetches /api/v1/playouts on load; measure the Playouts
|
||||
// screen's own contribution as a delta instead of absorbing that prefetch.
|
||||
await waitFor(() => {
|
||||
expect(fetchCount('/api/v1/playouts')).toBeGreaterThan(0);
|
||||
});
|
||||
const playoutFetchesBeforeNavigation = fetchCount('/api/v1/playouts');
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforeNavigation + 1);
|
||||
expect(fetchCount('/api/v1/playouts/20')).toBe(1);
|
||||
expect(fetchCount('/api/v1/playouts/20/items')).toBe(1);
|
||||
const playoutFetchesBeforePoll = fetchCount('/api/v1/playouts');
|
||||
const stateFetchesBeforePoll = fetchCount('/api/v1/channels/state');
|
||||
|
||||
intervalHandlers.forEach((handler) => handler());
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchCount('/api/v1/channels/state')).toBeGreaterThan(stateFetchesBeforePoll);
|
||||
});
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforePoll);
|
||||
expect(fetchCount('/api/v1/playouts/20/items')).toBe(1);
|
||||
});
|
||||
|
||||
it('switches selected playouts and fetches only the selected playout detail and items', async () => {
|
||||
mockDashboardApi({
|
||||
playoutDetails: playout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
playoutItems: [playoutItem({ title: 'Saturday Morning Cartoons' })],
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24' })
|
||||
],
|
||||
totalCount: 2
|
||||
}
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /News 24/ }));
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'News 24' })).toBeInTheDocument();
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/21', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/21/items', expect.any(Object));
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(2);
|
||||
});
|
||||
|
||||
// Regression coverage for the live-E2E finding: clicking "Alternate schedules" / "Templates"
|
||||
// used to update the URL via navigateToPath's pushState + synthetic popstate but never swap
|
||||
// the rendered screen, because routeFromLocation() returns the SAME ScreenRoute object
|
||||
// reference for /app/playouts and every /app/playouts/{id}/* sub-path, so React's
|
||||
// setActiveRoute(sameRef) bailed via Object.is and ScreenContent never re-ran. The fix (see
|
||||
// PlayoutsRouteScreen in App.tsx) mirrors BlocksScreen/TemplatesScreen/DecosScreen: it owns its
|
||||
// own pathname state and popstate listener instead of relying on the shell's activeRoute.
|
||||
// PlayoutsRouteScreen in screens/PlayoutsScreen.tsx) mirrors
|
||||
// BlocksScreen/TemplatesScreen/DecosScreen: it owns its own pathname state and popstate listener
|
||||
// instead of relying on the shell's activeRoute.
|
||||
it('client-side navigates into and back out of the alternate-schedules editor without a reload', async () => {
|
||||
mockDashboardApi({
|
||||
playoutDetails: playout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
@@ -918,496 +786,6 @@ describe('ChicoryTV SPA scaffold', () => {
|
||||
expect(window.location.pathname).toBe('/app/playouts');
|
||||
});
|
||||
|
||||
it('shows the Playouts loading state', async () => {
|
||||
vi.spyOn(window, 'fetch').mockImplementation((input: RequestInfo | URL) => {
|
||||
const path = input.toString();
|
||||
|
||||
if (path === '/api/v1/playouts') {
|
||||
return new Promise<Response>(() => {});
|
||||
}
|
||||
|
||||
if (path === '/api/v1/channels/state') {
|
||||
return Promise.resolve(jsonResponse([]));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/playouts/warnings/count') {
|
||||
return Promise.resolve(jsonResponse(0));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse([]));
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
|
||||
expect((await screen.findAllByText('Loading playouts')).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('shows Playouts API errors and retries 404 parent handling', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItemsFailure: {
|
||||
detail: 'Playout 20 was not found',
|
||||
status: 404,
|
||||
title: 'Not found'
|
||||
},
|
||||
playoutItemsFailuresBeforeSuccess: 1,
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
|
||||
expect(await screen.findByText('Playout 20 was not found')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Retry' }));
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an empty Playouts state when no playouts exist', async () => {
|
||||
mockDashboardApi({ playouts: { page: [], totalCount: 0 } });
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
|
||||
expect((await screen.findAllByText('No playouts returned')).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('resets all playouts with confirmation and refetches playout-scoped data', async () => {
|
||||
mockDashboardApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
const playoutFetchesBeforeReset = fetchCount('/api/v1/playouts');
|
||||
const itemFetchesBeforeReset = fetchCount('/api/v1/playouts/20/items');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reset all playouts' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/reset-all', expect.objectContaining({ method: 'POST' }));
|
||||
});
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforeReset + 1);
|
||||
expect(fetchCount('/api/v1/playouts/20/items')).toBe(itemFetchesBeforeReset + 1);
|
||||
});
|
||||
|
||||
it('shows ProblemDetails when the reset-all transport fails with a 5xx', async () => {
|
||||
// Backend contract: POST /api/v1/playouts/reset-all is an unconditional 202 — there is no
|
||||
// application-level error path today. This test guards client robustness only, against
|
||||
// transport/server failures (proxy errors, unhandled exceptions).
|
||||
mockDashboardApi({
|
||||
confirm: true,
|
||||
mutationFailures: {
|
||||
'/api/v1/playouts/reset-all': {
|
||||
detail: 'The playout worker crashed while queueing rebuilds',
|
||||
status: 500,
|
||||
title: 'Internal Server Error'
|
||||
}
|
||||
},
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reset all playouts' }));
|
||||
|
||||
expect(await screen.findByText('The playout worker crashed while queueing rebuilds')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('deletes the selected playout with confirmation and refetches', async () => {
|
||||
mockDashboardApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
const playoutFetchesBeforeDelete = fetchCount('/api/v1/playouts');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20', expect.objectContaining({ method: 'DELETE' }));
|
||||
});
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforeDelete + 1);
|
||||
});
|
||||
|
||||
it('resets the selected channel playout with confirmation', async () => {
|
||||
mockDashboardApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Classic' }),
|
||||
channelStates: [{ channelId: 7, channelNumber: '5.1', onAir: true, nowPlaying: null }],
|
||||
playouts: { page: [listPlayout({ id: 20, channelNumber: '5.1' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reset' }));
|
||||
|
||||
await waitFor(() => {
|
||||
// Keyed on the resolved channel id (7), not the playout id (20) or the channel number.
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/channels/7/playout/reset',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('shows both erase buttons for a Block playout and posts to the right routes', async () => {
|
||||
mockDashboardApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Block' }),
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'Block' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Erase items' }));
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/playouts/20/erase-items',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
);
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Erase items and history' }));
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/playouts/20/erase-items-and-history',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('shows only erase-items-and-history for a Classic playout', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'Classic' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Erase items and history' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Erase items' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows no erase buttons for an ExternalJson playout', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'ExternalJson' }),
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'ExternalJson' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Erase items and history' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Erase items' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('disables mutation buttons and shows a Building cue for a locked (building) playout', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Block' }),
|
||||
playouts: { page: [listPlayout({ id: 20, isLocked: true, scheduleKind: 'Block' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Building…')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Reset' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Erase items' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Erase items and history' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Delete' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('disables Alternate schedules for an on-demand Classic playout', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, playoutMode: 'OnDemand', scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20, playoutMode: 'OnDemand', scheduleKind: 'Classic' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Alternate schedules' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('enables Alternate schedules for a continuous Classic playout', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, playoutMode: 'Continuous', scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20, playoutMode: 'Continuous', scheduleKind: 'Classic' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Alternate schedules' })).toBeEnabled();
|
||||
});
|
||||
|
||||
it('opens the scheduling-context dialog for an item that has one', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem({ hasSchedulingContext: true, id: 99, title: 'Context Item' })],
|
||||
playoutDetails: playout({ id: 20 }),
|
||||
playoutSchedulingContext: 'SCHEDULING_CONTEXT_BODY',
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Scheduling context' }));
|
||||
|
||||
expect(await screen.findByText('SCHEDULING_CONTEXT_BODY')).toBeInTheDocument();
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/playouts/items/99/scheduling-context',
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('shows an error in the scheduling-context dialog when the fetch fails', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem({ hasSchedulingContext: true, id: 99, title: 'Context Item' })],
|
||||
playoutDetails: playout({ id: 20 }),
|
||||
playoutSchedulingContextFailure: { detail: 'No scheduling context available', status: 404 },
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Scheduling context' }));
|
||||
|
||||
expect(await screen.findByText('No scheduling context available')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show a scheduling-context button for items without one', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem({ hasSchedulingContext: false, id: 99 })],
|
||||
playoutDetails: playout({ id: 20 }),
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Scheduling context' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('filters the playout selector rail by channel name', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24', scheduleName: 'News Rotation' })
|
||||
],
|
||||
totalCount: 2
|
||||
}
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
const rail = screen.getByRole('complementary', { name: 'Playout selector' });
|
||||
expect(within(rail).getByRole('button', { name: /Retro Cartoons/ })).toBeInTheDocument();
|
||||
expect(within(rail).getByRole('button', { name: /News 24/ })).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Filter playouts'), { target: { value: 'News' } });
|
||||
|
||||
expect(within(rail).queryByRole('button', { name: /Retro Cartoons/ })).not.toBeInTheDocument();
|
||||
expect(within(rail).getByRole('button', { name: /News 24/ })).toBeInTheDocument();
|
||||
expect(screen.getByText('1 of 2 playouts')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders honestly when totalCount exceeds the returned page length', async () => {
|
||||
mockDashboardApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutItemsTotalCount: 500,
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24' })
|
||||
],
|
||||
totalCount: 150
|
||||
}
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
// Only 2 of 150 rows were returned; the count label must not claim all 150 loaded.
|
||||
expect(screen.getByText('2 of 150 playouts')).toBeInTheDocument();
|
||||
// Items page is also partial (1 of 500); the monitor must still render without crashing.
|
||||
expect(screen.getAllByText('Saturday Morning Cartoons').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('creates a classic playout from the Add Playout dialog and selects it', async () => {
|
||||
mockDashboardApi({
|
||||
channels: [channelSummary({ id: 1, name: 'Retro Cartoons', number: '5' })],
|
||||
createPlayoutResponse: playout({ id: 42 }),
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 },
|
||||
schedules: [schedule({ id: 7, name: 'Weekend Lineup' })]
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add Playout' }));
|
||||
expect(await screen.findByText('Add playout')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Channel'), { target: { value: '1' } });
|
||||
await screen.findByRole('option', { name: 'Weekend Lineup' });
|
||||
fireEvent.change(screen.getByLabelText('Classic schedule'), { target: { value: '7' } });
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Create' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(requestBodyFor('/api/v1/playouts')).toMatchObject({
|
||||
channelId: 1,
|
||||
programScheduleId: 7,
|
||||
scheduleKind: 'Classic'
|
||||
});
|
||||
});
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts', expect.objectContaining({ method: 'POST' }));
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('Add playout')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('shows the create-playout error inline when the API rejects the request', async () => {
|
||||
mockDashboardApi({
|
||||
channels: [channelSummary({ id: 1, name: 'Retro Cartoons', number: '5' })],
|
||||
mutationFailures: {
|
||||
'/api/v1/playouts': {
|
||||
detail: 'Channel already has one playout',
|
||||
status: 422,
|
||||
title: 'Validation failed'
|
||||
}
|
||||
},
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 },
|
||||
schedules: [schedule({ id: 7, name: 'Weekend Lineup' })]
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add Playout' }));
|
||||
expect(await screen.findByText('Add playout')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Channel'), { target: { value: '1' } });
|
||||
await screen.findByRole('option', { name: 'Weekend Lineup' });
|
||||
fireEvent.change(screen.getByLabelText('Classic schedule'), { target: { value: '7' } });
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Create' }));
|
||||
|
||||
expect(await screen.findByText('Channel already has one playout')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('edits daily rebuild time from the playout detail panel', async () => {
|
||||
mockDashboardApi({
|
||||
playoutDetails: playout({ id: 20, dailyRebuildTime: '04:00:00' }),
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 },
|
||||
updatePlayoutDetailsResponse: playout({ id: 20, dailyRebuildTime: '05:00:00' })
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit details' }));
|
||||
expect(await screen.findByText('Edit playout details')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Daily reset time'), { target: { value: '05:00:00' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save changes' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(requestBodyFor('/api/v1/playouts/20')).toMatchObject({ dailyRebuildTime: '05:00:00' });
|
||||
});
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20', expect.objectContaining({ method: 'PUT' }));
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('Edit playout details')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('shows the schedule-file field only for file-backed playout kinds when editing', async () => {
|
||||
mockDashboardApi({
|
||||
playoutDetails: playout({ id: 20, scheduleFile: '/config/schedule.yml', scheduleKind: 'Sequential' }),
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'Sequential' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: /Playouts/ }));
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit details' }));
|
||||
expect(await screen.findByText('Edit playout details')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByLabelText('Sequential schedule')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the dashboard loading state while requests are pending', async () => {
|
||||
vi.spyOn(window, 'fetch').mockImplementation(() => new Promise<Response>(() => {}));
|
||||
|
||||
|
||||
+3
-1069
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,901 @@
|
||||
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { PlayoutsScreen } from './PlayoutsScreen';
|
||||
|
||||
function jsonResponse(body: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
status
|
||||
});
|
||||
}
|
||||
|
||||
// PlayoutListItemResponseModel: rail rows have no detail-only fields.
|
||||
function listPlayout(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
||||
return {
|
||||
buildStatus: {
|
||||
lastBuild: '2026-07-05T19:00:00Z',
|
||||
message: null,
|
||||
success: true
|
||||
},
|
||||
channelName: 'Retro Cartoons',
|
||||
channelNumber: '5.1',
|
||||
dailyRebuildTime: '04:00:00',
|
||||
id: 20,
|
||||
isLocked: false,
|
||||
scheduleKind: 'Classic',
|
||||
scheduleName: 'Prime Time Cartoons',
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
// PlayoutResponseModel adds detail-only fields to the list row.
|
||||
function playout(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
||||
return listPlayout({
|
||||
playoutMode: 'Continuous',
|
||||
scheduleFile: null,
|
||||
...overrides
|
||||
});
|
||||
}
|
||||
|
||||
// The backend always emits fillerKind; real content carries None.
|
||||
function playoutItem(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
||||
return {
|
||||
duration: '00:30:00',
|
||||
fillerKind: 'None',
|
||||
finish: '2026-07-05T20:30:00Z',
|
||||
start: '2026-07-05T20:00:00Z',
|
||||
title: 'Saturday Morning Cartoons',
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
function schedule(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
||||
return {
|
||||
fixedStartTimeBehavior: 'Flexible',
|
||||
id: 1,
|
||||
keepMultiPartEpisodesTogether: true,
|
||||
name: 'Default Schedule',
|
||||
randomStartPoint: false,
|
||||
shuffleScheduleItems: false,
|
||||
treatCollectionsAsShows: false,
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
function channelSummary(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
||||
return {
|
||||
categories: '',
|
||||
ffmpegProfile: '1080p H.264',
|
||||
group: 'ChicoryTV',
|
||||
id: 1,
|
||||
isEnabled: true,
|
||||
language: 'English',
|
||||
name: 'Movies',
|
||||
number: '5',
|
||||
showInEpg: true,
|
||||
sortNumber: 5,
|
||||
streamingMode: 'HttpLiveStreamingSegmenter',
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
interface Problem {
|
||||
detail?: string;
|
||||
status?: number;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
interface MockOptions {
|
||||
channels?: unknown[];
|
||||
channelStates?: unknown[];
|
||||
confirm?: boolean;
|
||||
createPlayoutResponse?: unknown;
|
||||
mutationFailures?: Record<string, Problem>;
|
||||
playoutDetails?: unknown;
|
||||
playoutItems?: unknown[];
|
||||
playoutItemsFailure?: Problem | null;
|
||||
playoutItemsFailuresBeforeSuccess?: number;
|
||||
playoutItemsTotalCount?: number | null;
|
||||
playoutSchedulingContext?: string;
|
||||
playoutSchedulingContextFailure?: Problem | null;
|
||||
playoutWarningsCount?: number;
|
||||
playouts?: unknown;
|
||||
schedules?: unknown[];
|
||||
updatePlayoutDetailsResponse?: unknown;
|
||||
}
|
||||
|
||||
function mockApi(options: MockOptions = {}): void {
|
||||
const channels = options.channels ?? [];
|
||||
const channelStates = options.channelStates ?? [];
|
||||
const mutationFailures = options.mutationFailures ?? {};
|
||||
const playoutDetails = options.playoutDetails ?? null;
|
||||
const playoutItems = options.playoutItems ?? [];
|
||||
const playoutSchedulingContext = options.playoutSchedulingContext ?? '{\n "sample": true\n}';
|
||||
const playoutWarningsCount = options.playoutWarningsCount ?? 0;
|
||||
const playouts = options.playouts ?? { page: [], totalCount: 0 };
|
||||
const schedules = options.schedules ?? [];
|
||||
let remainingPlayoutItemsFailures = options.playoutItemsFailuresBeforeSuccess ?? 0;
|
||||
|
||||
vi.spyOn(window, 'confirm').mockReturnValue(options.confirm ?? false);
|
||||
vi.spyOn(window, 'fetch').mockImplementation((input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const path = input.toString();
|
||||
const method = (init?.method ?? 'GET').toUpperCase();
|
||||
|
||||
if (path === '/api/v1/channels') {
|
||||
return Promise.resolve(jsonResponse(channels));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/channels/state') {
|
||||
return Promise.resolve(jsonResponse(channelStates));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/schedules') {
|
||||
return Promise.resolve(jsonResponse(schedules));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/decos') {
|
||||
return Promise.resolve(jsonResponse([]));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/playouts') {
|
||||
if (method === 'POST') {
|
||||
const failure = mutationFailures[path];
|
||||
if (failure) {
|
||||
return Promise.resolve(jsonResponse(failure, failure.status ?? 422));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse(options.createPlayoutResponse ?? playout({ id: 99 }), 201));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse(playouts));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/playouts/warnings/count') {
|
||||
return Promise.resolve(jsonResponse(playoutWarningsCount));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/playouts/reset-all') {
|
||||
const failure = mutationFailures[path];
|
||||
if (failure) {
|
||||
return Promise.resolve(jsonResponse(failure, failure.status ?? 422));
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 202 }));
|
||||
}
|
||||
|
||||
if (/^\/api\/v1\/channels\/\d+\/playout\/reset$/.test(path)) {
|
||||
const failure = mutationFailures[path];
|
||||
if (failure) {
|
||||
return Promise.resolve(jsonResponse(failure, failure.status ?? 422));
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 204 }));
|
||||
}
|
||||
|
||||
if (/^\/api\/v1\/playouts\/\d+\/erase-items(-and-history)?$/.test(path)) {
|
||||
const failure = mutationFailures[path];
|
||||
if (failure) {
|
||||
return Promise.resolve(jsonResponse(failure, failure.status ?? 422));
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 204 }));
|
||||
}
|
||||
|
||||
if (/^\/api\/v1\/playouts\/items\/\d+\/scheduling-context$/.test(path)) {
|
||||
if (options.playoutSchedulingContextFailure) {
|
||||
const failure = options.playoutSchedulingContextFailure;
|
||||
return Promise.resolve(jsonResponse(failure, failure.status ?? 404));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse({ context: playoutSchedulingContext }));
|
||||
}
|
||||
|
||||
const itemsMatch = path.match(/^\/api\/v1\/playouts\/\d+\/items(\?(?<query>.*))?$/);
|
||||
if (itemsMatch) {
|
||||
if (remainingPlayoutItemsFailures > 0) {
|
||||
remainingPlayoutItemsFailures -= 1;
|
||||
return Promise.resolve(jsonResponse(options.playoutItemsFailure, options.playoutItemsFailure?.status ?? 404));
|
||||
}
|
||||
|
||||
const showFiller = new URLSearchParams(itemsMatch.groups?.query ?? '').get('showFiller') === 'true';
|
||||
const page = showFiller
|
||||
? playoutItems
|
||||
: playoutItems.filter((item) => {
|
||||
const fillerKind = (item as { fillerKind?: null | string }).fillerKind;
|
||||
return fillerKind == null || fillerKind === 'None';
|
||||
});
|
||||
|
||||
return Promise.resolve(jsonResponse({
|
||||
page,
|
||||
totalCount: options.playoutItemsTotalCount ?? page.length
|
||||
}));
|
||||
}
|
||||
|
||||
if (/^\/api\/v1\/playouts\/\d+$/.test(path)) {
|
||||
const failure = mutationFailures[path];
|
||||
|
||||
if (method === 'PUT') {
|
||||
if (failure) {
|
||||
return Promise.resolve(jsonResponse(failure, failure.status ?? 422));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse(
|
||||
options.updatePlayoutDetailsResponse ?? playoutDetails ?? playout({ id: Number(path.split('/').at(-1)) })
|
||||
));
|
||||
}
|
||||
|
||||
if (method === 'DELETE') {
|
||||
if (failure) {
|
||||
return Promise.resolve(jsonResponse(failure, failure.status ?? 422));
|
||||
}
|
||||
|
||||
return Promise.resolve(new Response(null, { status: 204 }));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse(playoutDetails ?? playout({ id: Number(path.split('/').at(-1)) })));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse(null, 404));
|
||||
});
|
||||
}
|
||||
|
||||
function fetchCount(path: string): number {
|
||||
return vi.mocked(window.fetch).mock.calls.filter(([input]) => input.toString() === path).length;
|
||||
}
|
||||
|
||||
function requestBodyFor(path: string): Record<string, unknown> {
|
||||
const call = vi
|
||||
.mocked(window.fetch)
|
||||
.mock.calls.find(([input, init]) => input.toString() === path && init?.body != null);
|
||||
if (!call) {
|
||||
throw new Error('no request captured for ' + path);
|
||||
}
|
||||
|
||||
return JSON.parse(call[1]?.body as string) as Record<string, unknown>;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
window.history.replaceState(null, '', '/app/playouts');
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
window.history.replaceState(null, '', '/app/playouts');
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('PlayoutsScreen', () => {
|
||||
it('renders the Playouts monitor from live playout and channel state APIs', async () => {
|
||||
mockApi({
|
||||
channelStates: [
|
||||
{
|
||||
channelId: 1,
|
||||
channelNumber: '5.1',
|
||||
onAir: true,
|
||||
nowPlaying: {
|
||||
finishUtc: '2026-07-05T20:30:00Z',
|
||||
startUtc: '2026-07-05T20:00:00Z',
|
||||
title: 'Saturday Morning Cartoons'
|
||||
}
|
||||
}
|
||||
],
|
||||
playoutDetails: playout({ id: 20, playoutMode: 'Continuous', scheduleFile: '/config/schedules/retro.json' }),
|
||||
playoutItems: [
|
||||
playoutItem({ title: 'Saturday Morning Cartoons', start: '2026-07-05T20:00:00Z', finish: '2026-07-05T20:30:00Z' }),
|
||||
playoutItem({ title: 'Station ID', start: '2026-07-05T20:30:00Z', finish: '2026-07-05T20:31:00Z', duration: '00:01:00' }),
|
||||
playoutItem({ title: 'Moon Patrol', start: '2026-07-05T20:31:00Z', finish: '2026-07-05T21:00:00Z' })
|
||||
],
|
||||
playoutWarningsCount: 3,
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1', scheduleName: 'Prime Time Cartoons' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24', scheduleName: 'News Rotation' })
|
||||
],
|
||||
totalCount: 2
|
||||
}
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
expect(screen.getByText('2 playouts loaded')).toBeInTheDocument();
|
||||
expect(screen.getByText('3 warnings')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('Saturday Morning Cartoons').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('Moon Patrol').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('Station ID').length).toBeGreaterThan(0);
|
||||
// Real items carry fillerKind 'None' and must not be badged as filler.
|
||||
expect(screen.queryByText('Filler')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('Metadata preview only')).toBeInTheDocument();
|
||||
expect(screen.getByDisplayValue('Continuous')).toBeInTheDocument();
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20/items', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/warnings/count', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/channels/state', expect.any(Object));
|
||||
});
|
||||
|
||||
it('toggles Show filler to refetch playout items with showFiller=true and badge filler rows', async () => {
|
||||
mockApi({
|
||||
playoutItems: [
|
||||
playoutItem({ title: 'Saturday Morning Cartoons', start: '2026-07-05T20:00:00Z', finish: '2026-07-05T20:30:00Z' }),
|
||||
playoutItem({ title: 'Station ID', start: '2026-07-05T20:30:00Z', finish: '2026-07-05T20:31:00Z', duration: '00:01:00', fillerKind: 'PreRoll' })
|
||||
],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
// Toggle off: the filler item is not requested, so no Filler badge renders.
|
||||
expect(screen.queryByText('Station ID')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('Filler')).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('switch', { name: 'Show filler' }));
|
||||
|
||||
expect((await screen.findAllByText('Station ID')).length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('Filler')).toBeInTheDocument();
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20/items?showFiller=true', expect.any(Object));
|
||||
});
|
||||
|
||||
it('fetches the Playouts screen data exactly once on mount and only polls channel state', async () => {
|
||||
const intervalHandlers: Array<() => void> = [];
|
||||
vi.spyOn(window, 'setInterval').mockImplementation((handler: TimerHandler) => {
|
||||
if (typeof handler === 'function') {
|
||||
intervalHandlers.push(handler as () => void);
|
||||
}
|
||||
|
||||
return intervalHandlers.length;
|
||||
});
|
||||
vi.spyOn(window, 'clearInterval').mockImplementation(() => undefined);
|
||||
mockApi({
|
||||
channelStates: [
|
||||
{ channelId: 1, channelNumber: '5.1', onAir: true, nowPlaying: null }
|
||||
],
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(1);
|
||||
expect(fetchCount('/api/v1/playouts/20')).toBe(1);
|
||||
expect(fetchCount('/api/v1/playouts/20/items')).toBe(1);
|
||||
const playoutFetchesBeforePoll = fetchCount('/api/v1/playouts');
|
||||
const stateFetchesBeforePoll = fetchCount('/api/v1/channels/state');
|
||||
|
||||
intervalHandlers.forEach((handler) => handler());
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchCount('/api/v1/channels/state')).toBeGreaterThan(stateFetchesBeforePoll);
|
||||
});
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforePoll);
|
||||
expect(fetchCount('/api/v1/playouts/20/items')).toBe(1);
|
||||
});
|
||||
|
||||
it('switches selected playouts and fetches only the selected playout detail and items', async () => {
|
||||
mockApi({
|
||||
playoutDetails: playout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
playoutItems: [playoutItem({ title: 'Saturday Morning Cartoons' })],
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24' })
|
||||
],
|
||||
totalCount: 2
|
||||
}
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /News 24/ }));
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'News 24' })).toBeInTheDocument();
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/21', expect.any(Object));
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/21/items', expect.any(Object));
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(1);
|
||||
});
|
||||
|
||||
it('shows the Playouts loading state', async () => {
|
||||
vi.spyOn(window, 'fetch').mockImplementation((input: RequestInfo | URL) => {
|
||||
const path = input.toString();
|
||||
|
||||
if (path === '/api/v1/playouts') {
|
||||
return new Promise<Response>(() => {});
|
||||
}
|
||||
|
||||
if (path === '/api/v1/channels/state') {
|
||||
return Promise.resolve(jsonResponse([]));
|
||||
}
|
||||
|
||||
if (path === '/api/v1/playouts/warnings/count') {
|
||||
return Promise.resolve(jsonResponse(0));
|
||||
}
|
||||
|
||||
return Promise.resolve(jsonResponse([]));
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
|
||||
expect((await screen.findAllByText('Loading playouts')).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('shows Playouts API errors and retries 404 parent handling', async () => {
|
||||
mockApi({
|
||||
playoutItemsFailure: {
|
||||
detail: 'Playout 20 was not found',
|
||||
status: 404,
|
||||
title: 'Not found'
|
||||
},
|
||||
playoutItemsFailuresBeforeSuccess: 1,
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
|
||||
expect(await screen.findByText('Playout 20 was not found')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Retry' }));
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an empty Playouts state when no playouts exist', async () => {
|
||||
mockApi({ playouts: { page: [], totalCount: 0 } });
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
|
||||
expect((await screen.findAllByText('No playouts returned')).length).toBeGreaterThan(0);
|
||||
expect(screen.getByRole('button', { name: 'Add Playout' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('resets all playouts with confirmation and refetches playout-scoped data', async () => {
|
||||
mockApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
const playoutFetchesBeforeReset = fetchCount('/api/v1/playouts');
|
||||
const itemFetchesBeforeReset = fetchCount('/api/v1/playouts/20/items');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reset all playouts' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/reset-all', expect.objectContaining({ method: 'POST' }));
|
||||
});
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforeReset + 1);
|
||||
expect(fetchCount('/api/v1/playouts/20/items')).toBe(itemFetchesBeforeReset + 1);
|
||||
});
|
||||
|
||||
it('shows ProblemDetails when the reset-all transport fails with a 5xx', async () => {
|
||||
// Backend contract: POST /api/v1/playouts/reset-all is an unconditional 202 — there is no
|
||||
// application-level error path today. This test guards client robustness only, against
|
||||
// transport/server failures (proxy errors, unhandled exceptions).
|
||||
mockApi({
|
||||
confirm: true,
|
||||
mutationFailures: {
|
||||
'/api/v1/playouts/reset-all': {
|
||||
detail: 'The playout worker crashed while queueing rebuilds',
|
||||
status: 500,
|
||||
title: 'Internal Server Error'
|
||||
}
|
||||
},
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reset all playouts' }));
|
||||
|
||||
expect(await screen.findByText('The playout worker crashed while queueing rebuilds')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('deletes the selected playout with confirmation and refetches', async () => {
|
||||
mockApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
const playoutFetchesBeforeDelete = fetchCount('/api/v1/playouts');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20', expect.objectContaining({ method: 'DELETE' }));
|
||||
});
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforeDelete + 1);
|
||||
});
|
||||
|
||||
it('resets the selected channel playout with confirmation', async () => {
|
||||
mockApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Classic' }),
|
||||
channelStates: [{ channelId: 7, channelNumber: '5.1', onAir: true, nowPlaying: null }],
|
||||
playouts: { page: [listPlayout({ id: 20, channelNumber: '5.1' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reset' }));
|
||||
|
||||
await waitFor(() => {
|
||||
// Keyed on the resolved channel id (7), not the playout id (20) or the channel number.
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/channels/7/playout/reset',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('shows both erase buttons for a Block playout and posts to the right routes', async () => {
|
||||
mockApi({
|
||||
confirm: true,
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Block' }),
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'Block' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Erase items' }));
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/playouts/20/erase-items',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
);
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Erase items and history' }));
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/playouts/20/erase-items-and-history',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('shows only erase-items-and-history for a Classic playout', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'Classic' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Erase items and history' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Erase items' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows no erase buttons for an ExternalJson playout', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'ExternalJson' }),
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'ExternalJson' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Erase items and history' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Erase items' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
it('refreshes after a 409 mutation conflict so the latest build lock can be rendered', async () => {
|
||||
mockApi({
|
||||
confirm: true,
|
||||
mutationFailures: {
|
||||
'/api/v1/playouts/20': {
|
||||
detail: 'A playout build is already in progress',
|
||||
status: 409,
|
||||
title: 'Conflict'
|
||||
}
|
||||
},
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
const playoutFetchesBeforeConflict = fetchCount('/api/v1/playouts');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
|
||||
|
||||
expect(await screen.findByText('A playout build is already in progress')).toBeInTheDocument();
|
||||
await waitFor(() => {
|
||||
expect(fetchCount('/api/v1/playouts')).toBe(playoutFetchesBeforeConflict + 1);
|
||||
});
|
||||
});
|
||||
|
||||
it('disables mutation buttons and shows a Building cue for a locked (building) playout', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, scheduleKind: 'Block' }),
|
||||
playouts: { page: [listPlayout({ id: 20, isLocked: true, scheduleKind: 'Block' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText('Building…')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Reset' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Erase items' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Erase items and history' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Delete' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('disables Alternate schedules for an on-demand Classic playout', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, playoutMode: 'OnDemand', scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20, playoutMode: 'OnDemand', scheduleKind: 'Classic' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Alternate schedules' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('enables Alternate schedules for a continuous Classic playout', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutDetails: playout({ id: 20, playoutMode: 'Continuous', scheduleKind: 'Classic' }),
|
||||
playouts: { page: [listPlayout({ id: 20, playoutMode: 'Continuous', scheduleKind: 'Classic' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Alternate schedules' })).toBeEnabled();
|
||||
});
|
||||
|
||||
it('opens the scheduling-context dialog for an item that has one', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem({ hasSchedulingContext: true, id: 99, title: 'Context Item' })],
|
||||
playoutDetails: playout({ id: 20 }),
|
||||
playoutSchedulingContext: 'SCHEDULING_CONTEXT_BODY',
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Scheduling context' }));
|
||||
|
||||
expect(await screen.findByText('SCHEDULING_CONTEXT_BODY')).toBeInTheDocument();
|
||||
await waitFor(() => {
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
'/api/v1/playouts/items/99/scheduling-context',
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('shows an error in the scheduling-context dialog when the fetch fails', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem({ hasSchedulingContext: true, id: 99, title: 'Context Item' })],
|
||||
playoutDetails: playout({ id: 20 }),
|
||||
playoutSchedulingContextFailure: { detail: 'No scheduling context available', status: 404 },
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Scheduling context' }));
|
||||
|
||||
expect(await screen.findByText('No scheduling context available')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show a scheduling-context button for items without one', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem({ hasSchedulingContext: false, id: 99 })],
|
||||
playoutDetails: playout({ id: 20 }),
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Scheduling context' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('filters the playout selector rail by channel name', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24', scheduleName: 'News Rotation' })
|
||||
],
|
||||
totalCount: 2
|
||||
}
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
const rail = screen.getByRole('complementary', { name: 'Playout selector' });
|
||||
expect(within(rail).getByRole('button', { name: /Retro Cartoons/ })).toBeInTheDocument();
|
||||
expect(within(rail).getByRole('button', { name: /News 24/ })).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Filter playouts'), { target: { value: 'News' } });
|
||||
|
||||
expect(within(rail).queryByRole('button', { name: /Retro Cartoons/ })).not.toBeInTheDocument();
|
||||
expect(within(rail).getByRole('button', { name: /News 24/ })).toBeInTheDocument();
|
||||
expect(screen.getByText('1 of 2 playouts')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders honestly when totalCount exceeds the returned page length', async () => {
|
||||
mockApi({
|
||||
playoutItems: [playoutItem()],
|
||||
playoutItemsTotalCount: 500,
|
||||
playouts: {
|
||||
page: [
|
||||
listPlayout({ id: 20, channelName: 'Retro Cartoons', channelNumber: '5.1' }),
|
||||
listPlayout({ id: 21, channelName: 'News 24', channelNumber: '24' })
|
||||
],
|
||||
totalCount: 150
|
||||
}
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
// Only 2 of 150 rows were returned; the count label must not claim all 150 loaded.
|
||||
expect(screen.getByText('2 of 150 playouts')).toBeInTheDocument();
|
||||
// Items page is also partial (1 of 500); the monitor must still render without crashing.
|
||||
expect(screen.getAllByText('Saturday Morning Cartoons').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('creates a classic playout from the Add Playout dialog and selects it', async () => {
|
||||
mockApi({
|
||||
channels: [channelSummary({ id: 1, name: 'Retro Cartoons', number: '5' })],
|
||||
createPlayoutResponse: playout({ id: 42 }),
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 },
|
||||
schedules: [schedule({ id: 7, name: 'Weekend Lineup' })]
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add Playout' }));
|
||||
expect(await screen.findByText('Add playout')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Channel'), { target: { value: '1' } });
|
||||
await screen.findByRole('option', { name: 'Weekend Lineup' });
|
||||
fireEvent.change(screen.getByLabelText('Classic schedule'), { target: { value: '7' } });
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Create' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(requestBodyFor('/api/v1/playouts')).toMatchObject({
|
||||
channelId: 1,
|
||||
programScheduleId: 7,
|
||||
scheduleKind: 'Classic'
|
||||
});
|
||||
});
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts', expect.objectContaining({ method: 'POST' }));
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('Add playout')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('shows the create-playout error inline when the API rejects the request', async () => {
|
||||
mockApi({
|
||||
channels: [channelSummary({ id: 1, name: 'Retro Cartoons', number: '5' })],
|
||||
mutationFailures: {
|
||||
'/api/v1/playouts': {
|
||||
detail: 'Channel already has one playout',
|
||||
status: 422,
|
||||
title: 'Validation failed'
|
||||
}
|
||||
},
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 },
|
||||
schedules: [schedule({ id: 7, name: 'Weekend Lineup' })]
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add Playout' }));
|
||||
expect(await screen.findByText('Add playout')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Channel'), { target: { value: '1' } });
|
||||
await screen.findByRole('option', { name: 'Weekend Lineup' });
|
||||
fireEvent.change(screen.getByLabelText('Classic schedule'), { target: { value: '7' } });
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Create' }));
|
||||
|
||||
expect(await screen.findByText('Channel already has one playout')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('edits daily rebuild time from the playout detail panel', async () => {
|
||||
mockApi({
|
||||
playoutDetails: playout({ id: 20, dailyRebuildTime: '04:00:00' }),
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20 })], totalCount: 1 },
|
||||
updatePlayoutDetailsResponse: playout({ id: 20, dailyRebuildTime: '05:00:00' })
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit details' }));
|
||||
expect(await screen.findByText('Edit playout details')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Daily reset time'), { target: { value: '05:00:00' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save changes' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(requestBodyFor('/api/v1/playouts/20')).toMatchObject({ dailyRebuildTime: '05:00:00' });
|
||||
});
|
||||
expect(window.fetch).toHaveBeenCalledWith('/api/v1/playouts/20', expect.objectContaining({ method: 'PUT' }));
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('Edit playout details')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('shows the schedule-file field only for file-backed playout kinds when editing', async () => {
|
||||
mockApi({
|
||||
playoutDetails: playout({ id: 20, scheduleFile: '/config/schedule.yml', scheduleKind: 'Sequential' }),
|
||||
playoutItems: [playoutItem()],
|
||||
playouts: { page: [listPlayout({ id: 20, scheduleKind: 'Sequential' })], totalCount: 1 }
|
||||
});
|
||||
|
||||
render(<PlayoutsScreen />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Retro Cartoons' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit details' }));
|
||||
expect(await screen.findByText('Edit playout details')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByLabelText('Sequential schedule')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user