Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
managedClasses,
};
const rendered: any = mount();
const triggerItem: any = rendered.find(treeItemExpandListTriggerSelector);
triggerItem.at(0).simulate("keyup", { keyCode: KeyCodes.space });
expect(
rendered
.find(treeItemExpandListTriggerSelector)
.at(0)
.parent()
.props()["aria-expanded"]
).toEqual(true);
triggerItem.at(0).simulate("keyup", { keyCode: KeyCodes.space });
expect(
rendered
.find(treeItemExpandListTriggerSelector)
.at(0)
.parent()
.props()["aria-expanded"]
).toEqual(false);
});
test("should update the state with the `dataLocation` prop if it has been passed", () => {
test("should call a registered callback after enter/space key is pressed", (): void => {
const onInvoke: any = jest.fn();
const onKeyDown: any = jest.fn();
const rendered: any = shallow(
);
rendered.simulate("keydown", { keyCode: KeyCodes.enter, preventDefault: noop });
rendered.simulate("keydown", { keyCode: KeyCodes.space, preventDefault: noop });
expect(onInvoke).toHaveBeenCalledTimes(2);
expect(onKeyDown).toHaveBeenCalledTimes(2);
});
test("should collapse an expanded list if the space key has been pressed on the list trigger", () => {
const props: any = {
...navigationProps,
data: standardData,
managedClasses,
};
const rendered: any = mount();
const triggerItem: any = rendered.find(treeItemListItemSelector);
triggerItem.at(0).simulate("keydown", { keyCode: KeyCodes.space });
expect(
rendered
.find(treeItemListItemSelector)
.at(0)
.parent()
.props()["aria-expanded"]
).toEqual(true);
triggerItem.at(0).simulate("keydown", { keyCode: KeyCodes.space });
expect(
rendered
.find(treeItemListItemSelector)
.at(0)
.parent()
const props: any = {
...navigationProps,
data: standardData,
managedClasses,
};
const rendered: any = mount();
const triggerItem: any = rendered.find(treeItemListItemSelector);
expect(
triggerItem
.at(0)
.parent()
.props()["aria-expanded"]
).toEqual(false);
triggerItem.at(0).simulate("keydown", { keyCode: KeyCodes.space });
expect(
rendered
.find(treeItemListItemSelector)
.at(0)
.parent()
.props()["aria-expanded"]
).toEqual(true);
});
test("should collapse an expanded list if the space key has been pressed on the list trigger", () => {
test("should call a registered callback after spacebar is pressed", (): void => {
const onInvoke: any = jest.fn();
const rendered: any = shallow();
rendered.simulate("keydown", { keyCode: KeyCodes.space });
expect(onInvoke).toHaveBeenCalledTimes(1);
});
test("should not call a registered callback after enter/space key is pressed because it is disabled", (): void => {
const onInvoke: any = jest.fn();
const onKeyDown: any = jest.fn();
const rendered: any = shallow(
);
rendered.simulate("keydown", { keyCode: KeyCodes.enter, preventDefault: noop });
rendered.simulate("keydown", { keyCode: KeyCodes.space, preventDefault: noop });
expect(onInvoke).toHaveBeenCalledTimes(0);
expect(onKeyDown).toHaveBeenCalledTimes(0);
});
const props: any = {
...navigationProps,
data: standardData,
managedClasses,
};
const rendered: any = mount();
const triggerItem: any = rendered.find(treeItemExpandListTriggerSelector);
expect(
triggerItem
.at(0)
.parent()
.props()["aria-expanded"]
).toEqual(false);
triggerItem.at(0).simulate("keyup", { keyCode: KeyCodes.space });
expect(
rendered
.find(treeItemExpandListTriggerSelector)
.at(0)
.parent()
.props()["aria-expanded"]
).toEqual(true);
});
test("should collapse an expanded list if the space key has been pressed on the list trigger", () => {
return (e: React.KeyboardEvent): void => {
e.preventDefault();
if (e.target === e.currentTarget) {
switch (e.keyCode) {
case KeyCodes.enter:
case KeyCodes.space:
if (e.target === e.currentTarget) {
this.toggleItems(dataLocation);
}
break;
case KeyCodes.arrowDown:
this.focusNextTreeItem(dataLocation);
break;
case KeyCodes.arrowUp:
this.focusPreviousTreeItem(dataLocation);
break;
case KeyCodes.arrowRight:
this.focusAndOpenTreeItems(dataLocation);
break;
case KeyCodes.arrowLeft:
this.focusAndCloseTreeItems(dataLocation);
break;
{itemA}
{itemB}
{itemC}
);
const select: any = rendered.find("select");
expect(select.prop("value")).toEqual([]);
expect(select.prop("multiple")).toBe(true);
expect(select.prop("required")).toBe(true);
expect(select.prop("name")).toBe("testName");
expect(select.prop("form")).toBe("testForm");
rendered
.find('[displayString="a"]')
.simulate("keydown", { keyCode: KeyCodes.space });
expect(rendered.find("select").prop("value")).toEqual(["a"]);
rendered
.find('[displayString="a"]')
.simulate("keydown", { keyCode: KeyCodes.arrowDown, shiftKey: true });
expect(rendered.find("select").prop("value")).toEqual(["a", "b"]);
});
<select>
{itemA}
{itemB}
{itemC}
</select>
);
expect(rendered.state("selectedItems").length).toBe(1);
expect(onValueChange).toHaveBeenCalledTimes(0);
rendered.simulate("click");
expect(rendered.state("isMenuOpen")).toBe(true);
rendered
.find('[displayString="a"]')
.simulate("keydown", { keyCode: KeyCodes.space });
expect(rendered.state("selectedItems").length).toBe(1);
expect(rendered.state("value")).toBe("a");
expect(onValueChange).toHaveBeenCalledTimes(1);
});