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
20 changes: 20 additions & 0 deletions apps/desktop-tauri/src/surfaces/settings/tabs/GeneralTab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ describe("GeneralTab language picker", () => {
});
});

it("cancels the sound preview timer on unmount", () => {
vi.useFakeTimers();
try {
const { unmount } = render(
<GeneralTab mode="notifications" settings={settings} set={vi.fn()} saving={false} />,
);
fireEvent.click(
screen.getByRole("button", {
name: "NotificationSoundEventHighUsage: NotificationTestSound",
}),
);
expect(vi.getTimerCount()).toBeGreaterThan(0);

unmount();
expect(vi.getTimerCount()).toBe(0);
} finally {
vi.useRealTimers();
}
});

it("assigns and clears a custom WAV for one notification", async () => {
const set = vi.fn();
vi.mocked(open).mockResolvedValue("C:\\sounds\\high-usage.wav");
Expand Down
28 changes: 23 additions & 5 deletions apps/desktop-tauri/src/surfaces/settings/tabs/GeneralTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { useLocale } from "../../../hooks/useLocale";
import { invoke } from "@tauri-apps/api/core";
import { open } from "@tauri-apps/plugin-dialog";
Expand Down Expand Up @@ -168,15 +168,33 @@ export default function GeneralTab({
.catch(() => {}); // version row degrades to absent, never blocks the tab
}, []);

const soundPreviewTimeoutRef = useRef<number | null>(null);

useEffect(
() => () => {
if (soundPreviewTimeoutRef.current !== null) {
window.clearTimeout(soundPreviewTimeoutRef.current);
}
},
[],
);

const handleTestSound = useCallback((event: NotificationSoundEvent) => {
setSoundError(null);
setPlayingSound(event);
const timeoutId = window.setTimeout(
() => setPlayingSound(null),
NOTIFICATION_SOUND_PREVIEW_DURATION_MS,
);
if (soundPreviewTimeoutRef.current !== null) {
window.clearTimeout(soundPreviewTimeoutRef.current);
}
const timeoutId = window.setTimeout(() => {
soundPreviewTimeoutRef.current = null;
setPlayingSound(null);
}, NOTIFICATION_SOUND_PREVIEW_DURATION_MS);
soundPreviewTimeoutRef.current = timeoutId;
void playNotificationSound(event).catch((error: unknown) => {
window.clearTimeout(timeoutId);
if (soundPreviewTimeoutRef.current === timeoutId) {
soundPreviewTimeoutRef.current = null;
}
setPlayingSound(null);
setSoundError(error instanceof Error ? error.message : String(error));
});
Expand Down
13 changes: 9 additions & 4 deletions apps/desktop-tauri/src/surfaces/settings/tabs/HooksTab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,16 @@ describe("HooksTab", () => {
);
await renderTab(snapshot({ rules: full }));
expect(screen.getAllByTestId("hook-rule")).toHaveLength(32);
expect(screen.getByRole("button", { name: "+ HooksAddRule" })).toBeDisabled();
for (const add of screen.getAllByRole("button", { name: "+ HooksAddArgument" })) {
expect(add).toBeDisabled();
// Role queries over 32 × 32 argument rows are slow enough under a loaded
// CI runner to hit the default 5 s timeout; text queries find the same
// buttons, and the larger timeout covers the heavy render itself.
expect(screen.getByText("+ HooksAddRule").closest("button")).toBeDisabled();
const addArguments = screen.getAllByText("+ HooksAddArgument");
expect(addArguments).toHaveLength(32);
for (const add of addArguments) {
expect(add.closest("button")).toBeDisabled();
}
});
}, 20_000);

it("keeps an unreadable hooks.json read-only and shows why", async () => {
await renderTab(snapshot({ error: "expected value at line 1 column 1" }));
Expand Down