Skip to content
Open
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
5 changes: 5 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ and are asked to sign in again in Buzz.
is shortened with an ellipsis, hover over it or use the arrow keys to select
it and see the full name in a tooltip. A chosen or picked emoji is followed
by a space, unless one already follows, so you can keep typing.
- **Reminders**, in the desktop app when the plugin is on: choose **Remind me**
in a sent message's ⋯ menu. A confirmation names the due time, and the message
shows an alarm mark while the reminder is pending. In **Reminders**, a
reminder's due time snoozes it to a preset or **Custom…** date and time. A
reminder's note can't be edited once set.
- **Reminder counts** show how many reminders are due in a small capsule on the
app tile's corner. It shows `99+` above 99; its accessible label keeps the
exact count.
Expand Down
6 changes: 4 additions & 2 deletions docs/plugin-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -2748,8 +2748,10 @@ the entry appears; throwing matchers are skipped. `icon` renders beside the titl
Choosing the entry mounts `component` with `{ message, session, close, canOpen, open }` inside the
row, typically a dialog; it stays mounted until it calls `close()`. The optional
`marker` receives `{ message, session }` and renders beside the timestamp, such as a
state mark. It renders only while `matches` passes, so hiding the menu entry also
hides its mark. The host owns the menu, focus restoration and row lifetime: a row
state mark. A grouped message shows no byline, so its marks get a caption line of
their own above the message, which takes no space while they render nothing; like
the hidden byline, copying the row leaves them out. It renders only while
`matches` passes, so hiding the menu entry also hides its mark. The host owns the menu, focus restoration and row lifetime: a row
with an open action stays mounted while it scrolls out of view. Icon, component
and marker failures each render nothing and leave the row and menu usable. The
bundled Reminders plugin is the first consumer.
Expand Down
208 changes: 207 additions & 1 deletion src/bundled/reminders/RemindDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import { afterEach, assert, expect, it, vi } from "vitest";
import type { ChannelMessage } from "../../features/relay/contracts";
Expand All @@ -14,7 +15,9 @@ import { foldMessages } from "../../features/relay/fold";
import type { RelaySession } from "../../features/relay/session";
import { keypair, signed } from "../../features/relay/testing";
import userEvent from "@testing-library/user-event";
import { RemindDialog } from "./RemindDialog";
import { ToastProvider } from "../../shared/design-system/ui/Toast";
import { formatDue, nowSeconds } from "./model";
import { RemindDialog, SnoozeDialog } from "./RemindDialog";

afterEach(() => {
cleanup();
Expand Down Expand Up @@ -287,6 +290,209 @@ it("reveals labelled custom fields and saves a future time with the note", async
);
});

it("starts Custom date & time at the next 9am, so it never opens on a past time", async () => {
for (const [clock, date] of [
["2026-11-04T08:30", "2026-11-04"],
["2026-11-04T09:00", "2026-11-05"],
["2026-11-04T17:45", "2026-11-05"],
] as const) {
vi.useFakeTimers({ toFake: ["Date"], now: new Date(clock) });
try {
cleanup();
const user = userEvent.setup();
const create = vi.fn(async (..._args: unknown[]) => {});
dialog(create);
await user.click(screen.getByRole("combobox", { name: "When" }));
await user.click(
await screen.findByRole("option", { name: "Custom date & time" }),
);
expect(screen.getByLabelText("Reminder date")).toHaveValue(date);
expect(screen.getByLabelText("Reminder time")).toHaveValue("09:00");
expect(screen.queryByRole("status")).toBeNull();
const save = screen.getByRole("button", { name: "Set reminder" });
expect(save).toBeEnabled();
await user.click(save);
expect(create).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({ eventId: "m" }),
new Date(`${date}T09:00`).getTime() / 1000,
"",
);
} finally {
vi.useRealTimers();
}
}
});

it("confirms a saved reminder with its due time", async () => {
const create = vi.fn(async (..._args: unknown[]) => {});
const close = vi.fn();
render(
<ToastProvider>
<RemindDialog
message={
{
id: "m",
channelId: "c",
authorId: "a",
content: "hello",
} as unknown as ChannelMessage
}
session={{ reminders: { create } } as unknown as RelaySession}
close={close}
/>
</ToastProvider>,
);
await userEvent
.setup()
.click(screen.getByRole("button", { name: "Set reminder" }));
expect(close).toHaveBeenCalledOnce();
const at = create.mock.calls[0]?.[1] as number;
// Sonner mounts a toast transparent, then fades it in.
await waitFor(() =>
expect(screen.getByText(`Reminder set for ${formatDue(at)}`)).toBeVisible(),
);
});

it("starts a custom snooze at the reminder's due time while it is ahead, else the next 9am", () => {
const snooze = (due: number | undefined) =>
render(
<SnoozeDialog
title="Snooze reminder"
due={due}
cancelled={false}
save={vi.fn()}
close={vi.fn()}
finalFocus={() => null}
/>,
);
snooze(new Date("2099-06-20T16:15").getTime() / 1000);
expect(screen.getByLabelText("Reminder date")).toHaveValue("2099-06-20");
expect(screen.getByLabelText("Reminder time")).toHaveValue("16:15");
expect(screen.queryByRole("status")).toBeNull();
expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
// A past or undisplayable due time starts from the next 9am: today's until
// it passes, then tomorrow's, so Custom… never opens on a past time.
for (const [clock, date] of [
["2026-11-04T08:30", "2026-11-04"],
["2026-11-04T09:00", "2026-11-05"],
["2026-11-04T17:45", "2026-11-05"],
] as const) {
vi.useFakeTimers({ toFake: ["Date"], now: new Date(clock) });
try {
for (const due of [nowSeconds() - 60, 8_640_000_000_001, undefined]) {
cleanup();
snooze(due);
expect(screen.getByLabelText("Reminder date")).toHaveValue(date);
expect(screen.getByLabelText("Reminder time")).toHaveValue("09:00");
expect(screen.queryByRole("status")).toBeNull();
expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
}
} finally {
vi.useRealTimers();
}
}
});

it("saves an untouched custom snooze at its due time, even in the hour daylight saving repeats", async () => {
// In Los Angeles 01:30 on 2027-11-07 comes round twice: PDT, then PST.
const first = 1_825_576_200;
const second = first + 3600;
const zone = process.env.TZ;
process.env.TZ = "America/Los_Angeles";
vi.useFakeTimers({ toFake: ["Date"], now: (first - 3600) * 1000 });
try {
const user = userEvent.setup();
const open = (due: number) => {
cleanup();
const save = vi.fn(async (_notBefore: number) => {});
const props = {
title: "Snooze reminder",
cancelled: false,
save,
close: vi.fn(),
finalFocus: () => null,
};
const view = render(<SnoozeDialog {...props} due={due} />);
return {
saved: async () => {
await user.click(screen.getByRole("button", { name: "Save" }));
await waitFor(() => expect(props.close).toHaveBeenCalledOnce());
return save.mock.calls;
},
move: (to: number) =>
view.rerender(<SnoozeDialog {...props} due={to} />),
};
};
const date = () => screen.getByLabelText("Reminder date");
const time = () => screen.getByLabelText("Reminder time");
const enter = (value: string) =>
fireEvent.change(time(), { target: { value } });

const later = open(second);
expect(date()).toHaveValue("2027-11-07");
expect(time()).toHaveValue("01:30");
expect(await later.saved()).toEqual([[second]]);
const earlier = open(first);
expect(time()).toHaveValue("01:30");
expect(await earlier.saved()).toEqual([[first]]);
// An entered time is read as the hour's first pass, as anywhere else.
const edited = open(second);
enter("01:45");
expect(await edited.saved()).toEqual([[first + 900]]);
const restored = open(second);
enter("01:45");
enter("01:30");
expect(await restored.saved()).toEqual([[second]]);
// Another device moving the reminder leaves the fields, and what they
// stand for, as they opened.
const moved = open(second);
moved.move(second + 86_400);
expect(time()).toHaveValue("01:30");
expect(await moved.saved()).toEqual([[second]]);
// Between the two passes the fields would read as past, so the dialog
// starts from the next 9am instead.
vi.setSystemTime((first + 900) * 1000);
open(second);
expect(date()).toHaveValue("2027-11-07");
expect(time()).toHaveValue("09:00");
} finally {
vi.useRealTimers();
if (zone === undefined) delete process.env.TZ;
else process.env.TZ = zone;
}
});

it("keeps a cancelled reminder's custom snooze open, with what was typed, but won't save it", async () => {
const save = vi.fn(() => Promise.reject(new Error("offline")));
const props = {
title: "Snooze reminder",
due: new Date("2099-06-20T16:15").getTime() / 1000,
save,
close: vi.fn(),
finalFocus: () => null,
};
const view = render(<SnoozeDialog {...props} cancelled={false} />);
fireEvent.change(screen.getByLabelText("Reminder time"), {
target: { value: "17:30" },
});
await userEvent.setup().click(screen.getByRole("button", { name: "Save" }));
expect(await screen.findByRole("alert")).toHaveTextContent(
"The reminder could not be updated. Try again.",
);
view.rerender(<SnoozeDialog {...props} cancelled />);
expect(screen.getByRole("status")).toHaveTextContent(
"This reminder was cancelled.",
);
// There is nothing to try again, so the notice replaces the save error.
expect(screen.queryByRole("alert")).toBeNull();
expect(screen.getByLabelText("Reminder time")).toHaveValue("17:30");
const button = screen.getByRole("button", { name: "Save" });
expect(button).toBeDisabled();
fireEvent.click(button);
expect(save).toHaveBeenCalledOnce();
expect(screen.getByRole("button", { name: "Cancel" })).toBeEnabled();
});

it("stays open after a stray outside click", async () => {
const close = vi.fn();
render(
Expand Down
Loading
Loading