import * as React from 'react'; import { render, screen } from '@testing-library/react'; import { useGetRecordRepresentation } from './useGetRecordRepresentation'; import { ResourceDefinitionContextProvider } from './ResourceDefinitionContext'; const UseRecordRepresentation = ({ resource, record }) => { const getRecordRepresentation = useGetRecordRepresentation(resource); return <>{getRecordRepresentation(record)}; }; describe('useRecordRepresentation', () => { it('should return the record id by default', () => { render( ); screen.getByText('#123'); }); it('should return a record field if the recordRepresentation is a string', () => { render( ); screen.getByText('Doe'); }); it('should return a deep record field if the recordRepresentation is a string with a dot', () => { render( ); screen.getByText('Doe'); }); it('should return a string if the recordRepresentation is a function', () => { render( `${record.first_name} ${record.last_name}`, }, }} > ); screen.getByText('John Doe'); }); it('should return a React element if the recordRepresentation is a react element', () => { const Hello = () =>
Hello
; render( , }, }} > ); screen.getByText('Hello'); }); });