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: 3 additions & 0 deletions src/lib/daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const BASE = "https://api.daily.dev/public/v1";
export type Bookmark = {
id: string;
title: string;
// Empty for posts that live on daily.dev itself (shares, freeform posts,
// collections); commentsPermalink is always set and opens the post there.
url: string;
commentsPermalink?: string;
image?: string;
summary?: string;
source?: { name?: string; image?: string };
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/roulette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ export function initRoulette(): void {

function read() {
if (!state.current) return;
window.open(state.current.url, "_blank", "noopener");
const link = state.current.url || state.current.commentsPermalink;
if (link) window.open(link, "_blank", "noopener");
removeCurrent();
state.survived++;
showToast("馃摉 Spared! Off you go to read it.", "spare");
Expand Down
33 changes: 33 additions & 0 deletions tests/e2e/real-mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,39 @@ test.describe("real mode: loading bookmarks", () => {
});
});

test.describe("real mode: sparing", () => {
test("a bookmark with no url opens its daily.dev post instead", async ({ page }) => {
// Shares, freeform posts and collections come back with url: "".
const permalink = "https://daily.dev/posts/a-shared-post-r3";
await page.route("**/api/bookmarks", async (route) => {
if (route.request().method() !== "GET") return route.continue();
await route.fulfill({
json: {
items: [{ ...REAL_BOOKMARKS[0], id: "r3", url: "", commentsPermalink: permalink }],
},
});
});
await page.addInitScript(() => {
const opened: string[] = [];
(window as unknown as { opened: string[] }).opened = opened;
window.open = (url) => {
opened.push(String(url));
return null;
};
});

await loadRouletteAsReal(page);
await page.locator("#spin").click();
await expect(page.locator("#verdict")).toBeVisible({ timeout: 8000 });
await page.getByRole("button", { name: /Spare it/ }).click();

await expect(page.locator("#stat-survived")).toHaveText("1");
expect(await page.evaluate(() => (window as unknown as { opened: string[] }).opened)).toEqual([
permalink,
]);
});
});

test.describe("real mode: pulling the trigger", () => {
test.beforeEach(async ({ page }) => {
page.context().on("page", (p) => p.close().catch(() => {}));
Expand Down
Loading