import React from 'react' import { render, snapshot } from '../utils/test-utils' import { GridCellDefault } from './cell-default' import { Calendar, Mail } from '@planview/pv-icons' import { Avatar } from '@planview/pv-uikit' import userEvent from '@testing-library/user-event' import { overflow } from '@planview/pv-utilities' jest.mock('@planview/pv-utilities', () => { const utilities: any = jest.requireActual('@planview/pv-utilities') return { __esModule: true, ...utilities, overflow: { ...utilities.overflow, isEllipsisActive: jest.fn().mockReturnValue(false), }, } }) describe('GridCellDefault', () => { snapshot('Minimal props', ) snapshot('Label', ) snapshot('Icon', } />) snapshot( 'Icon and Label', } label="Cell content" /> ) snapshot( 'Avatar (string)', ) snapshot( 'Avatar (component)', } /> ) snapshot( 'Avatar and Label', } label="Cell content" /> ) snapshot('Badge', ) snapshot( 'Badge and Label', ) snapshot( 'WithCaret', ) snapshot( 'With link', ) snapshot( 'With link and icon', } href="http://www.planview.com" /> ) snapshot( 'With numeric', ) snapshot( 'With numeric, left aligned', ) snapshot( 'With color', ) snapshot( 'With background color', ) describe('left content tooltip', () => { describe('with a badge', () => { describe('with tooltip content provided', () => { it('should show the tooltip on hover', async () => { const { getByText, findByRole } = render( ) await userEvent.hover(getByText('Long badge')) expect(await findByRole('tooltip')).toHaveTextContent( 'Very nice' ) }) }) describe('without tooltip content provided', () => { it('should show the badge content when ellipsed', async () => { jest.mocked(overflow.isEllipsisActive).mockReturnValue(true) const { getByText, findByRole } = render( ) await userEvent.hover(getByText('Long badge')) expect(await findByRole('tooltip')).toHaveTextContent( 'Long badge' ) }) it('should not show a tooltip when not ellipsed', async () => { jest.mocked(overflow.isEllipsisActive).mockReturnValue( false ) const { getByText, findByRole } = render( ) await userEvent.hover(getByText('Long badge')) await expect(async () => { await findByRole('tooltip', {}, { timeout: 300 }) }).rejects.toThrow(/Unable to find role="tooltip"/) }) }) }) }) describe('link', () => { it('should call onLinkClick when the link is clicked', async () => { const onLinkClick = jest.fn() const { getByRole } = render( ) await userEvent.click(getByRole('link')) expect(onLinkClick).toHaveBeenCalledTimes(1) }) it('should call href.onClick when the link is clicked', async () => { const onClick = jest.fn() const { getByRole } = render( ) await userEvent.click(getByRole('link')) expect(onClick).toHaveBeenCalledTimes(1) }) it('should prefer href.onClick if both onClick and onLinkClick are passed', async () => { const onLinkClick = jest.fn() const onClick = jest.fn() const { getByRole } = render( ) await userEvent.click(getByRole('link')) expect(onClick).toHaveBeenCalledTimes(1) expect(onLinkClick).not.toHaveBeenCalled() }) }) })