|
| 1 | +import * as React from 'react'; |
| 2 | +import expect from 'expect'; |
| 3 | +import { render, screen } from '@testing-library/react'; |
| 4 | + |
| 5 | +import { |
| 6 | + Basic, |
| 7 | + Source, |
| 8 | + Label, |
| 9 | + Empty, |
| 10 | + Render, |
| 11 | + Field, |
| 12 | + Children, |
| 13 | +} from './RecordField.stories'; |
| 14 | +export default { |
| 15 | + title: 'ra-ui-materialui/fields/RecordField', |
| 16 | +}; |
| 17 | + |
| 18 | +describe('<RecordField />', () => { |
| 19 | + describe('source', () => { |
| 20 | + it('should render the source field from the record in context', () => { |
| 21 | + render(<Basic />); |
| 22 | + expect(screen.queryByText('War and Peace')).not.toBeNull(); |
| 23 | + }); |
| 24 | + it('should render nothing when the source is not found', () => { |
| 25 | + render(<Source />); |
| 26 | + expect(screen.queryByText('Missing field')).not.toBeNull(); |
| 27 | + }); |
| 28 | + it('should support paths with dots', () => { |
| 29 | + render(<Source />); |
| 30 | + expect(screen.queryByText('Leo Tolstoy')).not.toBeNull(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + describe('label', () => { |
| 34 | + it('should render the humanized source as label by default', () => { |
| 35 | + render(<Basic />); |
| 36 | + expect(screen.queryByText('Title')).not.toBeNull(); |
| 37 | + }); |
| 38 | + it('should render the label prop as label', () => { |
| 39 | + render(<Label />); |
| 40 | + expect(screen.queryByText('Identifier')).not.toBeNull(); |
| 41 | + }); |
| 42 | + it('should render no label when label is false', () => { |
| 43 | + render(<Label />); |
| 44 | + expect(screen.queryByText('Summary')).toBeNull(); |
| 45 | + }); |
| 46 | + }); |
| 47 | + describe('empty', () => { |
| 48 | + it('should render the translated empty when the record is undefined', () => { |
| 49 | + render(<Empty />); |
| 50 | + expect(screen.queryByText('No title')).not.toBeNull(); |
| 51 | + }); |
| 52 | + it('should render the translated empty when using a render prop', () => { |
| 53 | + render(<Empty />); |
| 54 | + expect(screen.queryByText('Unknown author')).not.toBeNull(); |
| 55 | + }); |
| 56 | + it('should render the translated empty when using a field prop', () => { |
| 57 | + render(<Empty />); |
| 58 | + expect(screen.queryByText('0')).not.toBeNull(); |
| 59 | + }); |
| 60 | + }); |
| 61 | + describe('render', () => { |
| 62 | + it('should render the value using the render prop', () => { |
| 63 | + render(<Render />); |
| 64 | + expect(screen.queryByText('WAR AND PEACE')).not.toBeNull(); |
| 65 | + }); |
| 66 | + it('should allow to render a React element', () => { |
| 67 | + render(<Render />); |
| 68 | + expect(screen.queryByText('LEO TOLSTOY')).not.toBeNull(); |
| 69 | + }); |
| 70 | + it('should not fail when the record is undefined', () => { |
| 71 | + render(<Render />); |
| 72 | + expect(screen.queryByText('Summary')).not.toBeNull(); |
| 73 | + }); |
| 74 | + }); |
| 75 | + describe('field', () => { |
| 76 | + it('should use the field component to render the field', () => { |
| 77 | + render(<Field />); |
| 78 | + expect(screen.queryByText('1,869')).not.toBeNull(); |
| 79 | + }); |
| 80 | + }); |
| 81 | + describe('children', () => { |
| 82 | + it('should render the field using the children rather than a TextField', () => { |
| 83 | + render(<Children />); |
| 84 | + expect(screen.queryByText('Leo Tolstoy')).not.toBeNull(); |
| 85 | + expect(screen.queryByText('(DECD)')).not.toBeNull(); |
| 86 | + }); |
| 87 | + }); |
| 88 | +}); |
0 commit comments