forked from farhoodlabs/paperclip
feat: polish inbox and issue list workflows
This commit is contained in:
@@ -10,12 +10,15 @@ import { useKeyboardShortcuts } from "./useKeyboardShortcuts";
|
||||
|
||||
function TestHarness({
|
||||
onNewIssue,
|
||||
onSearch,
|
||||
}: {
|
||||
onNewIssue: () => void;
|
||||
onSearch?: () => void;
|
||||
}) {
|
||||
useKeyboardShortcuts({
|
||||
enabled: true,
|
||||
onNewIssue,
|
||||
onSearch,
|
||||
});
|
||||
|
||||
return <div>keyboard shortcuts test</div>;
|
||||
@@ -55,4 +58,52 @@ describe("useKeyboardShortcuts", () => {
|
||||
root.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
it("focuses the current page search target on slash", () => {
|
||||
const root = createRoot(container);
|
||||
const onSearch = vi.fn();
|
||||
const input = document.createElement("input");
|
||||
input.setAttribute("data-page-search-target", "true");
|
||||
vi.spyOn(input, "getClientRects").mockReturnValue([{}] as unknown as DOMRectList);
|
||||
document.body.appendChild(input);
|
||||
|
||||
act(() => {
|
||||
root.render(<TestHarness onNewIssue={vi.fn()} onSearch={onSearch} />);
|
||||
});
|
||||
|
||||
document.dispatchEvent(new KeyboardEvent("keydown", {
|
||||
key: "/",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}));
|
||||
|
||||
expect(document.activeElement).toBe(input);
|
||||
expect(onSearch).not.toHaveBeenCalled();
|
||||
|
||||
act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
input.remove();
|
||||
});
|
||||
|
||||
it("falls back to quick search when the page has no search target", () => {
|
||||
const root = createRoot(container);
|
||||
const onSearch = vi.fn();
|
||||
|
||||
act(() => {
|
||||
root.render(<TestHarness onNewIssue={vi.fn()} onSearch={onSearch} />);
|
||||
});
|
||||
|
||||
document.dispatchEvent(new KeyboardEvent("keydown", {
|
||||
key: "/",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}));
|
||||
|
||||
expect(onSearch).toHaveBeenCalledTimes(1);
|
||||
|
||||
act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user