forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
useRenderNormalizedItem tests (deephaven#1909)
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/components/src/spectrum/utils/useRenderNormalizedItem.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,41 @@ | ||
import React, { Key } from 'react'; | ||
import { Item } from '@adobe/react-spectrum'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import ItemContent from '../ItemContent'; | ||
import { useRenderNormalizedItem } from './useRenderNormalizedItem'; | ||
import { getItemKey } from './itemUtils'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
expect.hasAssertions(); | ||
}); | ||
|
||
describe.each([null, { placement: 'top' }] as const)( | ||
'useRenderNormalizedItem: %s', | ||
tooltipOptions => { | ||
it.each([ | ||
[{}, 'Empty', ''], | ||
[{ item: { content: 'mock.content' } }, 'Empty', 'mock.content'], | ||
[ | ||
{ item: { textValue: 'mock.textValue', content: 'mock.content' } }, | ||
'mock.textValue', | ||
'mock.content', | ||
], | ||
])( | ||
'should return a render function that can be used to render a normalized item in collection components.', | ||
(normalizedItem, textValue, content) => { | ||
const { result } = renderHook(() => | ||
useRenderNormalizedItem(tooltipOptions) | ||
); | ||
|
||
const actual = result.current(normalizedItem); | ||
|
||
expect(actual).toEqual( | ||
<Item key={getItemKey(normalizedItem) as Key} textValue={textValue}> | ||
<ItemContent tooltipOptions={tooltipOptions}>{content}</ItemContent> | ||
</Item> | ||
); | ||
} | ||
); | ||
} | ||
); |