Skip to content

Commit

Permalink
add overlay unit test
Browse files Browse the repository at this point in the history
FLUP from #3936
  • Loading branch information
adidahiya committed Jan 23, 2020
1 parent 912b8ea commit b48c6b7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/core/test/overlay/overlayTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ describe("<Overlay>", () => {
assertFocus("button", done);
});

it("does not crash while trying to return focus to overlay if user clicks outside the document", () => {
mountWrapper(
<Overlay enforceFocus={true} canOutsideClickClose={false} isOpen={true} usePortal={false}>
{createOverlayContents()}
</Overlay>,
);

// this is a fairly custom / nonstandard event dispatch, trying to simulate what happens in some browsers when a user clicks
// on the browser toolbar (outside the document), but a focus event is still dispatched to document
// see https://github.com/palantir/blueprint/issues/3928
const event = new FocusEvent("focus");
Object.defineProperty(event, "target", { value: window });

try {
document.dispatchEvent(event);
} catch (e) {
assert.fail("threw uncaught error");
}
});

function assertFocus(selector: string | (() => void), done: MochaDone) {
// the behavior being tested relies on requestAnimationFrame.
// setTimeout for a few frames later to let things settle (to reduce flakes).
Expand Down

1 comment on commit b48c6b7

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add overlay unit test

Previews: documentation | landing | table

Please sign in to comment.