|
1 | 1 | // @vitest-environment happy-dom |
2 | 2 |
|
3 | 3 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import { DomEditSaveQueueOpenError } from "../../utils/domEditSaveQueue"; |
4 | 5 | import type { DomEditSelection } from "./domEditing"; |
5 | 6 | import type { GestureState, UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures"; |
6 | 7 |
|
@@ -75,7 +76,9 @@ interface CommitCall { |
75 | 76 | offset: { x: number; y: number } | undefined; |
76 | 77 | } |
77 | 78 |
|
78 | | -function buildHarness() { |
| 79 | +function buildHarness( |
| 80 | + onBoxSizeCommit?: UseDomEditOverlayGesturesOptions["onBoxSizeCommitRef"]["current"], |
| 81 | +) { |
79 | 82 | const element = document.createElement("div"); |
80 | 83 | document.body.append(element); |
81 | 84 |
|
@@ -136,9 +139,12 @@ function buildHarness() { |
136 | 139 | onManualDragStartRef: ref(() => {}), |
137 | 140 | onPathOffsetCommitRef: ref(() => {}), |
138 | 141 | onGroupPathOffsetCommitRef: ref(() => {}), |
139 | | - onBoxSizeCommitRef: ref((_s, size, offset) => { |
140 | | - commits.push({ size, offset }); |
141 | | - }), |
| 142 | + onBoxSizeCommitRef: ref( |
| 143 | + onBoxSizeCommit ?? |
| 144 | + ((_s, size, offset) => { |
| 145 | + commits.push({ size, offset }); |
| 146 | + }), |
| 147 | + ), |
142 | 148 | onRotationCommitRef: ref(() => {}), |
143 | 149 | onCanvasPointerMoveRef: ref(() => Promise.resolve(null)), |
144 | 150 | onCanvasMouseDown: () => {}, |
@@ -172,6 +178,15 @@ function evt(clientX: number, clientY: number) { |
172 | 178 | } as unknown as React.PointerEvent<HTMLDivElement>; |
173 | 179 | } |
174 | 180 |
|
| 181 | +async function finishResize(handlers: ReturnType<typeof createDomEditOverlayGestureHandlers>) { |
| 182 | + handlers.startGesture("resize", evt(ORIGIN_CENTER.x + 100, ORIGIN_CENTER.y), { |
| 183 | + resizeHandle: "se", |
| 184 | + }); |
| 185 | + handlers.onPointerMove(evt(ORIGIN_CENTER.x + 150, ORIGIN_CENTER.y)); |
| 186 | + handlers.onPointerUp(evt(ORIGIN_CENTER.x + 150, ORIGIN_CENTER.y)); |
| 187 | + await Promise.resolve(); |
| 188 | +} |
| 189 | + |
175 | 190 | afterEach(() => { |
176 | 191 | document.body.innerHTML = ""; |
177 | 192 | }); |
@@ -211,4 +226,23 @@ describe("anchored corner resize — the release commit feeds the center-pin off |
211 | 226 | expect(offset.x).toBeCloseTo(-(size.width - ORIGIN.width) / 2, 0); |
212 | 227 | expect(offset.y).toBeCloseTo(-(size.height - ORIGIN.height) / 2, 0); |
213 | 228 | }); |
| 229 | + |
| 230 | + it("does not log a paused save queue as an ordinary resize failure", async () => { |
| 231 | + const consoleError = vi.spyOn(console, "error").mockImplementation(() => {}); |
| 232 | + const { handlers } = buildHarness(() => Promise.reject(new DomEditSaveQueueOpenError())); |
| 233 | + |
| 234 | + await finishResize(handlers); |
| 235 | + |
| 236 | + expect(consoleError).not.toHaveBeenCalled(); |
| 237 | + }); |
| 238 | + |
| 239 | + it("still logs an ordinary resize failure", async () => { |
| 240 | + const failure = new Error("save failed"); |
| 241 | + const consoleError = vi.spyOn(console, "error").mockImplementation(() => {}); |
| 242 | + const { handlers } = buildHarness(() => Promise.reject(failure)); |
| 243 | + |
| 244 | + await finishResize(handlers); |
| 245 | + |
| 246 | + expect(consoleError).toHaveBeenCalledWith("resize commit failed", failure); |
| 247 | + }); |
214 | 248 | }); |
0 commit comments