Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test: cover saved search success result
Wu Shuwen4d1eca74f99b
diff --git a/apps/client/src/widgets/search_result.spec.tsx b/apps/client/src/widgets/search_result.spec.tsxindex 68daa770c6..376692cbdb 100644--- a/apps/client/src/widgets/search_result.spec.tsx+++ b/apps/client/src/widgets/search_result.spec.tsx@@ -59,6 +59,7 @@ describe("SearchResult", () => {handlers.clear();triggerEvent.mockClear();loadSearchNote.mockClear();+ loadSearchNote.mockResolvedValue(undefined);showError.mockClear();shownContext.current = null;shownContext.parentComponent = parent;@@ -74,7 +75,7 @@ describe("SearchResult", () => {}});- it("surfaces errors returned by a saved search", async () => {+ function showSavedSearchButton() {const savedSearch = buildNote({title: "My search",type: "search",@@ -96,10 +97,15 @@ describe("SearchResult", () => {const button = mountedContainer.querySelector("button");expect(button).toBeTruthy();+ return { savedSearch, button: button! };+ }++ it("surfaces errors returned by a saved search", async () => {+ const { savedSearch, button } = showSavedSearchButton();loadSearchNote.mockResolvedValue({ error: "Invalid saved search" });await act(async () => {- button?.click();+ button.click();});expect(loadSearchNote).toHaveBeenCalledWith(savedSearch.noteId);@@ -108,4 +114,18 @@ describe("SearchResult", () => {ntxId: "ntx1",});});++ it("refreshes a saved search without showing an error when it succeeds", async () => {+ const { savedSearch, button } = showSavedSearchButton();++ await act(async () => {+ button.click();+ });++ expect(loadSearchNote).toHaveBeenCalledWith(savedSearch.noteId);+ expect(showError).not.toHaveBeenCalled();+ expect(triggerEvent).toHaveBeenCalledWith("searchRefreshed", {+ ntxId: "ntx1",+ });+ });});