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
expect(event.defaultPrevented).toBe(false);
// drag not started
expect(isDragging(handle)).toBe(false);
});
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 });
// this last event shouldn't have any effect
fireEvent.mouseMove(window, { clientX: 25, clientY: 25 });
expect(container).toHaveStyle(`
top: 10px;
left: 10px;
`);
});
const { getByTestId, getByRole, getByText, getAllByTestId } = render();
expect(getByRole('listbox')).toHaveAttribute('aria-multiselectable', 'true');
const button = getByRole('button');
fireEvent.click(button);
const alphaItem = getByText('Alpha');
const betaItem = getByText('Beta');
const gammaItem = getByText('Gamma');
const deltaItem = getByText('Delta');
fireEvent.click(alphaItem);
fireEvent.click(betaItem);
fireEvent.mouseMove(gammaItem);
expect(gammaItem).toHaveAttribute('aria-selected', 'true');
fireEvent.mouseMove(deltaItem);
expect(deltaItem).toHaveAttribute('aria-selected', 'false');
const alphaDisplay = getByTestId('a');
fireEvent.click(alphaDisplay);
expect(alphaDisplay).not.toBeInTheDocument();
// Previous item should lose hover once another item is selected / removed
expect(gammaItem).toHaveAttribute('aria-selected', 'false');
fireEvent.mouseMove(betaItem);
expect(betaItem).toHaveAttribute('aria-selected', 'true');
fireEvent.mouseLeave(betaItem);
expect(betaItem).toHaveAttribute('aria-selected', 'false');
fireEvent.click(betaItem);
expect(() => getAllByTestId('b')).toThrow();
move: (handle: HTMLElement, point: Position) => {
fireEvent.mouseMove(handle, { clientX: point.x, clientY: point.y });
// movements are throttled by raf
act(() => {
requestAnimationFrame.step();
});
},
startDrop: (handle: HTMLElement) => {
>
{({getInputProps, getItemProps}) => (
<div>
<input data-testid="input">
<div>
<div>
</div>
)}
)
}
}
const {queryByTestId} = render()
const input = queryByTestId('input')
const item = queryByTestId('item-2')
fireEvent.mouseMove(item)
jest.runAllTimers()
expect(scrollIntoView).not.toHaveBeenCalled()
// now let's make sure that we can still scroll items into view
// ↓
fireEvent.keyDown(input, {key: 'ArrowDown'})
expect(scrollIntoView).toHaveBeenCalledWith(item, undefined)
})
</div></div>
export const swipeRightMouse = container => {
fireEvent.mouseDown(container, { clientX: 250, clientY: 20 });
fireEvent.mouseMove(container, { clientX: 350, clientY: 20 });
fireEvent.mouseUp(container, { clientX: 350, clientY: 20 });
};
lift: (handle: HTMLElement) => {
fireEvent.mouseMove(handle, { clientX: 0, clientY: sloppyClickThreshold });
},
move: (handle: HTMLElement) => {
beforeEach(() => {
({container, queryByText} = render(
{Trigger}
));
fireEvent.mouseMove(container.firstChild as HTMLElement);
jest.runAllTimers();
});
it('retains current focus treatment if html is initial pointer movement', () => {
const { getByTestId } = render();
const button = getByTestId('button');
fireEvent.keyDown(button);
fireEvent.mouseMove(document.documentElement);
fireEvent.focus(button);
expect(button).toHaveAttribute('data-garden-focus-visible');
});