完善桌面体验与系统通知收口

This commit is contained in:
Cheng Zhou
2026-07-02 15:13:08 +08:00
parent a7b631f468
commit 5b387226a3
12 changed files with 428 additions and 23 deletions
@@ -39,7 +39,7 @@ describe("desktop notification manager", () => {
},
});
acknowledgeNotificationsMock.mockResolvedValue({ data: {} });
showNotificationMock.mockResolvedValue(undefined);
showNotificationMock.mockResolvedValue(true);
});
afterEach(async () => {
@@ -53,7 +53,7 @@ describe("desktop notification manager", () => {
it("acknowledges displayed notifications and leaves failed deliveries for retry", async () => {
showNotificationMock
.mockResolvedValueOnce(undefined)
.mockResolvedValueOnce(true)
.mockRejectedValueOnce(new Error("notification failed"));
const { initDesktopNotificationManager, triggerDesktopNotificationPoll } = await import("./desktopNotificationManager");
@@ -66,6 +66,21 @@ describe("desktop notification manager", () => {
expect(acknowledgeNotificationsMock).toHaveBeenCalledTimes(1);
});
it("does not acknowledge notifications when the system dispatch does not happen", async () => {
showNotificationMock
.mockResolvedValueOnce(false)
.mockResolvedValueOnce(true);
const { initDesktopNotificationManager, triggerDesktopNotificationPoll } = await import("./desktopNotificationManager");
initDesktopNotificationManager();
triggerDesktopNotificationPoll();
await vi.runOnlyPendingTimersAsync();
expect(showNotificationMock).toHaveBeenCalledTimes(2);
expect(acknowledgeNotificationsMock).toHaveBeenCalledWith("claim-token", ["notification-2"]);
expect(acknowledgeNotificationsMock).toHaveBeenCalledTimes(1);
});
it("does not claim notifications before operating system permission is granted", async () => {
getPermissionMock.mockResolvedValue("prompt");
const { initDesktopNotificationManager, triggerDesktopNotificationPoll } = await import("./desktopNotificationManager");