Skip to content

Build your personal knowledge base with Trilium Notes

test(quick-search): cover the pinned link and the un-highlighted result path

BeatLink129241a8f025
diff --git a/apps/client/src/widgets/quick_search.spec.ts b/apps/client/src/widgets/quick_search.spec.ts
index 2184f8ceb7..8a4b5a5477 100644
--- a/apps/client/src/widgets/quick_search.spec.ts
+++ b/apps/client/src/widgets/quick_search.spec.ts
@@ -1,5 +1,8 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
+import appContext from "../components/app_context.js";
+import froca from "../services/froca.js";
+import linkService from "../services/link.js";
import server from "../services/server.js";
import QuickSearchWidget from "./quick_search.js";
@@ -49,6 +52,37 @@ describe("QuickSearchWidget", () => {
expect($footer.hasClass("hidden-ext")).toBe(true);
expect(widget.$widget.find(".quick-search-results .dropdown-item.disabled").length).toBe(1);
});
+
+ it("runs the full search from the pinned link, by click and by Enter", async () => {
+ const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockResolvedValue(undefined);
+ const widget = renderWidget();
+ mockResults(3);
+ await widget.search();
+
+ const $link = widget.$widget.find(".show-in-full-search");
+ $link.trigger("click");
+ expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "hello" });
+
+ triggerCommand.mockClear();
+ $link[0].dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", code: "Enter", bubbles: true }));
+ expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "hello" });
+ });
+
+ it("puts the results of a search the server did not highlight in the same scroller", async () => {
+ const widget = renderWidget();
+ vi.spyOn(server, "get").mockResolvedValue({
+ searchResultNoteIds: [ "note0", "note1" ],
+ error: ""
+ } as never);
+ vi.spyOn(froca, "getNotes").mockResolvedValue([ { noteId: "note0" }, { noteId: "note1" } ] as never);
+ vi.spyOn(linkService, "createLink").mockImplementation(async (notePath) => $("<span>").text(String(notePath)));
+
+ await widget.search();
+
+ const $menu = widget.$widget.find(".dropdown-menu");
+ expect($menu.find(".quick-search-results > .dropdown-item").length).toBe(2);
+ expect($menu.children().last().hasClass("quick-search-footer")).toBe(true);
+ });
});
function renderWidget() {