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('useGetRecordRepresentation', () => { 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'); }); it('should return the record name at first', () => { render( ); screen.getByText('Ipsum'); }); it('should return the record title at second', () => { render( ); screen.getByText('Lorem'); }); it('should return the record label at third', () => { render( ); screen.getByText('lorem-ipsum'); }); it('should return the record reference at fourth', () => { render( ); screen.getByText('456'); }); it('should return the record id by default', () => { render( ); screen.getByText('#123'); }); });