Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should call the onKeyboardFocus with the correct values when there is a match", () => {
const { container } = render();
const items = container.querySelectorAll("[role='menuitem']");
fireEvent.keyDown(items[0], { key: "I" });
expect(onKeyboardFocus).toBeCalledWith(
expect.objectContaining({
element: items[1],
elementIndex: 1,
// using items causes a memeory leak for some reason
focusableElements: expect.any(Array),
}),
expect.any(Object)
);
fireEvent.keyDown(items[1], { key: "t" });
expect(onKeyboardFocus).toBeCalledWith(
expect.objectContaining({
element: items[2],
elementIndex: 2,
focusableElements: expect.any(Array),
}),
expect.any(Object)
);
});
});
it("calls the onRequestClose callback on pressing the ESC key", () => {
const closeSpy = jest.fn();
render(
<div>Component under test</div>
);
fireEvent.keyDown(global.document, {
keyCode: ESCAPE
});
expect(closeSpy).toHaveBeenCalled();
});
it("should not call the onKeyboardFocus when the key has a length greater than 1", () => {
const { getByRole } = render();
const menu = getByRole("menu");
fireEvent.keyDown(menu, { key: "Unidentified" });
progress();
fireEvent.keyDown(menu, { key: "Tab" });
progress();
fireEvent.keyDown(menu, { key: "Home" });
progress();
fireEvent.keyDown(menu, { key: "Shift" });
progress();
fireEvent.keyDown(menu, { key: "Alt" });
progress();
fireEvent.keyDown(menu, { key: "Option" });
progress();
fireEvent.keyDown(menu, { key: "Enter" });
progress();
it("should not trigger the onKeyboardFocus when there is not a valid keyboard key mapping", () => {
const { getByRole } = render(
);
const menu = getByRole("menu");
fireEvent.keyDown(menu);
fireEvent.keyDown(menu, { key: "Tab" });
fireEvent.keyDown(menu, { key: "Tab", shiftKey: true });
expect(onKeyboardFocus).not.toBeCalled();
});
});
it("do not calls the onKeyPress function on pressing any other key than ESC", () => {
const { container } = render(
<div>Europe</div>
<div>Africa</div>
<div>Asias</div>
);
fireEvent.keyDown(global.document, {
key: " ",
keyCode: 32
});
expect(container.firstChild).toMatchSnapshot();
});
it("should call the prop onKeyDown", () => {
const onKeyDown = jest.fn();
const { getByRole } = render();
fireEvent.keyDown(getByRole("menu"));
jest.runAllTimers();
expect(onKeyDown).toBeCalled();
});
it('Image should be deleted', async () => {
fireEvent.keyDown(clickedImage, { key: 'Backspace', code: 8})
await wait(() => expect(container.querySelector('img')).should.be.empty)
})
})
it('should expose fire event helpers', () => {
fireEvent.copy(htmlEl);
fireEvent.cut(htmlEl);
fireEvent.paste(htmlEl);
fireEvent.compositionEnd(htmlEl);
fireEvent.compositionStart(htmlEl);
fireEvent.compositionUpdate(htmlEl);
fireEvent.keyDown(htmlEl);
fireEvent.keyPress(htmlEl);
fireEvent.keyUp(htmlEl);
fireEvent.focus(htmlEl);
fireEvent.blur(htmlEl);
fireEvent.change(htmlEl);
fireEvent.input(htmlEl);
fireEvent.invalid(htmlEl);
fireEvent.submit(htmlEl);
fireEvent.click(htmlEl);
fireEvent.contextMenu(htmlEl);
fireEvent.dblClick(htmlEl);
fireEvent.doubleClick(htmlEl);
fireEvent.drag(htmlEl);
fireEvent.dragEnd(htmlEl);
fireEvent.dragEnter(htmlEl);
fireEvent.dragExit(htmlEl);
it("if entered texted doesn't not match then select the option that matched previously", () => {
const onChange = jest.fn();
const { queryAllByText, getByTestId } = renderTestComponentOne({
onChange
});
fireEvent.keyDown(getByTestId("test-dropContainer"), {
key: "ArrowDown",
keyCode: 40,
which: 40,
bubbles: true
});
fireEvent.keyDown(getByTestId("test-dropDownOptionOne"), {
key: "s",
keyCode: 83,
which: 83,
bubbles: true
});
fireEvent.keyDown(getByTestId("test-dropDownOptionOne"), {
key: "z",
keyCode: 90,
which: 90,
bubbles: true
});
fireEvent.keyDown(getByTestId("test-dropDownOptionOne"), {
key: "",
keyCode: 32,
it("should triggered onClose when pressing ESC key", () => {
const fn = jest.fn();
const { getByRole } = render({
onClose: fn,
children: Header,
});
fireEvent.keyDown(getByRole("dialog"), { key: "Escape", keyCode: 27, which: 27 });
expect(fn).toHaveBeenCalled();
});