import * as React from 'react';
import { render, screen } from '@testing-library/react';
import { useFieldValue, UseFieldValueOptions } from './useFieldValue';
import { RecordContextProvider } from '../controller';
describe('useFieldValue', () => {
const Component = (props: UseFieldValueOptions) => {
return
{useFieldValue(props) ?? 'None'}
;
};
it('should return undefined if no record is available', async () => {
render();
await screen.findByText('None');
});
it('should return the provided defaultValue if no record is available', async () => {
render();
await screen.findByText('Molly Millions');
});
it('should return the provided defaultValue if the record does not have a value for the source', async () => {
render(
);
await screen.findByText('Peter Riviera');
});
it('should return the field value from the record in RecordContext', async () => {
render(
);
await screen.findByText('John Wick');
});
it('should return the field value from the record in props', async () => {
render(
);
await screen.findByText('Johnny Silverhand');
});
it('should return the field value from a deep path', async () => {
render(
);
await screen.findByText('John');
});
});