feat(CAD): 332-3 설정 배선 — 휠 확대 방향 · 내 별칭
- 휠 — A00_Common/input_prefs 방향(기본 당김 = 지금과 같음 · 밀기 저장 뒤 뒤집힘) · 트랙패드 핀치는 늘 벌리면 확대(옛 CAD 는 벌리면 축소) - 별칭 — 명령 이름 > 내 별칭(cadAliases) > 기본 별칭 · 자동완성 후보 맨 앞 · 부를 때마다 읽어 저장 즉시 따름 - tsconfig include 에 input_prefs.ts · 시험 resources/tester/cad/input-prefs-cad.test.ts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013QyNXY2TUKXCFMwAca2APG
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* CAD 설정 배선(PLAN 332-3) — ☰ [설정] 휠 확대 방향 · 내 별칭(`A00_Common/input_prefs.ts`).
|
||||
* 휠 = 기본 당김(지금과 같음) · 밀기 저장 뒤 뒤집힘 · 핀치는 늘 벌리면 확대.
|
||||
* 별칭 = 명령 이름 > 내 별칭 > 기본 별칭 · 저장 즉시 따름.
|
||||
* 실행: cd B07_DesignDetail/openwebcad && npx vitest run --dir ../../resources/tester/cad input-prefs-cad
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { INPUT_PREFS_KEY } from "../../../A00_Common/input_prefs";
|
||||
import { wheelZoom } from "../../../B07_DesignDetail/openwebcad/src/inputController/input-wheel";
|
||||
import {
|
||||
matchCommandPrefixes,
|
||||
resolveCommandInput,
|
||||
} from "../../../B07_DesignDetail/openwebcad/src/commands/registry";
|
||||
import { getActiveToolActor } from "../../../B07_DesignDetail/openwebcad/src/state";
|
||||
import { initApplication } from "../../../B07_DesignDetail/openwebcad/test/helpers/init-application";
|
||||
|
||||
const store = new Map<string, string>();
|
||||
|
||||
const savePrefs = (value: unknown) => store.set(INPUT_PREFS_KEY, JSON.stringify(value));
|
||||
|
||||
beforeEach(() => {
|
||||
store.clear();
|
||||
vi.stubGlobal("localStorage", {
|
||||
getItem: (key: string) => store.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => store.set(key, value),
|
||||
removeItem: (key: string) => store.delete(key),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
const wheel = (deltaY: number, ctrlKey = false) =>
|
||||
wheelZoom({ deltaY, deltaMode: 0, ctrlKey })?.delta;
|
||||
|
||||
describe("휠 확대 방향", () => {
|
||||
it("저장 없음 = 당김(몸 쪽 deltaY > 0 → 확대 = 음수 delta) — 지금과 같음", () => {
|
||||
expect(wheel(100)).toBe(-100);
|
||||
expect(wheel(-100)).toBe(100);
|
||||
});
|
||||
|
||||
it("밀기 저장 → 뒤집힘 · 깨진 값 = 당김", () => {
|
||||
savePrefs({ wheelZoom: "push" });
|
||||
expect(wheel(100)).toBe(100);
|
||||
expect(wheel(-100)).toBe(-100);
|
||||
store.set(INPUT_PREFS_KEY, "{깨짐");
|
||||
expect(wheel(100)).toBe(-100);
|
||||
});
|
||||
|
||||
it("트랙패드 핀치(ctrl · 잔 델타)는 설정과 상관없이 벌리면(deltaY < 0) 확대", () => {
|
||||
expect(wheel(-7, true)).toBe(-7);
|
||||
expect(wheel(7, true)).toBe(7);
|
||||
savePrefs({ wheelZoom: "push" });
|
||||
expect(wheel(-7, true)).toBe(-7);
|
||||
// 마우스 Ctrl+휠(큰 델타)은 설정 방향
|
||||
expect(wheel(100, true)).toBe(100);
|
||||
});
|
||||
});
|
||||
|
||||
describe("내 별칭", () => {
|
||||
it("기본 별칭 그대로 · 내 별칭이 기본 별칭을 이김 · 명령 이름이 내 별칭을 이김", () => {
|
||||
expect(resolveCommandInput("L")?.id).toBe("LINE");
|
||||
savePrefs({ cadAliases: { CIRCLE: ["L"], ARC: ["LINE"] } });
|
||||
expect(resolveCommandInput("l")?.id).toBe("CIRCLE");
|
||||
expect(resolveCommandInput("LINE")?.id).toBe("LINE");
|
||||
});
|
||||
|
||||
it("새 별칭 · 자동완성 후보 맨 앞 · 없는 명령 이름은 무시", () => {
|
||||
savePrefs({ cadAliases: { RECTANG: ["QQ"], NOPE: ["QZ"] } });
|
||||
expect(resolveCommandInput("QQ")?.id).toBe("RECTANG");
|
||||
expect(matchCommandPrefixes("Q")[0]?.id).toBe("RECTANG");
|
||||
expect(resolveCommandInput("QZ")?.id).not.toBe("NOPE");
|
||||
});
|
||||
|
||||
it("CAD 키 입력 — 「qq␣」 = 사각형 명령", () => {
|
||||
savePrefs({ cadAliases: { RECTANG: ["QQ"] } });
|
||||
const controller = initApplication();
|
||||
for (const k of ["q", "q", " "]) {
|
||||
controller.handleKeyStroke({
|
||||
key: k,
|
||||
code: "",
|
||||
keyCode: 0,
|
||||
isComposing: false,
|
||||
shiftKey: false,
|
||||
ctrlKey: false,
|
||||
altKey: false,
|
||||
metaKey: false,
|
||||
repeat: false,
|
||||
target: null,
|
||||
preventDefault: vi.fn(),
|
||||
stopPropagation: vi.fn(),
|
||||
} as unknown as KeyboardEvent);
|
||||
}
|
||||
expect(getActiveToolActor()?.getSnapshot()?.context.type).toBe("RECTANGLE");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user