Skip to content

Commit

Permalink
Fix resizable table tests with fireEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
ggdouglas committed Jan 10, 2025
1 parent d6b8a6f commit 7a76c7f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/table/test/resizableTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { render } from "@testing-library/react";
import { fireEvent, render } from "@testing-library/react";
import { expect } from "chai";
import { mount } from "enzyme";
import * as React from "react";
Expand Down Expand Up @@ -94,7 +94,7 @@ describe("Resizable", () => {
expect(onResizeEnd.called).to.be.false;
});

it.skip("renders a draggable resize handle", () => {
it("renders a draggable resize handle", () => {
const onDoubleClick = sinon.spy();
const onLayoutLock = sinon.spy();
const onResizeEnd = sinon.spy();
Expand All @@ -114,28 +114,31 @@ describe("Resizable", () => {
<ResizableDiv />
</Resizable>,
);
const resizable = new ElementHarness(container);

const target = resizable.find(`.${Classes.TABLE_RESIZE_HANDLE_TARGET}`)!;
expect(target.element).to.exist;
const target = container.querySelector(`.${Classes.TABLE_RESIZE_HANDLE_TARGET}`);
expect(target).to.exist;

// drag resize handle to the right by 10 pixels
target.mouse("mousemove").mouse("mousedown").mouse("mousemove", 10).mouse("mouseup", 10);
fireEvent.mouseDown(target!);
fireEvent.mouseMove(target!, { clientX: 10 });
fireEvent.mouseUp(target!, { clientX: 10 });

expect(onLayoutLock.called).to.be.true;
expect(onLayoutLock.lastCall.args[0]).to.be.false;
expect(onSizeChanged.called).to.be.true;
expect(onResizeEnd.called).to.be.true;
expect(onDoubleClick.called).to.be.false;
expect(resizable.find(".resizable-div")!.bounds()!.width).to.equal(110);
expect(container.querySelector(".resizable-div")!.getBoundingClientRect().width).to.equal(110);

onDoubleClick.resetHistory();
onLayoutLock.resetHistory();
onResizeEnd.resetHistory();
onSizeChanged.resetHistory();

// double click the resize handle
target.mouse("mousemove").mouse("mousedown").mouse("mouseup", 10).mouse("mousedown").mouse("mouseup", 10);
fireEvent.mouseDown(target!);
fireEvent.mouseUp(target!, { clientX: 10 });
fireEvent.mouseDown(target!);
fireEvent.mouseUp(target!, { clientX: 10 });

expect(onLayoutLock.called).to.be.true;
expect(onSizeChanged.called).to.be.false;
Expand Down

0 comments on commit 7a76c7f

Please sign in to comment.