import { render } from '@testing-library/react';
import React from 'react';
import { InternalHighlight } from '../InternalHighlight';
import type { InternalHighlightProps } from '../InternalHighlight';
describe('Highlight', () => {
test('renders only wrapper with empty match', () => {
const { container } = render(
);
expect(container).toMatchInlineSnapshot(`
`);
});
test('renders parts', () => {
const { container } = render(
);
expect(container).toMatchInlineSnapshot(`
te
st
,
nothing
`);
});
test('renders with custom tag names and separator', () => {
function Highlighted({ children }) {
return {children};
}
function NonHighlighted({ children }) {
return {children};
}
const { container } = render(
- }
parts={[
[
{ isHighlighted: true, value: 'te' },
{ isHighlighted: false, value: 'st' },
],
[{ isHighlighted: false, value: 'nothing' }],
]}
/>
);
expect(container).toMatchInlineSnapshot(`
te
st
-
nothing
`);
});
test('accepts custom class names', () => {
const props: InternalHighlightProps = {
parts: [
[
{ isHighlighted: true, value: 'te' },
{ isHighlighted: false, value: 'st' },
],
[{ isHighlighted: false, value: 'nothing' }],
],
className: 'MyCustomInternalHighlight',
classNames: {
root: 'ROOT',
highlighted: 'HIGHLIGHTED',
nonHighlighted: 'NON-HIGHLIGHTED',
separator: 'SEPARATOR',
},
};
const { container } = render();
expect(container).toMatchInlineSnapshot(`
te
st
,
nothing
`);
});
test('forwards `div` props to the root element', () => {
const { container } = render(
);
expect(container.querySelector('.ROOT')).toHaveAttribute(
'aria-hidden',
'true'
);
});
});