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
client: fix some issues
Adorian Doran22df70f2c493
diff --git a/apps/client/src/test/setup.ts b/apps/client/src/test/setup.tsindex 9bec34ae8c..b21692d788 100644--- a/apps/client/src/test/setup.ts+++ b/apps/client/src/test/setup.ts@@ -28,8 +28,7 @@ function mockWebsocket() {// Do nothing.}- // Awaited by code that reads back what the server has just written. Nothing is written under- // test, so there is nothing to wait for.+ // Awaited before reading back what the server wrote. No write happens under test.async function waitForMaxKnownEntityChangeId() {}return {diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.tsindex 838a36978e..6fb90fc9ec 100644--- a/apps/client/src/widgets/collections/board/context_menu.ts+++ b/apps/client/src/widgets/collections/board/context_menu.ts@@ -170,21 +170,21 @@ const LISTED_COLUMNS = 7;/** What the board is, and what it can be asked to do, for a press on the ground its columns stand on. */interface BoardMenuTarget {- /** Whether the board keeps an inbox column, which the entry reports and toggles. */+ /** Whether the board keeps an inbox column. The entry shows it and toggles it. */inboxShown: boolean;- /** Whether the board draws the notes filed as archived. */+ /** Whether the board renders notes labelled `archived`. */archivedShown: boolean;- /** Opens the editor a column is named in, the same one the button at the end opens. */+ /** Opens the column name editor, the same one the button at the end opens. */onAddColumn: () => void;onCollapseAll: () => void;onExpandAll: () => void;onShowInbox: (shown: boolean) => void;onShowArchived: (shown: boolean) => void;- /** Opens the dialog holding what the board is set up with, its card templates among them. */+ /** Opens `BoardProperties`, which configures the card templates. */onOpenProperties: () => void;}-/** What the board itself offers, for a press on the ground the columns stand on. */+/** The board's own menu, opened by a right click outside any column. */export function openBoardContextMenu(event: ContextMenuEvent, board: BoardMenuTarget) {event.preventDefault();event.stopPropagation();diff --git a/apps/client/src/widgets/collections/board/properties.spec.tsx b/apps/client/src/widgets/collections/board/properties.spec.tsxindex 707e63f569..7d73be640e 100644--- a/apps/client/src/widgets/collections/board/properties.spec.tsx+++ b/apps/client/src/widgets/collections/board/properties.spec.tsx@@ -12,8 +12,8 @@ vi.mock("../../../services/i18n", () => ({t: (key: string) => key}));-// The card is the app's and is tested where it lives; what the board answers for is the words it is-// given and where what it holds is written.+// TemplateSelectionCard is tested in its own spec. What this dialog decides is the labels it+// passes and where onChange writes.vi.mock("../../react/TemplateSelectionCard", () => ({default: ({ heading, instruction, note, newTemplateName, templates, onChange }: {heading: string, instruction: string, note: FNote, newTemplateName?: string,@@ -58,8 +58,8 @@ describe("Board properties", () => {});afterEach(() => {- // Taken down before Bootstrap is: what is left of a dialog it still believes is shown holds- // the focus of everything after it, its teardown waiting on a transition happy-dom never+ // Unmounted before Bootstrap is disposed: a modal Bootstrap still believes is shown traps+ // the focus of every later test, and its teardown waits on a transition happy-dom never// runs.render(null, container);container.remove();@@ -81,7 +81,7 @@ describe("Board properties", () => {.toContain("board_view.properties-title");expect(card?.dataset.heading).toBe("board_view.card-templates");expect(card?.dataset.instruction).toBe("board_view.card-templates-hint");- // Filed under the board, and drawn from what the board offers now.+ // Filed under the board, and read from what the board offers now.expect(card?.dataset.note).toBe("board1");expect(card?.dataset.newName).toBe("board_view.new-template-name");expect(card?.dataset.templates).toBe("type:text:text/html");diff --git a/apps/client/src/widgets/react/SortableCard.spec.tsx b/apps/client/src/widgets/react/SortableCard.spec.tsxindex f28f173bef..ffb9d4c59f 100644--- a/apps/client/src/widgets/react/SortableCard.spec.tsx+++ b/apps/client/src/widgets/react/SortableCard.spec.tsx@@ -115,6 +115,30 @@ describe("SortableCard", () => {});});+ /**+ * A key pressed on a control inside a segment belongs to that control: Enter and Space+ * activate a button, and the entry's own commands must not fire alongside it.+ */+ it("leaves the keys of a control inside an entry to that control", async () => {+ const onItemKeyDown = vi.fn();+ draw({+ onItemKeyDown,+ renderItem: (item) => <button type="button" className="own">{item.caption}</button>,+ itemCreationButtons: [ makes("d", "Delta") ]+ });++ const button = segments()[0].querySelector<HTMLElement>(".own");+ press(button, " ");+ press(button, "Delete");+ press(button, "Enter");+ press(button, "ArrowDown", { ctrlKey: true });+ await act(async () => {});++ expect(onItemKeyDown).not.toHaveBeenCalled();+ expect(captions()).toEqual([ "Alpha", "Beta", "Gamma" ]);+ expect(changed).toEqual([]);+ });+describe("selection", () => {it("selects the entry the reader reaches, and says which it is", () => {const onSelect = vi.fn();diff --git a/apps/client/src/widgets/react/SortableCard.tsx b/apps/client/src/widgets/react/SortableCard.tsxindex 76418b0b0a..4f366f1425 100644--- a/apps/client/src/widgets/react/SortableCard.tsx+++ b/apps/client/src/widgets/react/SortableCard.tsx@@ -428,6 +428,12 @@ export function SortableCard<T extends SortableItem>({return;}+ // A key pressed on a control `renderItem` drew belongs to that control: Enter and Space+ // activate a button, and the card would otherwise act on the entry at the same time.+ if (event.target !== event.currentTarget) {+ return;+ }+// Creates an entry below the focused one, or above it with Shift, the way a spreadsheet// adds a row. Uses the first creation button, since no button was pressed.const leading = itemCreationButtons?.[0];