Skip to content

Build your personal knowledge base with Trilium Notes

test(quick_search): cover the branches the patch left half-taken

Elian Doran7f85ac78cfce
diff --git a/apps/client/src/widgets/quick_search.spec.tsx b/apps/client/src/widgets/quick_search.spec.tsx
index 9d3abe01be..3b24457256 100644
--- a/apps/client/src/widgets/quick_search.spec.tsx
+++ b/apps/client/src/widgets/quick_search.spec.tsx
@@ -79,7 +79,9 @@ describe("QuickSearch", () => {
});
it("links to the plain note path when the search highlighted nothing", async () => {
- vi.spyOn(server, "get").mockResolvedValue(response(1, []));
+ const plain = response(1, []);
+ delete plain.searchResults[0].highlightedNotePathTitle;
+ vi.spyOn(server, "get").mockResolvedValue(plain);
const { editor } = await mount();
typeQuery(editor, "#book");
@@ -87,6 +89,8 @@ describe("QuickSearch", () => {
const [ first ] = await waitForResults(1);
expect(first.getAttribute("href")).toBe(calculateHash({ notePath: "root/note0" }));
+ // Nor its title, which then shows as it stands.
+ expect(first.querySelector(".search-result-title")?.innerHTML).toBe("Note 0");
});
it("shows progress while searching, then says when nothing matches", async () => {
@@ -202,6 +206,11 @@ describe("QuickSearch", () => {
target.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
});
first.focus();
+ // A key the results do not answer stays where it was pressed.
+ expect(first.dispatchEvent(new KeyboardEvent("keydown", { key: "a", bubbles: true, cancelable: true })))
+ .toBe(true);
+ expect(document.activeElement).toBe(first);
+
press(first, "ArrowDown");
expect(document.activeElement).toBe(second);
press(second, "ArrowUp");
@@ -322,6 +331,11 @@ describe("QuickSearch", () => {
pressKey(editor.contentDOM, "Escape");
await vi.waitFor(() => expect(menu()).toBeNull());
expect(editor.hasFocus).toBe(true);
+
+ // With the results closed, Escape is left to whatever the field sits in.
+ expect(editor.contentDOM.dispatchEvent(new KeyboardEvent("keydown", {
+ key: "Escape", bubbles: true, cancelable: true
+ }))).toBe(true);
});
it("leaves ArrowDown to the field while the results are closed or hold nothing to focus", async () => {
diff --git a/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx b/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx
index a4eda472bd..0907d23e70 100644
--- a/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx
+++ b/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx
@@ -47,6 +47,17 @@ describe("SearchStringEditor", () => {
editor.dispatch({ changes: { from: 11, insert: " = 1954" } });
expect(onChange).toHaveBeenCalledWith("#book #year = 1954");
});
+
+ it("leaves ArrowDown to the caret when no handler takes it", async () => {
+ const { editor } = await mount({ noteId: "search1", currentValue: "#book\n#year", onChange: () => {} });
+ editor.dispatch({ selection: { anchor: 0 } });
+
+ editor.contentDOM.dispatchEvent(new KeyboardEvent("keydown", {
+ key: "ArrowDown", bubbles: true, cancelable: true
+ }));
+ expect(editor.state.doc.lineAt(editor.state.selection.main.head).number).toBe(2);
+ });
+
it("registers the keys the field answers on the host component", () => {
const host = new Component();
act(() => {