From 19d0f311ac813fe030f13691a5d02a35eb651734 Mon Sep 17 00:00:00 2001 From: az3ta <24527778+az3ta@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:05:41 +0100 Subject: [PATCH 1/2] feat(radio): add station shortcuts to player views - Open the Add station editor from empty states and the station list - Share the station editor with Settings and add regression coverage --- .../src/components/radio/dj/dj-radio-list.tsx | 3 +- .../radio/src/components/radio/empty-hint.tsx | 5 +- .../src/components/radio/node/canvas-hint.tsx | 6 +- .../components/radio/node/node-rack.test.tsx | 1 + .../src/components/radio/node/node-rack.tsx | 5 +- .../single-player-station-list.stories.tsx | 7 +- .../single/single-player-station-list.tsx | 11 +- .../radio/single/single-player.test.tsx | 4 +- .../settings/add-station-button.tsx | 34 ++++ .../components/settings/add-station.test.tsx | 175 ++++++++++++++++++ .../src/components/settings/radio-dialog.tsx | 121 +----------- .../components/settings/radio-management.tsx | 86 +++++++-- .../src/components/settings/settings-form.tsx | 9 +- .../components/settings/station-editor.tsx | 137 ++++++++++++++ 14 files changed, 458 insertions(+), 146 deletions(-) create mode 100644 apps/radio/src/components/settings/add-station-button.tsx create mode 100644 apps/radio/src/components/settings/add-station.test.tsx create mode 100644 apps/radio/src/components/settings/station-editor.tsx diff --git a/apps/radio/src/components/radio/dj/dj-radio-list.tsx b/apps/radio/src/components/radio/dj/dj-radio-list.tsx index 1173884fb..2a6eb2ef1 100644 --- a/apps/radio/src/components/radio/dj/dj-radio-list.tsx +++ b/apps/radio/src/components/radio/dj/dj-radio-list.tsx @@ -8,6 +8,7 @@ import { } from "@avoid.quest/ui/components/tabs"; import { cn } from "@avoid.quest/ui/lib/utils"; import { useState } from "react"; +import { AddStationButton } from "@/components/settings/add-station-button"; import type { Radio } from "@/lib/audio"; import { getDjDeckModule } from "@/lib/dj-deck"; import { @@ -162,7 +163,7 @@ function RowList({ isSearch?: boolean; }) { if (items.length === 0) { - return {emptyLabel}; + return }>{emptyLabel}; } return ( diff --git a/apps/radio/src/components/radio/empty-hint.tsx b/apps/radio/src/components/radio/empty-hint.tsx index 7f70d1900..f89c63663 100644 --- a/apps/radio/src/components/radio/empty-hint.tsx +++ b/apps/radio/src/components/radio/empty-hint.tsx @@ -5,12 +5,14 @@ import { } from "@avoid.quest/ui/components/empty"; import { cn } from "@avoid.quest/ui/lib/utils"; -/** The compact empty state: an optional faint icon over one line of direction. */ +/** The compact empty state, with an optional icon and action. */ export function EmptyHint({ + action, icon, children, className, }: { + action?: React.ReactNode; icon?: React.ReactNode; children: React.ReactNode; className?: string; @@ -23,6 +25,7 @@ export function EmptyHint({ ) : null} {children} + {action} ); } diff --git a/apps/radio/src/components/radio/node/canvas-hint.tsx b/apps/radio/src/components/radio/node/canvas-hint.tsx index 1f306f4da..048a2065e 100644 --- a/apps/radio/src/components/radio/node/canvas-hint.tsx +++ b/apps/radio/src/components/radio/node/canvas-hint.tsx @@ -1,3 +1,4 @@ +import { AddStationButton } from "@/components/settings/add-station-button"; import { isRadioSourceNode, isStripSource, @@ -50,7 +51,10 @@ export function NodeCanvasHint({ } if (!hasFilledSource(graph)) { return ( - + } + className="pointer-events-none absolute inset-x-0 bottom-0 z-10 py-4 md:py-4" + > {firstStep(graph, isPhone)} ); diff --git a/apps/radio/src/components/radio/node/node-rack.test.tsx b/apps/radio/src/components/radio/node/node-rack.test.tsx index 5633af2a8..2c124d0ee 100644 --- a/apps/radio/src/components/radio/node/node-rack.test.tsx +++ b/apps/radio/src/components/radio/node/node-rack.test.tsx @@ -615,6 +615,7 @@ describe("NodeRack", () => { ); expect(view.getByText("Search to add a station")).toBeTruthy(); + expect(view.getByRole("button", { name: "Add station" })).toBeTruthy(); }); test("a File to pick again after a reload opens its settings from the Rack", () => { diff --git a/apps/radio/src/components/radio/node/node-rack.tsx b/apps/radio/src/components/radio/node/node-rack.tsx index b8a3e0d08..bed222f31 100644 --- a/apps/radio/src/components/radio/node/node-rack.tsx +++ b/apps/radio/src/components/radio/node/node-rack.tsx @@ -6,6 +6,7 @@ import { cn } from "@avoid.quest/ui/lib/utils"; import { IconKey, IconPlaylist } from "@tabler/icons-react"; import { useStore } from "@tanstack/react-store"; import { useId, useState } from "react"; +import { AddStationButton } from "@/components/settings/add-station-button"; import type { Radio } from "@/lib/audio"; import { isSessionRadio } from "@/lib/hooks/use-session-radios"; import { getNodeDefinition } from "@/lib/node-graph/catalogue"; @@ -355,7 +356,9 @@ export function NodeRack({ {graph.nodes.every( (node) => getNodeDefinition(node.type).category === "output" ) ? ( - Search to add a station + } className="py-10"> + Search to add a station + ) : null} {groups.map((group) => ( { await expect( - within(canvasElement).getByText("Search to add a station") + within(canvasElement).getByText( + "Search or paste a link to play a station. Save it to keep it in My stations." + ) ).toBeVisible(); + await expect( + within(canvasElement).getAllByRole("button", { name: "Add station" }) + ).toHaveLength(2); }, }; diff --git a/apps/radio/src/components/radio/single/single-player-station-list.tsx b/apps/radio/src/components/radio/single/single-player-station-list.tsx index ee664602e..a69d0bd4f 100644 --- a/apps/radio/src/components/radio/single/single-player-station-list.tsx +++ b/apps/radio/src/components/radio/single/single-player-station-list.tsx @@ -2,6 +2,7 @@ import { ScrollArea } from "@avoid.quest/ui/components/scroll-area"; import { cn } from "@avoid.quest/ui/lib/utils"; import { IconWaveSine } from "@tabler/icons-react"; +import { AddStationButton } from "@/components/settings/add-station-button"; import type { Radio } from "@/lib/audio"; import { useHasEnteredViewport } from "@/lib/hooks/use-has-entered-viewport"; import { useRadioMetadata } from "@/lib/hooks/use-radio-metadata"; @@ -162,7 +163,10 @@ export function StationList({ return ( - {searchBar} + + {searchBar} + + {allRadios.length > 0 ? ( @@ -183,7 +187,10 @@ export function StationList({ ))} ) : ( - Search to add a station + } className="py-10"> + Search or paste a link to play a station. Save it to keep it in My + stations. + )} diff --git a/apps/radio/src/components/radio/single/single-player.test.tsx b/apps/radio/src/components/radio/single/single-player.test.tsx index 2607c7f8b..786e7b8e4 100644 --- a/apps/radio/src/components/radio/single/single-player.test.tsx +++ b/apps/radio/src/components/radio/single/single-player.test.tsx @@ -131,8 +131,8 @@ if (process.env.RADIO_SINGLE_LINK_REGRESSION === "1") { fireEvent.click( view.getByRole("button", { name: "Options for stream.example" }) ); - expect(view.getByRole("menuitem", { name: "Save" })).toBeTruthy(); - fireEvent.click(view.getByRole("menuitem", { name: "Remove" })); + expect(view.getByRole("menuitem", { name: "Save station" })).toBeTruthy(); + fireEvent.click(view.getByRole("menuitem", { name: "Remove station" })); await waitFor(() => expect(getSessionRadios()).toEqual([])); } ); diff --git a/apps/radio/src/components/settings/add-station-button.tsx b/apps/radio/src/components/settings/add-station-button.tsx new file mode 100644 index 000000000..92f5dca0c --- /dev/null +++ b/apps/radio/src/components/settings/add-station-button.tsx @@ -0,0 +1,34 @@ +import { Button } from "@avoid.quest/ui/components/button"; +import { cn } from "@avoid.quest/ui/lib/utils"; +import { IconPlus } from "@tabler/icons-react"; +import { SettingsButton } from "./settings-button"; + +/** Open the station page without mounting Settings until it is needed. */ +export function AddStationButton({ + iconOnly = false, + className, +}: { + iconOnly?: boolean; + className?: string; +}) { + return ( + + + {iconOnly ? null : "Add station"} + + } + /> + ); +} diff --git a/apps/radio/src/components/settings/add-station.test.tsx b/apps/radio/src/components/settings/add-station.test.tsx new file mode 100644 index 000000000..4523a2e57 --- /dev/null +++ b/apps/radio/src/components/settings/add-station.test.tsx @@ -0,0 +1,175 @@ +/** biome-ignore-all lint/performance/noJsxPropsBind: Test harnesses record component interactions. */ +import { afterEach, beforeEach, expect, test } from "bun:test"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { browserTestGlobals } from "@/test-utils/browser-globals"; +import { installSettingsTestDom } from "./settings-test-dom"; + +if (process.env.RADIO_ADD_STATION_REGRESSION === "1") { + const dom = installSettingsTestDom(); + Object.assign(globalThis, browserTestGlobals(dom.window), { + ResizeObserver: class { + disconnect() { + // JSDOM does not perform layout. + } + observe() { + // JSDOM does not perform layout. + } + unobserve() { + // JSDOM does not perform layout. + } + }, + }); + Object.defineProperty(window, "matchMedia", { + configurable: true, + value: () => ({ + addEventListener: () => undefined, + matches: false, + removeEventListener: () => undefined, + }), + }); + const { cleanup, fireEvent, render, waitFor } = await import( + "@testing-library/react" + ); + const { StationList } = await import( + "../radio/single/single-player-station-list" + ); + const { NodeCanvasHint } = await import("../radio/node/canvas-hint"); + const { DjRadioList } = await import("../radio/dj/dj-radio-list"); + const { SettingsButton } = await import("./settings-button"); + const { radiosCollection } = await import("@/lib/collections/radios"); + const { initializeSettings } = await import("@/lib/collections/settings"); + const { buildNodeGraphFromTemplate } = await import( + "@/lib/node-graph/templates" + ); + const noop = () => undefined; + const single = ( + } + sessionRadios={[]} + /> + ); + const entries = [ + { name: "Single header", player: single, triggerIndex: 0 }, + { name: "Single empty state", player: single, triggerIndex: 1 }, + { + name: "Node empty state", + player: , + triggerIndex: 0, + }, + { + name: "DJ empty state", + player: , + triggerIndex: 0, + }, + ]; + beforeEach(async () => { + await initializeSettings(); + await radiosCollection.stateWhenReady(); + }); + afterEach(() => { + cleanup(); + for (const id of radiosCollection.state.keys()) { + radiosCollection.delete(id); + } + }); + + for (const { name, player, triggerIndex } of entries) { + test(`${name} opens Add station inside Settings and saves to My stations`, async () => { + const client = new QueryClient({ + defaultOptions: { queries: { retry: false } }, + }); + const view = render( + {player} + ); + const trigger = view.getAllByRole("button", { name: "Add station" })[ + triggerIndex + ]; + expect(trigger).toBeDefined(); + if (name.startsWith("Single")) { + expect( + view.getByText( + "Search or paste a link to play a station. Save it to keep it in My stations." + ) + ).toBeTruthy(); + } + // Cold keyboard activation must survive the lazy Settings load. + fireEvent.click(trigger, { detail: 0 }); + await view.findByRole("heading", { name: "Add station" }); + expect(view.getAllByRole("dialog")).toHaveLength(1); + expect( + view + .getByRole("tab", { name: "My stations" }) + .getAttribute("aria-selected") + ).toBe("true"); + fireEvent.click(view.getByRole("tab", { name: "Manual" })); + fireEvent.change(await view.findByLabelText("Name"), { + target: { value: "My new station" }, + }); + fireEvent.change(view.getByLabelText("Stream URL"), { + target: { value: "https://stream.example/live.mp3" }, + }); + fireEvent.click(view.getByRole("button", { name: "Add station" })); + await view.findByRole("searchbox", { name: "Filter stations" }); + expect([...radiosCollection.state.values()]).toEqual([ + expect.objectContaining({ + enabled: true, + name: "My new station", + streamUrl: "https://stream.example/live.mp3", + }), + ]); + expect(view.getAllByRole("dialog")).toHaveLength(1); + fireEvent.click(view.getByRole("button", { name: "Close" })); + await waitFor(() => expect(view.queryByRole("dialog")).toBeNull()); + await waitFor(() => expect(document.activeElement).toBe(trigger)); + // The shortcut starts a fresh Add page even after saving and closing. + fireEvent.click(trigger, { detail: 0 }); + await view.findByRole("heading", { name: "Add station" }); + expect(view.getAllByRole("dialog")).toHaveLength(1); + fireEvent.click(view.getByRole("button", { name: "My stations" })); + await view.findByRole("searchbox", { name: "Filter stations" }); + expect(document.activeElement).toBe( + view.getByRole("button", { name: "Add station" }) + ); + }); + } + + test("the existing Settings Add station button opens the same page without another dialog", async () => { + const view = render(); + fireEvent.click(view.getByRole("button", { name: "Open settings" })); + fireEvent.click(await view.findByRole("button", { name: "Add station" })); + const heading = await view.findByRole("heading", { name: "Add station" }); + expect(view.getAllByRole("dialog")).toHaveLength(1); + expect(document.activeElement).toBe(heading); + fireEvent.click(view.getByRole("button", { name: "My stations" })); + await view.findByRole("searchbox", { name: "Filter stations" }); + expect(document.activeElement).toBe( + view.getByRole("button", { name: "Add station" }) + ); + }); +} else { + test("player add-station regressions (isolated browser environment)", async () => { + const child = Bun.spawn([process.execPath, "test", import.meta.path], { + env: { ...process.env, RADIO_ADD_STATION_REGRESSION: "1" }, + stderr: "pipe", + stdout: "pipe", + timeout: 25_000, + }); + const [stderr, exitCode] = await Promise.all([ + new Response(child.stderr).text(), + child.exited, + ]); + expect({ errors: exitCode ? stderr : "", exitCode }).toEqual({ + errors: "", + exitCode: 0, + }); + }, 30_000); +} diff --git a/apps/radio/src/components/settings/radio-dialog.tsx b/apps/radio/src/components/settings/radio-dialog.tsx index dfce999a2..2d844f29b 100644 --- a/apps/radio/src/components/settings/radio-dialog.tsx +++ b/apps/radio/src/components/settings/radio-dialog.tsx @@ -6,63 +6,10 @@ import { DialogHeader, DialogTitle, } from "@avoid.quest/ui/components/dialog"; -import { - Tabs, - TabsContent, - TabsList, - TabsTrigger, -} from "@avoid.quest/ui/components/tabs"; -import { Suspense } from "react"; -import { LazyBoundary, lazyWithRetry } from "@/components/lazy-recovery"; import type { Radio } from "@/lib/audio"; +import { StationEditor } from "./station-editor"; -function preloadRadioForm() { - return import("./radio-form"); -} -const RadioForm = lazyWithRetry(() => - preloadRadioForm().then((module) => ({ default: module.RadioForm })) -); -const preloadRadioFromUrl = () => import("./radio-from-url-tab"); -const RadioFromUrlTab = lazyWithRetry(() => - preloadRadioFromUrl().then((module) => ({ - default: module.RadioFromUrlTab, - })) -); -const preloadRadioGarden = () => import("./radio-garden-tab"); -const RadioGardenTab = lazyWithRetry(() => - preloadRadioGarden().then((module) => ({ - default: module.RadioGardenTab, - })) -); - -/** Station menus are rendered by shared components outside this file's ownership. - * Capture intent at the player so their keyboard and pointer triggers both - * warm the editor, without importing it while the player mounts. - */ -export function prefetchStationDialogOnIntent(event: React.SyntheticEvent) { - if ( - event.target instanceof Element && - event.target.closest('[aria-haspopup="menu"]') - ) { - preloadRadioForm().catch(() => undefined); - import("../radio/confirm-delete-dialog").catch(() => undefined); - } -} - -function prefetchTab(load: () => Promise) { - load().catch(() => undefined); -} - -function LoadingStationForm() { - return ( - - Loading station details… - - ); -} +export { prefetchStationDialogOnIntent } from "./station-editor"; type RadioDialogProps = { mode: "create" | "edit"; @@ -95,69 +42,7 @@ export function RadioDialog({ - {isEdit ? ( - - }> - - - - ) : ( - - - prefetchTab(preloadRadioGarden)} - onPointerEnter={() => prefetchTab(preloadRadioGarden)} - value="radiogarden" - > - Radio Garden - - prefetchTab(preloadRadioFromUrl)} - onPointerEnter={() => prefetchTab(preloadRadioFromUrl)} - value="from-url" - > - From URL - - prefetchTab(preloadRadioForm)} - onPointerEnter={() => prefetchTab(preloadRadioForm)} - value="manual" - > - Manual - - - - - }> - - - - - - - }> - - - - - - - }> - - - - - - )} + diff --git a/apps/radio/src/components/settings/radio-management.tsx b/apps/radio/src/components/settings/radio-management.tsx index 4e05a00cd..20c3dd1ad 100644 --- a/apps/radio/src/components/settings/radio-management.tsx +++ b/apps/radio/src/components/settings/radio-management.tsx @@ -23,8 +23,8 @@ import { verticalListSortingStrategy, } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; -import { IconGripVertical, IconPlus } from "@tabler/icons-react"; -import { useState } from "react"; +import { IconArrowLeft, IconGripVertical, IconPlus } from "@tabler/icons-react"; +import { useEffect, useRef, useState } from "react"; import type { Radio } from "@/lib/audio"; import { deleteRadio, @@ -38,7 +38,7 @@ import { RadioLogo } from "../radio/radio-logo"; import { SearchField } from "../radio/search-field"; import { stationFallbackSubtitle } from "../radio/station-row"; -import { RadioDialog } from "./radio-dialog"; +import { StationEditor } from "./station-editor"; type SortableRadioItemProps = { radio: Radio; @@ -140,7 +140,7 @@ function stationName(radios: Radio[] | undefined, id: UniqueIdentifier) { ); } -export function RadioManagement() { +export function RadioManagement({ defaultPage }: { defaultPage?: "create" }) { const { data: radios } = useAllRadios(); // Screen readers hear station names, not record ids, while reordering. const reorderAnnouncements: Announcements = { @@ -157,8 +157,16 @@ export function RadioManagement() { onDragStart: ({ active }) => `Picked up ${stationName(radios, active.id)}.`, }; const [isUpdating, setIsUpdating] = useState(false); - const [dialogOpen, setDialogOpen] = useState(false); - const [dialogMode, setDialogMode] = useState<"create" | "edit">("create"); + const [editorOpen, setEditorOpen] = useState(defaultPage === "create"); + const addButtonRef = useRef(null); + const wasEditing = useRef(editorOpen); + useEffect(() => { + if (wasEditing.current && !editorOpen) { + addButtonRef.current?.focus(); + } + wasEditing.current = editorOpen; + }, [editorOpen]); + const [editorMode, setEditorMode] = useState<"create" | "edit">("create"); const [selectedRadio, setSelectedRadio] = useState(); const [deleteConfirm, setDeleteConfirm] = useState(null); const [filter, setFilter] = useState(""); @@ -240,15 +248,15 @@ export function RadioManagement() { }; const handleAddRadio = () => { - setDialogMode("create"); + setEditorMode("create"); setSelectedRadio(undefined); - setDialogOpen(true); + setEditorOpen(true); }; const handleEditRadio = (radio: Radio) => { - setDialogMode("edit"); + setEditorMode("edit"); setSelectedRadio(radio); - setDialogOpen(true); + setEditorOpen(true); }; const handleDeleteRadio = (radio: Radio) => { @@ -274,6 +282,17 @@ export function RadioManagement() { const handleCancelDelete = () => { setDeleteConfirm(null); }; + const handleCloseEditor = () => setEditorOpen(false); + + if (editorOpen) { + return ( + + ); + } if (!radios) { return ; @@ -289,7 +308,12 @@ export function RadioManagement() { placeholder={`Filter ${radios.length} stations…`} value={filter} /> - + Add station @@ -334,13 +358,6 @@ export function RadioManagement() { - - void; +}) { + const headingRef = useRef(null); + useEffect(() => headingRef.current?.focus(), []); + return ( + + + My stations + + + {mode === "create" ? "Add station" : "Edit station"} + + + {mode === "create" + ? "Search Radio Garden, fetch from a URL, or enter details manually." + : "Update station details."} + + + + ); +} + export function LoadingFallback() { return ( Loading… diff --git a/apps/radio/src/components/settings/settings-form.tsx b/apps/radio/src/components/settings/settings-form.tsx index c82f8c75d..a36054c00 100644 --- a/apps/radio/src/components/settings/settings-form.tsx +++ b/apps/radio/src/components/settings/settings-form.tsx @@ -142,6 +142,9 @@ export function SettingsForm({ const [dataPanel, setDataPanel] = useState(() => getInitialDataPanel(defaultTab) ); + const [defaultStationPage, setDefaultStationPage] = useState< + "create" | undefined + >(defaultTab === "add-station" ? "create" : undefined); const [isResetting, setIsResetting] = useState(false); const [showResetDialog, setShowResetDialog] = useState(false); @@ -160,6 +163,7 @@ export function SettingsForm({ // The section list is a column from md up: arrow keys follow its layout. const isMobile = useIsMobile(); const handleSectionChange = (value: string) => { + setDefaultStationPage(undefined); setActive(value as SettingsSection); }; @@ -207,6 +211,7 @@ export function SettingsForm({ ; } if (section === "radios") { - return ; + return ; } if (section === "playback") { return ( diff --git a/apps/radio/src/components/settings/station-editor.tsx b/apps/radio/src/components/settings/station-editor.tsx new file mode 100644 index 000000000..3e8f6c3c3 --- /dev/null +++ b/apps/radio/src/components/settings/station-editor.tsx @@ -0,0 +1,137 @@ +// biome-ignore-all lint/performance/noJsxPropsBind: React Compiler stabilizes component handlers +import { + Tabs, + TabsContent, + TabsList, + TabsTrigger, +} from "@avoid.quest/ui/components/tabs"; +import { Suspense } from "react"; +import { LazyBoundary, lazyWithRetry } from "@/components/lazy-recovery"; +import type { Radio } from "@/lib/audio"; + +function preloadRadioForm() { + return import("./radio-form"); +} +const RadioForm = lazyWithRetry(() => + preloadRadioForm().then((module) => ({ default: module.RadioForm })) +); +const preloadRadioFromUrl = () => import("./radio-from-url-tab"); +const RadioFromUrlTab = lazyWithRetry(() => + preloadRadioFromUrl().then((module) => ({ + default: module.RadioFromUrlTab, + })) +); +const preloadRadioGarden = () => import("./radio-garden-tab"); +const RadioGardenTab = lazyWithRetry(() => + preloadRadioGarden().then((module) => ({ + default: module.RadioGardenTab, + })) +); + +/** Station menus are rendered by shared components outside this file's ownership. + * Capture intent at the player so their keyboard and pointer triggers both + * warm the editor, without importing it while the player mounts. + */ +export function prefetchStationDialogOnIntent(event: React.SyntheticEvent) { + if ( + event.target instanceof Element && + event.target.closest('[aria-haspopup="menu"]') + ) { + preloadRadioForm().catch(() => undefined); + import("../radio/confirm-delete-dialog").catch(() => undefined); + } +} + +function prefetchTab(load: () => Promise) { + load().catch(() => undefined); +} + +function LoadingStationForm() { + return ( + + Loading station details… + + ); +} + +/** Shared by the standalone editor and the station page inside Settings. */ +export function StationEditor({ + mode, + radio, + onClose, +}: { + mode: "create" | "edit"; + radio?: Radio; + onClose: () => void; +}) { + return ( + + {mode === "edit" ? ( + + }> + + + + ) : ( + + + prefetchTab(preloadRadioGarden)} + onPointerEnter={() => prefetchTab(preloadRadioGarden)} + value="radiogarden" + > + Radio Garden + + prefetchTab(preloadRadioFromUrl)} + onPointerEnter={() => prefetchTab(preloadRadioFromUrl)} + value="from-url" + > + From URL + + prefetchTab(preloadRadioForm)} + onPointerEnter={() => prefetchTab(preloadRadioForm)} + value="manual" + > + Manual + + + + + }> + + + + + + + }> + + + + + + + }> + + + + + + )} + + ); +} From 134c0bb5115c7838e25f99e7307c6b0f67c565a3 Mon Sep 17 00:00:00 2001 From: az3ta <24527778+az3ta@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:38:25 +0100 Subject: [PATCH 2/2] test(radio): cover adding stations in the player --- .../components/settings/add-station.test.tsx | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/apps/radio/src/components/settings/add-station.test.tsx b/apps/radio/src/components/settings/add-station.test.tsx index 4523a2e57..45c553104 100644 --- a/apps/radio/src/components/settings/add-station.test.tsx +++ b/apps/radio/src/components/settings/add-station.test.tsx @@ -4,6 +4,8 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { browserTestGlobals } from "@/test-utils/browser-globals"; import { installSettingsTestDom } from "./settings-test-dom"; +const SAVED_STATION = /^My new station/; + if (process.env.RADIO_ADD_STATION_REGRESSION === "1") { const dom = installSettingsTestDom(); Object.assign(globalThis, browserTestGlobals(dom.window), { @@ -19,6 +21,7 @@ if (process.env.RADIO_ADD_STATION_REGRESSION === "1") { } }, }); + Object.assign(CSS, { supports: () => false }); Object.defineProperty(window, "matchMedia", { configurable: true, value: () => ({ @@ -27,36 +30,21 @@ if (process.env.RADIO_ADD_STATION_REGRESSION === "1") { removeEventListener: () => undefined, }), }); - const { cleanup, fireEvent, render, waitFor } = await import( + const { cleanup, fireEvent, render, waitFor, within } = await import( "@testing-library/react" ); - const { StationList } = await import( - "../radio/single/single-player-station-list" - ); + const { Radios } = await import("../radio"); const { NodeCanvasHint } = await import("../radio/node/canvas-hint"); const { DjRadioList } = await import("../radio/dj/dj-radio-list"); const { SettingsButton } = await import("./settings-button"); const { radiosCollection } = await import("@/lib/collections/radios"); - const { initializeSettings } = await import("@/lib/collections/settings"); + const { initializeSettings, setPlayerMode } = await import( + "@/lib/collections/settings" + ); const { buildNodeGraphFromTemplate } = await import( "@/lib/node-graph/templates" ); - const noop = () => undefined; - const single = ( - } - sessionRadios={[]} - /> - ); + const single = ; const entries = [ { name: "Single header", player: single, triggerIndex: 0 }, { name: "Single empty state", player: single, triggerIndex: 1 }, @@ -73,6 +61,7 @@ if (process.env.RADIO_ADD_STATION_REGRESSION === "1") { ]; beforeEach(async () => { await initializeSettings(); + setPlayerMode("single"); await radiosCollection.stateWhenReady(); }); afterEach(() => { @@ -88,11 +77,14 @@ if (process.env.RADIO_ADD_STATION_REGRESSION === "1") { defaultOptions: { queries: { retry: false } }, }); const view = render( - {player} + + {player} + ); - const trigger = view.getAllByRole("button", { name: "Add station" })[ - triggerIndex - ]; + const playerView = within(view.getByTestId("player")); + let trigger = ( + await playerView.findAllByRole("button", { name: "Add station" }) + )[triggerIndex]; expect(trigger).toBeDefined(); if (name.startsWith("Single")) { expect( @@ -118,18 +110,31 @@ if (process.env.RADIO_ADD_STATION_REGRESSION === "1") { target: { value: "https://stream.example/live.mp3" }, }); fireEvent.click(view.getByRole("button", { name: "Add station" })); - await view.findByRole("searchbox", { name: "Filter stations" }); - expect([...radiosCollection.state.values()]).toEqual([ - expect.objectContaining({ - enabled: true, - name: "My new station", - streamUrl: "https://stream.example/live.mp3", - }), - ]); - expect(view.getAllByRole("dialog")).toHaveLength(1); - fireEvent.click(view.getByRole("button", { name: "Close" })); - await waitFor(() => expect(view.queryByRole("dialog")).toBeNull()); - await waitFor(() => expect(document.activeElement).toBe(trigger)); + await waitFor(() => + expect([...radiosCollection.state.values()]).toEqual([ + expect.objectContaining({ + enabled: true, + name: "My new station", + streamUrl: "https://stream.example/live.mp3", + }), + ]) + ); + if (name === "Single empty state") { + // The saved station replaces the empty state and its Settings trigger. + await waitFor(() => expect(view.queryByRole("dialog")).toBeNull()); + trigger = playerView.getByRole("button", { name: "Add station" }); + } else { + await view.findByRole("searchbox", { name: "Filter stations" }); + expect(view.getAllByRole("dialog")).toHaveLength(1); + fireEvent.click(view.getByRole("button", { name: "Close" })); + await waitFor(() => expect(view.queryByRole("dialog")).toBeNull()); + await waitFor(() => expect(document.activeElement).toBe(trigger)); + } + if (name.startsWith("Single")) { + expect( + await playerView.findByRole("button", { name: SAVED_STATION }) + ).toBeTruthy(); + } // The shortcut starts a fresh Add page even after saving and closing. fireEvent.click(trigger, { detail: 0 }); await view.findByRole("heading", { name: "Add station" });
+ {mode === "create" + ? "Search Radio Garden, fetch from a URL, or enter details manually." + : "Update station details."} +
Loading…