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
53 changes: 53 additions & 0 deletions client/__tests__/BacklogRoulette.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ describe("Backlog roulette", () => {
vi.restoreAllMocks();
});

it("formats fractional completion estimates without changing budget eligibility", async () => {
render(
<BacklogRoulette
games={[{ ...game("fractional"), timeToBeatNormally: 5.012345678 }]}
loading={false}
/>
);
fireEvent.click(screen.getByRole("button", { name: "Pick a game" }));
expect(screen.getByText("About 5 hours to finish")).toBeVisible();
fireEvent.keyDown(screen.getByRole("combobox", { name: "Game length" }), { key: "ArrowDown" });
fireEvent.click(
await screen.findByRole("option", { name: "A short adventure · up to 5 hours" })
);
expect(screen.getByText("No games in this draw")).toBeVisible();
});

it("draws only visible owned games and never repeats on consecutive rerolls", () => {
render(
<BacklogRoulette
Expand Down Expand Up @@ -163,4 +179,41 @@ describe("Backlog roulette", () => {
expect(crypto.getRandomValues).toHaveBeenCalledTimes(2);
expect(screen.getByTestId("roulette-title")).toHaveTextContent("Quest a");
});

it("draws within the completion budget and keeps unknown lengths in Any length", async () => {
render(
<BacklogRoulette
games={[
{ ...game("long"), timeToBeatNormally: 41 },
{ ...game("short"), timeToBeatNormally: 5 },
{ ...game("weekend"), timeToBeatNormally: 15 },
game("unknown"),
{ ...game("zero"), timeToBeatNormally: 0 },
{ ...game("hidden", "owned", true), timeToBeatNormally: 2 },
]}
loading={false}
/>
);
fireEvent.click(screen.getByRole("button", { name: "Pick a game" }));
expect(screen.getByText("Chosen from 5 matching games.")).toBeVisible();
const chooseLength = async (name: string) => {
fireEvent.keyDown(screen.getByRole("combobox", { name: "Game length" }), {
key: "ArrowDown",
});
fireEvent.click(await screen.findByRole("option", { name, exact: true }));
};
await chooseLength("A short adventure · up to 5 hours");
expect(screen.getByTestId("roulette-title")).toHaveTextContent("Quest short");
expect(screen.getByText("About 5 hours to finish")).toBeVisible();
expect(screen.getByRole("button", { name: "Roll again" })).toBeDisabled();
await chooseLength("A weekend quest · up to 15 hours");
expect(screen.getByTestId("roulette-title")).toHaveTextContent("Quest weekend");
expect(screen.getByText("Chosen from 2 matching games.")).toBeVisible();
await choosePool("Currently playing");
expect(screen.getByText("No games in this draw")).toBeVisible();
await choosePool("Owned games");
expect(screen.getByText("Chosen from 2 matching games.")).toBeVisible();
await chooseLength("Any length");
expect(screen.getByText("Chosen from 5 matching games.")).toBeVisible();
});
});
59 changes: 51 additions & 8 deletions client/src/components/BacklogRoulette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,27 @@ export default function BacklogRoulette({
}) {
const [open, setOpen] = useState(false);
const [pool, setPool] = useState<Pool>(pools[0] ?? "all");
const [maxHours, setMaxHours] = useState("any");
const [selectedId, setSelectedId] = useState<string | null>(null);
const [, navigate] = useLocation();
const [starting, setStarting] = useState(false);
const candidates = games.filter(
(game) => !game.hidden && (pool === "all" || game.status === pool)
);
function eligibleGames(nextPool: Pool, nextMaxHours: string) {
return games.filter(
(game) =>
!game.hidden &&
(nextPool === "all" || game.status === nextPool) &&
(nextMaxHours === "any" ||
(Number.isFinite(game.timeToBeatNormally) &&
(game.timeToBeatNormally ?? 0) > 0 &&
(game.timeToBeatNormally ?? Infinity) <= Number(nextMaxHours)))
);
}
const candidates = eligibleGames(pool, maxHours);
const selected = candidates.find((game) => game.id === selectedId);

/** Draw uniformly from the chosen pool, skipping the previous game when possible. */
function roll(nextPool = pool) {
const eligible = games.filter(
(game) => !game.hidden && (nextPool === "all" || game.status === nextPool)
);
function roll(nextPool = pool, nextMaxHours = maxHours) {
const eligible = eligibleGames(nextPool, nextMaxHours);
const choices =
eligible.length > 1 ? eligible.filter((game) => game.id !== selectedId) : eligible;
if (!choices.length) {
Expand Down Expand Up @@ -148,6 +156,31 @@ export default function BacklogRoulette({
Your current search and filters apply. Hidden games stay out of the draw.
</p>
</div>
<div className="space-y-2">
<Label htmlFor="roulette-length">Game length</Label>
<Select
value={maxHours}
disabled={starting || loading}
onValueChange={(value) => {
setMaxHours(value);
roll(pool, value);
}}
>
<SelectTrigger id="roulette-length">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="any">Any length</SelectItem>
<SelectItem value="5">A short adventure · up to 5 hours</SelectItem>
<SelectItem value="15">A weekend quest · up to 15 hours</SelectItem>
<SelectItem value="40">A longer journey · up to 40 hours</SelectItem>
</SelectContent>
</Select>
<p className="text-xs text-muted-foreground">
Estimated total time to finish, not a play session. Length filters exclude games
without a known normal completion time.
</p>
</div>
<div aria-live="polite" aria-atomic="true">
{selected ? (
<div className="rounded-lg border bg-muted/30 p-4 space-y-4">
Expand All @@ -166,6 +199,16 @@ export default function BacklogRoulette({
{selected.title}
</h2>
<StatusBadge status={selected.status} />
{Number.isFinite(selected.timeToBeatNormally) &&
(selected.timeToBeatNormally ?? 0) > 0 && (
<p className="text-sm text-muted-foreground">
About{" "}
{selected.timeToBeatNormally?.toLocaleString("en-US", {
maximumFractionDigits: 1,
})}{" "}
hours to finish
</p>
)}
Comment thread
Doezer marked this conversation as resolved.
Resolved
<p className="text-sm text-muted-foreground break-words">
{selected.genres?.join(" · ")}
</p>
Expand All @@ -188,7 +231,7 @@ export default function BacklogRoulette({
<p className="text-sm text-muted-foreground">
{candidates.length
? "Roll again to pick from your updated list."
: "Choose another pool or adjust your filters to find a game."}
: "Choose another pool, game length or Library filters to find a game."}
</p>
</div>
)}
Expand Down
11 changes: 11 additions & 0 deletions docs/BACKLOG_ROULETTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ Drawing a game never changes your collection; only Mark as Playing changes statu
No API key, command line or additional setup is needed. The feature uses the
Library's existing authenticated data and status update endpoint.

## Find a weekend quest

Use **Game length** to choose **A short adventure** (up to 5 hours), **A weekend
quest** (up to 15 hours), or **A longer journey** (up to 40 hours). Roulette uses
the game's normal completion estimate from IGDB. This is estimated total time
to finish, not a single play session or remaining time for a game in progress.
Games without a positive, known estimate stay out of length-filtered draws;
**Any length**, the default, includes them. The selected game's estimate appears
beside its status. Changing the length draws again using the same pool and
Library filters.

## Pick from Playing

On **Playing**, **Pick a game** draws only from your currently playing games
Expand Down
Binary file added docs/pr-evidence/weekend-quest-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/pr-evidence/weekend-quest-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/pr-evidence/weekend-quest-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions tests/e2e/backlog-roulette.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@ import { test, expect } from "@playwright/test";
import { seedGame, uniqueId } from "./helpers";

test.describe("Backlog roulette", () => {
test("picks a weekend quest by completion time", async ({ page }, testInfo) => {
const id = uniqueId();
const prefix = `Weekend quest ${id}`;
await page.goto("/");
const short = await seedGame(page, {
title: `${prefix} Short adventure`,
igdbId: id,
status: "owned",
timeToBeatNormally: 4.56789,
});
await seedGame(page, {
title: `${prefix} Epic journey`,
igdbId: id + 1,
status: "owned",
timeToBeatNormally: 60,
});
await seedGame(page, { title: `${prefix} Mystery`, igdbId: id + 2, status: "owned" });
await page.reload();
await page.getByPlaceholder("Search your library...").fill(prefix);
await page.getByRole("button", { name: "Pick a game", exact: true }).click();
const dialog = page.getByRole("dialog", { name: "Backlog roulette" });
await dialog.getByRole("combobox", { name: "Game length" }).click();
await page.getByRole("option", { name: "A weekend quest · up to 15 hours" }).click();
await expect(dialog.getByTestId("roulette-title")).toHaveText(short.title);
await expect(dialog.getByText("Chosen from 1 matching game.")).toBeVisible();
await expect(dialog.getByText("About 4.6 hours to finish")).toBeVisible();
await expect(dialog.getByRole("button", { name: "Roll again" })).toBeDisabled();
await page.screenshot({ path: testInfo.outputPath("weekend-quest-desktop.png") });
await page.setViewportSize({ width: 390, height: 844 });
await page.screenshot({ path: testInfo.outputPath("weekend-quest-mobile.png") });
await page.evaluate(() => {
document.documentElement.classList.remove("dark");
document.documentElement.classList.add("light");
});
await page.screenshot({ path: testInfo.outputPath("weekend-quest-light.png") });
await dialog.getByRole("combobox", { name: "Game length" }).click();
await page.getByRole("option", { name: "Any length", exact: true }).click();
await expect(dialog.getByText("Chosen from 3 matching games.")).toBeVisible();
});
test("draws owned games, rerolls, opens details and saves Mark as Playing", async ({
page,
}, testInfo) => {
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Page } from "@playwright/test";
*/
export async function seedGame(
page: Page,
game: { title: string; igdbId: number; status?: string }
game: { title: string; igdbId: number; status?: string; timeToBeatNormally?: number }
): Promise<{ id: string; title: string }> {
const cookies = await page.context().cookies();
const csrf = cookies.find((c) => c.name === "questarr_csrf")?.value ?? "";
Expand All @@ -17,6 +17,7 @@ export async function seedGame(
title: game.title,
igdbId: game.igdbId,
status: game.status ?? "wanted",
timeToBeatNormally: game.timeToBeatNormally,
platforms: ["PC (Microsoft Windows)"],
genres: ["Adventure"],
releaseDate: "2020-01-15",
Expand Down
Loading