Skip to content

Commit

Permalink
useRenderNormalizedItem tests (deephaven#1909)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 11, 2024
1 parent 055f953 commit 8d382b5
Showing 1 changed file with 41 additions and 0 deletions.
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>
);
}
);
}
);

0 comments on commit 8d382b5

Please sign in to comment.