Files
obsidian-excalidraw-plugin/scripts/testing/penToggleShortcut.test.mjs
T
zsviczian 8dbd9ad7ad Fix embed controls and add optional empty-tab drawing creation
Prefer physical table ownership for wrapped embeds and reset relative mobile toolbar offsets. Add independent ribbon and empty-tab action preferences using the canonical creation/settings pipelines, with maintained translations and deterministic cleanup.

Toggle pen to selection on a second unmodified P at the plugin capture boundary. Cancel incomplete Extras APIs cleanly while preserving version gates; the incomplete #3051 reporter cause remains unconfirmed. Pair native video coverage with fork PR #484's two-condition iframe fix.

Validation: 781 plugin source cases, five bundle checks, development/production builds, focused lint, CSS and inventory pass. Fork source/browser/type/audit evidence and inherited-test limitations are documented. Native CLI testing is explicitly paused at maintainer request. Versions and dependencies remain unchanged. Refs #3049, #3047, #3044, #3048 and #3051.
2026-11-14 08:30:51 +01:00

28 lines
2.0 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { sourceHarness } from "./sourceHarness.mjs";
test("P toggles freedraw to selection only for the owning canvas and ignores repeats", async () => {
const graph = sourceHarness();
try {
const { handlePenToggleShortcut: handle } = await graph.importModule("src/view/managers/penToggleShortcut.ts");
const selected = [], doc = {}, target = { ownerDocument: doc, closest: selector => selector === ".excalidraw" ? {} : null };
doc.activeElement = target;
const state = { activeTool: { type: "freedraw" } };
const view = { ownerDocument: doc, containerEl: { contains: el => el === target }, isClosingOrMigrating: () => false,
excalidrawAPI: { getAppState: () => state, setActiveTool: tool => selected.push(tool) } };
const event = extra => ({ key: "p", target, preventDefault() { this.prevented = true; }, stopPropagation() { this.stopped = true; }, ...extra });
const e = event(); assert.equal(handle(view, e), true); assert.equal(e.prevented, true); assert.equal(e.stopped, true);
assert.deepEqual(selected, [{ type: "selection" }]);
assert.equal(handle(view, event({ repeat: true })), true); assert.equal(selected.length, 1);
for (const flags of [{ ctrlKey: true }, { metaKey: true }, { altKey: true }, { shiftKey: true }, { isComposing: true }, { defaultPrevented: true }, { key: "v" }]) assert.equal(handle(view, event(flags)), false);
for (const flags of [{ activeTool: { type: "selection" } }, { newElement: {} }, { viewModeEnabled: true }, { openDialog: {} }]) {
const original = { ...state }; Object.assign(state, flags); assert.equal(handle(view, event()), false);
for (const key of Object.keys(state)) delete state[key]; Object.assign(state, original);
}
target.closest = () => ({}); assert.equal(handle(view, event()), false);
target.ownerDocument = {}; assert.equal(handle(view, event()), false);
assert.equal(selected.length, 1);
} finally { graph.close(); }
});