import expect from 'expect'; import { render } from '@testing-library/react'; import * as React from 'react'; import { FieldTitle } from './FieldTitle'; import { TestTranslationProvider } from '../i18n'; describe('FieldTitle', () => { it('should return empty span by default', () => { const { container } = render(); expect(container.firstChild).toBeInstanceOf(HTMLSpanElement); expect(container.firstChild.textContent).toEqual(''); }); it('should use the label when given', () => { const { container } = render(); expect(container.firstChild.textContent).toEqual('foo'); }); it('should use the label as translate key when translation is available', () => { const { container } = render( ); expect(container.firstChild.textContent).toEqual('bar'); }); it('should use the humanized source when given', () => { const { container } = render( options._}> ); expect(container.firstChild.textContent).toEqual('Title'); }); it('should use the humanized source when given with underscores', () => { const { container } = render( options._}> ); expect(container.firstChild.textContent).toEqual( 'Title with underscore' ); }); it('should use the humanized source when given with camelCase', () => { const { container } = render( options._}> ); expect(container.firstChild.textContent).toEqual( 'Title with camel case' ); }); it('should use the source and resource as translate key when translation is available', () => { const { container } = render( ); expect(container.firstChild.textContent).toEqual('titre'); }); it('should use label rather than source', () => { const { container } = render( ); expect(container.firstChild.textContent).toEqual('foo'); }); it('should return null if label is false', () => { const { container } = render(); expect(container.firstChild).toBeNull(); }); it('should return null if label is empty string', () => { const { container } = render(); expect(container.firstChild).toBeNull(); }); });