From e2ce1eb88b350d33a97e6534233995e63389319c Mon Sep 17 00:00:00 2001 From: Sanjib Kumar Sah <35219515+s4nju@users.noreply.github.com> Date: Fri, 19 May 2023 15:37:23 +0530 Subject: [PATCH] Test: added few test cases for Tooltip (#2714) * test: added few test cases for Tooltip * Update TextToolTip.test.tsx --------- Co-authored-by: Palash Gupta --- .../TextToolTip/TextToolTip.test.tsx | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 frontend/src/components/TextToolTip/TextToolTip.test.tsx diff --git a/frontend/src/components/TextToolTip/TextToolTip.test.tsx b/frontend/src/components/TextToolTip/TextToolTip.test.tsx new file mode 100644 index 0000000000..65192cf001 --- /dev/null +++ b/frontend/src/components/TextToolTip/TextToolTip.test.tsx @@ -0,0 +1,53 @@ +import { fireEvent, render, waitFor } from '@testing-library/react'; + +import TextToolTip from './index'; + +describe('TextToolTip', () => { + const tooltipText = 'Tooltip Text'; + + it('displays the tooltip when hovering over the icon', async () => { + const { getByRole, getByText } = render(); + const icon = getByRole('img'); + fireEvent.mouseOver(icon); + + await waitFor(() => { + const tooltip = getByText(tooltipText); + expect(tooltip).toBeInTheDocument(); + }); + }); + + it('renders the tooltip content correctly', async () => { + const { getByRole, getByText } = render( + , + ); + const icon = getByRole('img'); + fireEvent.mouseOver(icon); + + await waitFor(() => { + const tooltip = getByText(tooltipText); + const link = getByText('here'); + expect(tooltip).toBeInTheDocument(); + expect(link).toHaveAttribute('href', 'https://example.com'); + expect(link).toHaveAttribute('target', '_blank'); + }); + }); + + it('does not display the tooltip by default', () => { + const { queryByText } = render(); + const tooltip = queryByText(tooltipText); + expect(tooltip).toBeNull(); + }); + + it('opens the URL in a new tab when clicked', async () => { + const { getByRole } = render( + , + ); + const icon = getByRole('img'); + fireEvent.mouseOver(icon); + await waitFor(() => { + const link = getByRole('link'); + expect(link).toHaveAttribute('href', 'https://example.com'); + expect(link).toHaveAttribute('target', '_blank'); + }); + }); +});