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 abort when there is a window scroll', () => {
const { getByText } = render();
const handle: HTMLElement = getByText('item: 0');
fireEvent.mouseDown(handle);
// abort
const event: Event = new Event('scroll', {
target: window,
bubbles: true,
cancelable: true,
});
fireEvent(window, event);
// would normally start
fireEvent.mouseMove(handle, {
clientX: 0,
clientY: sloppyClickThreshold,
});
// event not consumed as it is an indirect cancel
{isOpen ? : null}
)}
)
}
const {getByTestId, queryByTestId} = render()
expect(queryByTestId('menu')).toBeNull()
getByTestId('button').click()
expect(getByTestId('menu')).toBeInstanceOf(HTMLElement)
const notAnItem = getByTestId('not-an-item')
// Mouse events
fireEvent.mouseDown(notAnItem)
notAnItem.focus() // sets document.activeElement
fireEvent.mouseUp(notAnItem)
expect(getByTestId('menu')).toBeInstanceOf(HTMLElement)
// Touch events
fireEvent.touchStart(notAnItem)
fireEvent.touchEnd(notAnItem)
notAnItem.focus() // sets document.activeElement
expect(getByTestId('menu')).toBeInstanceOf(HTMLElement)
getByTestId('item').click()
expect(queryByTestId('menu')).toBeNull()
expect(getByTestId('selection')).toHaveTextContent('The item')
})
it('should keep min value', () => {
// ARRANGE
const TEST_ID = 'test-id';
const { getByTestId } = renderWithProvider(
);
const input = getByTestId(TEST_ID) as HTMLInputElement;
// ACT
fireEvent.mouseDown(document.getElementsByClassName('ant-input-number-handler-down')[0]);
// ASSERT
expect(input.value).toEqual('2');
});
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);
fireEvent.dragLeave(htmlEl);
fireEvent.dragOver(htmlEl);
fireEvent.dragStart(htmlEl);
fireEvent.drop(htmlEl);
fireEvent.mouseDown(htmlEl);
fireEvent.mouseEnter(htmlEl);
fireEvent.mouseLeave(htmlEl);
fireEvent.mouseMove(htmlEl);
fireEvent.mouseOut(htmlEl);
fireEvent.mouseOver(htmlEl);
fireEvent.mouseUp(htmlEl);
fireEvent.select(htmlEl);
fireEvent.touchCancel(htmlEl);
fireEvent.touchEnd(htmlEl);
fireEvent.touchMove(htmlEl);
fireEvent.touchStart(htmlEl);
fireEvent.scroll(htmlEl);
fireEvent.wheel(htmlEl);
fireEvent.abort(htmlEl);
fireEvent.canPlay(htmlEl);
fireEvent.canPlayThrough(htmlEl);
it('should follow the mouse until is dropped', () => {
const onClose = jest.fn();
const { container } = getQueries({
dragbar: ,
});
const dragbar = container.getElementsByClassName(
'rdl-float__drag-bar',
)[0];
fireEvent.mouseDown(dragbar, { clientX: 10, clientY: 10 });
fireEvent.mouseMove(window, { clientX: 11, clientY: 11 });
expect(container).toHaveStyle(`
top: 1px;
left: 1px;
`);
fireEvent.mouseMove(window, { clientX: 20, clientY: 20 });
expect(container).toHaveStyle(`
top: 10px;
left: 10px;
`);
fireEvent.mouseUp(window, { clientX: 20, clientY: 20 });
function mouseDownAndUp(node) {
fireEvent.mouseDown(node)
fireEvent.mouseUp(node)
}
function clickClearButton(container) {
const allSvgs = container.querySelectorAll('svg');
const clear = allSvgs[allSvgs.length - 2];
fireEvent.mouseDown(clear, {
button: 0,
});
}
const childrenSpy = jest.fn(({getItemProps}) => (
<div>
<button data-testid="external-button">
<div>
</div></button><button data-testid="in-item-button">
</button></div>
))
const {queryByTestId} = render({childrenSpy})
const externalButton = queryByTestId('external-button')
const inItemButton = queryByTestId('in-item-button')
childrenSpy.mockClear()
externalButton.focus()
expect(document.activeElement).toBe(externalButton)
fireEvent.mouseDown(inItemButton)
expect(document.activeElement).toBe(externalButton)
})
it('does not apply focus treatment if pointer is used', () => {
const { getByTestId } = render();
const button = getByTestId('button');
fireEvent.mouseDown(button);
fireEvent.focus(button);
expect(button).not.toHaveAttribute('data-garden-focus-visible');
});