Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[popover2] various fixes and improvements #4512

Merged
merged 7 commits into from
Feb 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tweak test suite
adidahiya committed Jan 28, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
commit c4e48f8d671448535ef36815d5bf205f8def7b0b
48 changes: 34 additions & 14 deletions packages/popover2/test/popover2Tests.tsx
Original file line number Diff line number Diff line change
@@ -216,19 +216,31 @@ describe("<Popover2>", () => {
describe("openOnTargetFocus", () => {
describe("if true (default)", () => {
it('adds tabindex="0" to target\'s child node when interactionKind is HOVER', () => {
assertPopoverTargetTabIndex("hover", true, true);
assertPopoverTargetTabIndex(true, {
interactionKind: "hover",
openOnTargetFocus: true,
});
});

it('adds tabindex="0" to target\'s child node when interactionKind is HOVER_TARGET_ONLY', () => {
assertPopoverTargetTabIndex("hover-target", true, true);
assertPopoverTargetTabIndex(true, {
interactionKind: "hover-target",
openOnTargetFocus: true,
});
});

it("does not add tabindex to target's child node when interactionKind is CLICK", () => {
assertPopoverTargetTabIndex("click", false, true);
assertPopoverTargetTabIndex(false, {
interactionKind: "click",
openOnTargetFocus: true,
});
});

it("does not add tabindex to target's child node when interactionKind is CLICK_TARGET_ONLY", () => {
assertPopoverTargetTabIndex("click-target", false, true);
assertPopoverTargetTabIndex(false, {
interactionKind: "click-target",
openOnTargetFocus: true,
});
});

it("opens popover on target focus when interactionKind is HOVER", () => {
@@ -268,19 +280,31 @@ describe("<Popover2>", () => {

describe("if false", () => {
it("does not add tabindex to target's child node when interactionKind is HOVER", () => {
assertPopoverTargetTabIndex("hover", false, false);
assertPopoverTargetTabIndex(false, {
interactionKind: "hover",
openOnTargetFocus: false,
});
});

it("does not add tabindex to target's child node when interactionKind is HOVER_TARGET_ONLY", () => {
assertPopoverTargetTabIndex("hover-target", false, false);
assertPopoverTargetTabIndex(false, {
interactionKind: "hover-target",
openOnTargetFocus: false,
});
});

it("does not add tabindex to target's child node when interactionKind is CLICK", () => {
assertPopoverTargetTabIndex("click", false, false);
assertPopoverTargetTabIndex(false, {
interactionKind: "click",
openOnTargetFocus: false,
});
});

it("does not add tabindex to target's child node when interactionKind is CLICK_TARGET_ONLY", () => {
assertPopoverTargetTabIndex("click-target", false, false);
assertPopoverTargetTabIndex(false, {
interactionKind: "click-target",
openOnTargetFocus: false,
});
});

it("does not open popover on target focus when interactionKind is HOVER", () => {
@@ -326,12 +350,8 @@ describe("<Popover2>", () => {
assert.equal(wrapper.state("isOpen"), isOpen);
}

function assertPopoverTargetTabIndex(
interactionKind: Popover2InteractionKind,
shouldTabIndexExist: boolean,
openOnTargetFocus?: boolean,
) {
wrapper = renderPopover({ interactionKind, openOnTargetFocus, usePortal: true });
function assertPopoverTargetTabIndex(shouldTabIndexExist: boolean, popoverProps: Partial<IPopover2Props>) {
wrapper = renderPopover({ ...popoverProps, usePortal: true });
const targetElement = wrapper.findClass(Classes.POPOVER2_TARGET).getDOMNode();

if (shouldTabIndexExist) {