fix: textarea handle undefined

This commit is contained in:
Elliot DeNolf
2021-01-17 21:40:07 -05:00
parent c12d4757a4
commit ba31397ac1
4 changed files with 56 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import { render } from '@testing-library/react';
import BlocksCell from './field-types/Blocks';
import DateCell from './field-types/Date';
import Checkbox from './field-types/Checkbox';
import Textarea from './field-types/Textarea';
describe('Cell Types', () => {
describe('Blocks', () => {
@@ -87,4 +88,17 @@ describe('Cell Types', () => {
expect(el).toHaveTextContent('false');
});
});
describe('Textarea', () => {
it('renders data', () => {
const { container } = render(<Textarea data="data" />);
const el = container.querySelector('span');
expect(el).toHaveTextContent('data');
});
it('handle undefined - bug/13', () => {
const { container } = render(<Textarea data={undefined} />);
const el = container.querySelector('span');
expect(el).toHaveTextContent('');
});
});
});

View File

@@ -1,7 +1,7 @@
import React from 'react';
const TextareaCell = ({ data }) => {
const textToShow = data.length > 100 ? `${data.substr(0, 100)}\u2026` : data;
const textToShow = data?.length > 100 ? `${data.substr(0, 100)}\u2026` : data;
return (
<span>{textToShow}</span>
);