Skip to content

Commit c82e383

Browse files
fix(test): drop image inside table cell instead of viewport center
The trailing separator paragraph added after tables caused the synthetic drop at viewport center to land outside the cell. Target the rendered `.superdoc-table-fragment` element so the drop coordinates are inside the cell and getMaxContentSize() picks up the cell context.
1 parent bfa3db8 commit c82e383

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

tests/behavior/tests/tables/image-resize-in-cell.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ async function placeCursorInFirstTableCell(superdoc: SuperDocFixture): Promise<v
7575

7676
/**
7777
* Dispatch a synthetic drag-drop carrying a canvas-generated PNG of the given
78-
* pixel dimensions at the viewport's centre. Returns the number of files the
79-
* drop handler saw, mirroring the pattern in drag-drop-image-insertion.spec.ts.
78+
* pixel dimensions inside the first table cell. Returns the number of files
79+
* the drop handler saw, mirroring the pattern in drag-drop-image-insertion.spec.ts.
8080
*/
81-
async function dropOversizedImageAtViewportCentre(
81+
async function dropOversizedImageInFirstCell(
8282
superdoc: SuperDocFixture,
8383
imageWidthPx: number,
8484
imageHeightPx: number,
@@ -107,8 +107,11 @@ async function dropOversizedImageAtViewportCentre(
107107
dt.items.add(file);
108108
dt.effectAllowed = 'copy';
109109

110-
// Drop at the viewport centre.
111-
const rect = host.getBoundingClientRect();
110+
// Drop inside the rendered table fragment rather than the viewport
111+
// centre, which may land in the trailing separator paragraph.
112+
const tableFragment = host.querySelector('.superdoc-table-fragment');
113+
const targetEl = tableFragment ?? host;
114+
const rect = targetEl.getBoundingClientRect();
112115
const dropX = Math.round(rect.left + rect.width / 2);
113116
const dropY = Math.round(rect.top + rect.height / 2);
114117

@@ -179,7 +182,7 @@ test('image dropped into a narrow table cell is constrained to the cell width',
179182
const IMAGE_WIDTH_PX = 1200;
180183
const IMAGE_HEIGHT_PX = 900;
181184

182-
const { droppedFileCount } = await dropOversizedImageAtViewportCentre(superdoc, IMAGE_WIDTH_PX, IMAGE_HEIGHT_PX);
185+
const { droppedFileCount } = await dropOversizedImageInFirstCell(superdoc, IMAGE_WIDTH_PX, IMAGE_HEIGHT_PX);
183186

184187
// If the drop handler did not receive any files the test environment does not
185188
// support synthetic drops; skip rather than fail.

0 commit comments

Comments
 (0)