perf(project): smooth sidebar resizing
Batch drag updates per frame and defer full layout recalculation until release. Cover resize edge cases and retain goals review records.
This commit is contained in:
@@ -575,6 +575,47 @@ function titleVal(d) { return d.getElementById("pj-t-title").value; }
|
||||
check("[왼쪽 메뉴] 드래그 최소 너비·저장", layout.style.getPropertyValue("--pj-side-w") === "170px" && w.localStorage.getItem("pj_side_w") === "170");
|
||||
handle.dispatchEvent(new w.KeyboardEvent("keydown", { bubbles: true, key: "ArrowRight" }));
|
||||
check("[왼쪽 메뉴] 방향키 너비 조절", layout.style.getPropertyValue("--pj-side-w") === "180px");
|
||||
// 프레임을 직접 진행시켜 빠른 마우스 이동과 놓는 순간의 순서를 검증한다.
|
||||
const realRaf = w.requestAnimationFrame, realCancel = w.cancelAnimationFrame;
|
||||
let nextFrame = 0, resizeCount = 0;
|
||||
const frames = new Map();
|
||||
w.requestAnimationFrame = function (fn) { frames.set(++nextFrame, fn); return nextFrame; };
|
||||
w.cancelAnimationFrame = function (id) { frames.delete(id); };
|
||||
function paint() {
|
||||
const batch = Array.from(frames.values()); frames.clear(); batch.forEach(function (fn) { fn(); });
|
||||
}
|
||||
w.addEventListener("resize", function () { resizeCount++; });
|
||||
function down(x) { handle.dispatchEvent(new w.MouseEvent("mousedown", { bubbles: true, button: 0, clientX: x })); }
|
||||
function move(x) { d.dispatchEvent(new w.MouseEvent("mousemove", { bubbles: true, clientX: x })); }
|
||||
function up() { d.dispatchEvent(new w.MouseEvent("mouseup", { bubbles: true })); }
|
||||
down(200); move(220); move(240); move(260);
|
||||
check("[왼쪽 메뉴] 빠른 이동은 프레임 하나로 모으고 전체 재계산 없음", frames.size === 1 && resizeCount === 0 && handle.getAttribute("aria-valuenow") === "180");
|
||||
paint();
|
||||
check("[왼쪽 메뉴] 프레임에서 최신 위치만 즉시 표시", layout.style.getPropertyValue("--pj-side-w") === "240px" && resizeCount === 0);
|
||||
move(290); up();
|
||||
check("[왼쪽 메뉴] 놓는 순간 마지막 위치 반영·한 번 재계산·콜백 정리", layout.style.getPropertyValue("--pj-side-w") === "270px" && w.localStorage.getItem("pj_side_w") === "270" && resizeCount === 1 && frames.size === 0 && !d.documentElement.classList.contains("pj-side-resizing"));
|
||||
move(400); paint();
|
||||
check("[왼쪽 메뉴] 종료 뒤 이동은 너비를 바꾸지 않음", handle.getAttribute("aria-valuenow") === "270");
|
||||
d.documentElement.classList.add("pj-ui-scale");
|
||||
down(200); move(230); paint(); up();
|
||||
check("[왼쪽 메뉴] 75% 화면 배율에서도 이동 거리 보정", handle.getAttribute("aria-valuenow") === "310" && resizeCount === 2);
|
||||
d.documentElement.classList.remove("pj-ui-scale");
|
||||
down(200); move(1000); paint(); move(1100); paint(); up();
|
||||
check("[왼쪽 메뉴] 최대 500px·중복 프레임은 재계산 없음", handle.getAttribute("aria-valuenow") === "500" && resizeCount === 3);
|
||||
down(200); move(300); paint(); up();
|
||||
check("[왼쪽 메뉴] 한계에서 너비가 그대로면 재계산 생략", resizeCount === 3);
|
||||
down(200); move(150); w.dispatchEvent(new w.Event("blur"));
|
||||
check("[왼쪽 메뉴] 창 포커스를 잃어도 저장·드래그 정리", handle.getAttribute("aria-valuenow") === "450" && w.localStorage.getItem("pj_side_w") === "450" && resizeCount === 4 && frames.size === 0 && !handle.classList.contains("is-dragging"));
|
||||
handle.dispatchEvent(new w.KeyboardEvent("keydown", { bubbles: true, key: "Home" }));
|
||||
handle.dispatchEvent(new w.KeyboardEvent("keydown", { bubbles: true, key: "ArrowLeft" }));
|
||||
check("[왼쪽 메뉴] Home 최소값·한계 방향키 재계산 생략", handle.getAttribute("aria-valuenow") === "170" && resizeCount === 5);
|
||||
handle.dispatchEvent(new w.MouseEvent("dblclick", { bubbles: true }));
|
||||
check("[왼쪽 메뉴] 더블클릭 기본 너비·저장값 초기화", !layout.style.getPropertyValue("--pj-side-w") && handle.getAttribute("aria-valuenow") === "250" && w.localStorage.getItem("pj_side_w") === null && resizeCount === 6);
|
||||
// jsdom에는 레이아웃이 없으므로 좁은 창의 CSS 기본 너비(220px)를 직접 제공한다.
|
||||
d.querySelector(".pj-side").getBoundingClientRect = function () { return { width: 220 }; };
|
||||
handle.dispatchEvent(new w.KeyboardEvent("keydown", { bubbles: true, key: "ArrowRight" }));
|
||||
check("[왼쪽 메뉴] 기본값 복원 뒤 창 크기가 바뀌면 현재 너비에서 조절", handle.getAttribute("aria-valuenow") === "230" && resizeCount === 7);
|
||||
w.requestAnimationFrame = realRaf; w.cancelAnimationFrame = realCancel;
|
||||
const input = d.getElementById("pj-cm-input");
|
||||
Object.defineProperty(input, "scrollHeight", { value: 300 });
|
||||
input.value = "첫 줄\n둘째 줄\n셋째 줄"; input.dispatchEvent(new w.Event("input", { bubbles: true }));
|
||||
@@ -582,6 +623,11 @@ function titleVal(d) { return d.getElementById("pj-t-title").value; }
|
||||
input.value = ""; input.dispatchEvent(new w.Event("input", { bubbles: true }));
|
||||
check("[댓글] 비운 뒤에도 높이 70px", input.style.height === "70px");
|
||||
}
|
||||
{
|
||||
const env = makeEnv(); baseRoutes(env);
|
||||
env.w.localStorage.setItem("pj_side_w", "250"); await boot(env);
|
||||
check("[왼쪽 메뉴] 저장값이 기본 너비와 같아도 명시적으로 복원", env.d.querySelector(".pj-layout").style.getPropertyValue("--pj-side-w") === "250px");
|
||||
}
|
||||
clearTimeout(WATCHDOG);
|
||||
console.log(fails.length ? "\nFAILED: " + fails.join(", ") : "\nALL PASS");
|
||||
process.exit(fails.length ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user