Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/radio/src/components/radio/dj/dj-radio-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -162,7 +163,7 @@ function RowList({
isSearch?: boolean;
}) {
if (items.length === 0) {
return <EmptyHint>{emptyLabel}</EmptyHint>;
return <EmptyHint action={<AddStationButton />}>{emptyLabel}</EmptyHint>;
}

return (
Expand Down
5 changes: 4 additions & 1 deletion apps/radio/src/components/radio/empty-hint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +25,7 @@ export function EmptyHint({
</EmptyMedia>
) : null}
<EmptyDescription className="text-xs">{children}</EmptyDescription>
{action}
</Empty>
);
}
6 changes: 5 additions & 1 deletion apps/radio/src/components/radio/node/canvas-hint.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AddStationButton } from "@/components/settings/add-station-button";
import {
isRadioSourceNode,
isStripSource,
Expand Down Expand Up @@ -50,7 +51,10 @@ export function NodeCanvasHint({
}
if (!hasFilledSource(graph)) {
return (
<EmptyHint className="pointer-events-none absolute inset-x-0 bottom-0 z-10 py-4 md:py-4">
<EmptyHint
action={<AddStationButton />}
className="pointer-events-none absolute inset-x-0 bottom-0 z-10 py-4 md:py-4"
>
{firstStep(graph, isPhone)}
</EmptyHint>
);
Expand Down
1 change: 1 addition & 0 deletions apps/radio/src/components/radio/node/node-rack.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
5 changes: 4 additions & 1 deletion apps/radio/src/components/radio/node/node-rack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -355,7 +356,9 @@ export function NodeRack({
{graph.nodes.every(
(node) => getNodeDefinition(node.type).category === "output"
) ? (
<EmptyHint className="py-10">Search to add a station</EmptyHint>
<EmptyHint action={<AddStationButton />} className="py-10">
Search to add a station
</EmptyHint>
) : null}
{groups.map((group) => (
<RackSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ export const Empty: Story = {
args: { radios: [] },
play: async ({ canvasElement }) => {
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);
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -162,7 +163,10 @@ export function StationList({

return (
<div className="flex min-h-0 w-full min-w-0 flex-1 flex-col border-border/50 lg:w-80 lg:flex-none lg:border-r xl:w-96">
<div className="px-3 py-2">{searchBar}</div>
<div className="flex items-center gap-2 px-3 py-2">
<div className="min-w-0 flex-1">{searchBar}</div>
<AddStationButton iconOnly />
</div>

<ScrollArea className="min-h-0 min-w-0 flex-1 overflow-x-hidden">
{allRadios.length > 0 ? (
Expand All @@ -183,7 +187,10 @@ export function StationList({
))}
</div>
) : (
<EmptyHint className="py-10">Search to add a station</EmptyHint>
<EmptyHint action={<AddStationButton />} className="py-10">
Search or paste a link to play a station. Save it to keep it in My
stations.
</EmptyHint>
)}
</ScrollArea>
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/radio/src/components/radio/single/single-player.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([]));
}
);
Expand Down
34 changes: 34 additions & 0 deletions apps/radio/src/components/settings/add-station-button.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<SettingsButton
defaultTab="add-station"
trigger={
<Button
aria-label="Add station"
className={cn(
"pointer-events-auto shrink-0 [@media(pointer:coarse)]:min-h-11 [@media(pointer:coarse)]:min-w-11",
className
)}
size={iconOnly ? "icon" : "sm"}
type="button"
variant="outline"
>
<IconPlus aria-hidden="true" />
{iconOnly ? null : "Add station"}
</Button>
}
/>
);
}
180 changes: 180 additions & 0 deletions apps/radio/src/components/settings/add-station.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/** 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";

const SAVED_STATION = /^My new station/;

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.assign(CSS, { supports: () => false });
Object.defineProperty(window, "matchMedia", {
configurable: true,
value: () => ({
addEventListener: () => undefined,
matches: false,
removeEventListener: () => undefined,
}),
});
const { cleanup, fireEvent, render, waitFor, within } = await import(
"@testing-library/react"
);
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, setPlayerMode } = await import(
"@/lib/collections/settings"
);
const { buildNodeGraphFromTemplate } = await import(
"@/lib/node-graph/templates"
);
const single = <Radios />;
const entries = [
{ name: "Single header", player: single, triggerIndex: 0 },
{ name: "Single empty state", player: single, triggerIndex: 1 },
{
name: "Node empty state",
player: <NodeCanvasHint graph={buildNodeGraphFromTemplate("starter")} />,
triggerIndex: 0,
},
{
name: "DJ empty state",
player: <DjRadioList deckId="deck-a" radios={[]} />,
triggerIndex: 0,
},
];
beforeEach(async () => {
await initializeSettings();
setPlayerMode("single");
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(
<QueryClientProvider client={client}>
<div data-testid="player">{player}</div>
</QueryClientProvider>
);
const playerView = within(view.getByTestId("player"));
let trigger = (
await playerView.findAllByRole("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 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" });
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(<SettingsButton />);
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);
}
Loading
Loading