123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {Hovercard} from 'sentry/components/hovercard';
- describe('Hovercard', () => {
- beforeEach(() => {
- jest.useFakeTimers();
- jest.clearAllMocks();
- });
- afterEach(() => {
- jest.useRealTimers();
- });
- it('Displays card', async () => {
- render(
- <Hovercard
- position="top"
- body="Hovercard Body"
- header="Hovercard Header"
- displayTimeout={0}
- >
- Hovercard Trigger
- </Hovercard>
- );
- userEvent.hover(screen.getByText('Hovercard Trigger'));
- expect(await screen.findByText(/Hovercard Body/)).toBeInTheDocument();
- expect(await screen.findByText(/Hovercard Header/)).toBeInTheDocument();
- });
- it('Does not display card', () => {
- render(
- <Hovercard
- position="top"
- body="Hovercard Body"
- header="Hovercard Header"
- displayTimeout={0}
- forceVisible={false}
- >
- Hovercard Trigger
- </Hovercard>
- );
- userEvent.hover(screen.getByText('Hovercard Trigger'));
- act(() => void jest.runAllTimers());
- expect(screen.queryByText(/Hovercard Body/)).not.toBeInTheDocument();
- expect(screen.queryByText(/Hovercard Header/)).not.toBeInTheDocument();
- });
- it('Always displays card', () => {
- render(
- <Hovercard
- position="top"
- body="Hovercard Body"
- header="Hovercard Header"
- displayTimeout={0}
- forceVisible
- >
- Hovercard Trigger
- </Hovercard>
- );
- expect(screen.getByText(/Hovercard Body/)).toBeInTheDocument();
- expect(screen.getByText(/Hovercard Header/)).toBeInTheDocument();
- });
- it('Respects displayTimeout displays card', async () => {
- const DISPLAY_TIMEOUT = 100;
- render(
- <Hovercard
- position="top"
- body="Hovercard Body"
- header="Hovercard Header"
- delay={DISPLAY_TIMEOUT}
- displayTimeout={DISPLAY_TIMEOUT}
- >
- Hovercard Trigger
- </Hovercard>
- );
- userEvent.hover(screen.getByText('Hovercard Trigger'));
- act(() => void jest.advanceTimersByTime(DISPLAY_TIMEOUT - 1));
- expect(screen.queryByText(/Hovercard Body/)).not.toBeInTheDocument();
- expect(screen.queryByText(/Hovercard Header/)).not.toBeInTheDocument();
- expect(await screen.findByText(/Hovercard Body/)).toBeInTheDocument();
- expect(await screen.findByText(/Hovercard Header/)).toBeInTheDocument();
- });
- it('Doesnt leak timeout', () => {
- const DISPLAY_TIMEOUT = 100;
- render(
- <Hovercard
- position="top"
- body="Hovercard Body"
- header="Hovercard Header"
- delay={DISPLAY_TIMEOUT}
- displayTimeout={DISPLAY_TIMEOUT}
- >
- Hovercard Trigger
- </Hovercard>
- );
- userEvent.hover(screen.getByText('Hovercard Trigger'));
- act(() => void jest.advanceTimersByTime(DISPLAY_TIMEOUT - 1));
- expect(screen.queryByText(/Hovercard Body/)).not.toBeInTheDocument();
- expect(screen.queryByText(/Hovercard Header/)).not.toBeInTheDocument();
- userEvent.unhover(screen.getByText('Hovercard Trigger'));
- act(() => void jest.advanceTimersByTime(1));
- expect(screen.queryByText(/Hovercard Body/)).not.toBeInTheDocument();
- expect(screen.queryByText(/Hovercard Header/)).not.toBeInTheDocument();
- });
- });
|