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(splits): cover the guards the keyboard actions reach
Elian Doran3d7fff548614
diff --git a/apps/client/src/components/tab_manager.spec.ts b/apps/client/src/components/tab_manager.spec.tsindex a10e969f04..669d914686 100644--- a/apps/client/src/components/tab_manager.spec.ts+++ b/apps/client/src/components/tab_manager.spec.ts@@ -218,6 +218,12 @@ describe("moving the focus between splits", () => {// and nothing sits to the left of the first paneawait tm.focusNoteSplitLeftCommand();expect(tm.activeNtxId).toBe(main.ntxId);++ // a pane closed between the keypress and the handler leaves the id behind; resolving it is+ // what getActiveMainContext() would throw over+ tm.activeNtxId = "already-gone";+ await tm.focusNoteSplitRightCommand();+ expect(tm.activeNtxId).toBe("already-gone");});});diff --git a/apps/client/src/widgets/containers/split_note_container.spec.tsx b/apps/client/src/widgets/containers/split_note_container.spec.tsxindex 2e9c0f0d7c..f3492da775 100644--- a/apps/client/src/widgets/containers/split_note_container.spec.tsx+++ b/apps/client/src/widgets/containers/split_note_container.spec.tsx@@ -1,5 +1,5 @@import { useLayoutEffect } from "preact/hooks";-import { beforeEach, describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import appContext from "../../components/app_context";import NoteContext from "../../components/note_context";@@ -22,6 +22,10 @@ describe("SplitNoteContainer", () => {let noteContexts: NoteContext[];let removeNoteContext: ReturnType<typeof vi.fn>;+ afterEach(() => {+ vi.unstubAllGlobals();+ });+beforeEach(() => {noteContexts = [];removeNoteContext = vi.fn();@@ -129,6 +133,21 @@ describe("SplitNoteContainer", () => {await container.moveActiveNoteSplitRightEvent({ ntxId: "split-b" });// and split-a is the first pane of the windowawait container.moveActiveNoteSplitLeftEvent({ ntxId: "split-a" });+ // other-tab is the last pane of all, so there is no neighbour to read, let alone swap+ await container.moveActiveNoteSplitRightEvent({ ntxId: "other-tab" });+ expect(triggerCommand).not.toHaveBeenCalled();+ });++ it("reports a move aimed at a pane that is not open", async () => {+ const container = await openSplits([ "split-a", "split-b" ]);+ const logError = vi.fn();+ vi.stubGlobal("logError", logError);+ const triggerCommand = vi.spyOn(container, "triggerCommand");++ // the pane can close between the keypress and the handler+ await container.moveActiveNoteSplitLeftEvent({ ntxId: "already-gone" });++ expect(logError).toHaveBeenCalled();expect(triggerCommand).not.toHaveBeenCalled();});});