-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test(web-react): Add test for hook useFloatingUI
- Loading branch information
1 parent
c017828
commit 93236de
Showing
5 changed files
with
106 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/web-react/src/components/Tooltip/__tests__/TooltipPopover.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest'; | ||
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest'; | ||
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; | ||
import { TooltipPopover } from '..'; | ||
|
||
describe('TooltipPopover', () => { | ||
classNamePrefixProviderTest(TooltipPopover, 'Tooltip'); | ||
|
||
stylePropsTest((props) => <TooltipPopover {...props} data-testid="TooltipPopover-test" />, 'TooltipPopover-test'); | ||
|
||
restPropsTest((props) => <TooltipPopover {...props} />, 'div'); | ||
|
||
it('should render tooltip popover', () => { | ||
const popoverText = 'TooltipPopover'; | ||
|
||
const dom = render(<TooltipPopover>{popoverText}</TooltipPopover>); | ||
const element = dom.container.querySelector('.Tooltip') as HTMLElement; | ||
|
||
expect(element.textContent).toBe(popoverText); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/web-react/src/components/Tooltip/__tests__/TooltipTrigger.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest'; | ||
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; | ||
import { Button } from '../../Button'; | ||
import { TooltipTrigger } from '..'; | ||
|
||
describe('TooltipTrigger', () => { | ||
stylePropsTest((props) => <TooltipTrigger {...props} data-testid="TooltipTrigger-test" />, 'TooltipTrigger-test'); | ||
|
||
restPropsTest((props) => <TooltipTrigger elementType={Button} {...props} />, 'button'); | ||
|
||
it('should render tooltip trigger', () => { | ||
const id = 'TooltipTriggerTest'; | ||
const triggerText = 'TooltipTrigger'; | ||
|
||
const dom = render(<TooltipTrigger data-spirit-testid={id}>{triggerText}</TooltipTrigger>); | ||
const element = dom.container.querySelector(`[data-spirit-testid="${id}"]`) as HTMLElement; | ||
|
||
expect(element.textContent).toBe(triggerText); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/web-react/src/components/Tooltip/__tests__/useFloatingUI.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useFloatingUI } from '../useFloatingUI'; | ||
|
||
describe('useFloatingUI', () => { | ||
it('should initialize with default values', () => { | ||
const { result } = renderHook(() => | ||
useFloatingUI({ | ||
arrowRef: { current: null }, | ||
flipCrossAxis: false, | ||
flipFallbackAxisSideDirection: 'none', | ||
flipFallbackPlacements: 'bottom', | ||
flipProp: false, | ||
isOpen: false, | ||
onToggle: jest.fn(), | ||
shiftProp: false, | ||
sizeProp: false, | ||
tooltipPlacement: undefined, | ||
}), | ||
); | ||
|
||
expect(result.current.context).toBeDefined(); | ||
expect(result.current.getFloatingProps).toBeDefined(); | ||
expect(result.current.getReferenceProps).toBeDefined(); | ||
expect(result.current.middlewareData).toBeDefined(); | ||
expect(result.current.placement).toBeDefined(); | ||
expect(result.current.refs).toBeDefined(); | ||
expect(result.current.x).toBeDefined(); | ||
expect(result.current.y).toBeDefined(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/web-react/src/components/Tooltip/__tests__/useTooltipModernStyleProps.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { PlacementDictionaryType } from '../../../types'; | ||
import { useTooltipModernStyleProps, UseTooltipModernStyleProps } from '../useTooltipModernStyleProps'; | ||
|
||
describe('useTooltipModernStyleProps', () => { | ||
it('should return defaults', () => { | ||
const { result } = renderHook(() => useTooltipModernStyleProps({})); | ||
|
||
expect(result.current.classProps.rootClassName).toBe('Tooltip Tooltip--bottom'); | ||
expect(result.current.classProps.wrapperClassName).toBe('TooltipWrapper'); | ||
expect(result.current.classProps.arrowClassName).toBe('Tooltip__arrow'); | ||
expect(result.current.classProps.closeButtonClassName).toBe('Tooltip__close'); | ||
}); | ||
|
||
it('should change placement', () => { | ||
const props = { | ||
placement: 'top-right' as PlacementDictionaryType, | ||
} as UseTooltipModernStyleProps; | ||
const { result } = renderHook(() => useTooltipModernStyleProps(props)); | ||
|
||
expect(result.current.classProps.rootClassName).toBe('Tooltip Tooltip--topRight'); | ||
}); | ||
|
||
it('should return dismissible class', () => { | ||
const { result } = renderHook(() => useTooltipModernStyleProps({ isDismissible: true })); | ||
|
||
expect(result.current.classProps.rootClassName).toBe('Tooltip Tooltip--bottom Tooltip--dismissible'); | ||
}); | ||
}); |