alexandrusoare commented on code in PR #45090:
URL: https://github.com/apache/superset/pull/45090#discussion_r4283897066


##########
superset-frontend/src/features/canvas/CanvasGrid.test.tsx:
##########
@@ -190,3 +213,81 @@ test('setting a cross-filter does nothing while 
cross-filters are off', () => {
 
   expect(onValueChange).not.toHaveBeenCalled();
 });
+
+test('a canvas that is not editable gets no drag or resize handles', () => {
+  renderGrid();
+
+  expect(
+    screen.queryByRole('button', { name: 'Move widget' }),
+  ).not.toBeInTheDocument();
+  expect(
+    screen.queryByRole('button', { name: 'Resize widget' }),
+  ).not.toBeInTheDocument();
+});
+
+test('an editable canvas gets a handle per placed widget', () => {
+  renderGrid(emptyScopeValues(), jest.fn(), result, jest.fn(), true);
+
+  // Every node with a resolved placement, on the root grid and inside the
+  // nested group, is draggable and resizable.
+  expect(screen.getAllByRole('button', { name: 'Move widget' })).toHaveLength(
+    Object.keys(result.placements).length,
+  );
+  expect(screen.getAllByRole('button', { name: 'Resize widget' 
})).toHaveLength(
+    Object.keys(result.placements).length,
+  );
+});
+
+/**
+ * jsdom carries none of the properties a gesture needs on its own
+ * `PointerEvent`, so these are built on `MouseEvent` with the pointer id added
+ * -- the same shape `CanvasGridSurface.test.tsx` uses.
+ */
+class TestPointerEvent extends MouseEvent {
+  pointerId: number;
+
+  constructor(type: string, init: MouseEventInit = {}) {
+    super(type, { bubbles: true, cancelable: true, ...init });
+    this.pointerId = 1;
+  }
+}
+
+const dragRight = (handle: HTMLElement, dx: number) =>
+  [
+    new TestPointerEvent('pointerdown', { button: 0, clientX: 0, clientY: 0 }),
+    new TestPointerEvent('pointermove', { clientX: dx, clientY: 0 }),
+    new TestPointerEvent('pointerup', { clientX: dx, clientY: 0 }),
+  ].forEach(event => fireEvent(handle, event));
+
+beforeAll(() => {
+  // jsdom lays nothing out, so every grid is told it is 1000px wide.
+  Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
+    configurable: true,
+    get: () => 1000,
+  });
+  // jsdom has no pointer capture; the gesture only needs it not to throw.
+  HTMLElement.prototype.setPointerCapture = jest.fn();
+  HTMLElement.prototype.releasePointerCapture = jest.fn();
+});
+
+test('a nested grid resizes against its own column count, not the root', () => 
{

Review Comment:
   You're right, {} would have passed. Added a case that drags c1's corner well 
past the left edge and asserts colSpan: 2 rather than 1; it fails if the prop 
is replaced with {}.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to