Skip to content

Commit

Permalink
test: added textarea test
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Valgoi committed Oct 3, 2020
1 parent ea58b38 commit 22416da
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/Form/TextArea/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ const TextArea = ({ field, form: { touched, errors }, labelText, rows, style, ..

return (
<FieldBase labelText={labelText}>
<UI5TextArea valueState={errorState} valueStateMessage={<span>{errorMsg}</span>} rows={rows} style={style ? style : spacing.sapUiSmallMarginBottom} {...props} {...field} />
<UI5TextArea
data-testid="textArea-wrapper"
valueState={errorState}
valueStateMessage={<span>{errorMsg}</span>}
rows={rows}
style={style ? style : spacing.sapUiSmallMarginBottom}
{...props}
{...field}
/>
</FieldBase>
);
};
Expand Down
26 changes: 26 additions & 0 deletions src/components/Form/TextArea/TextArea.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';

import '@testing-library/jest-dom/extend-expect';
import { render, screen } from '../../../util/TestSetup';

import TextArea from '../TextArea/TextArea';

describe('TextArea.js Test Suite', () => {
test('should match snapshot', () => {
const { asFragment } = render(
<TextArea labelText="Text Content" name="description" field={{ name: 'description' }} form={{ touched: { name: 'description' }, errors: { name: 'description' } }} />,
);

expect(asFragment()).toMatchSnapshot();
});

test('should have rendered with the fieldbase', () => {
render(<TextArea labelText="Text Content" name="description" field={{ name: 'description' }} form={{ touched: { name: 'description' }, errors: { name: 'description' } }} />);

const fieldbase = screen.getByTestId('fieldbase-wrapper');
const component = screen.getByTestId('textArea-wrapper');

expect(fieldbase).toBeInTheDocument();
expect(component).toBeInTheDocument();
});
});
40 changes: 40 additions & 0 deletions src/components/Form/TextArea/__snapshots__/TextArea.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TextArea.js Test Suite should match snapshot 1`] = `
<DocumentFragment>
<div
class="FlexBox-flexBox-0-2-1 FlexBox-flexBoxDirectionColumn-0-2-8 FlexBox-justifyContentStart-0-2-3 FlexBox-alignItemsStretch-0-2-15 FlexBox-flexWrapNoWrap-0-2-17"
data-testid="fieldbase-wrapper"
>
Label {
"_domRefReadyPromise": Promise {
"_deferredResolve": [Function],
},
"_firePropertyChange": false,
"_fullyConnected": false,
"_inDOM": false,
"_monitoredChildProps": Map {},
"_shouldInvalidateParent": false,
"_state": Object {
"for": "",
"required": false,
"showColon": false,
"wrap": true,
},
"_upToDate": false,
}
<ui5-textarea
data-testid="textArea-wrapper"
growing-max-lines="0"
name="description"
rows="0"
style="margin-bottom: 1rem;"
value-state="None"
>
<span
slot="valueStateMessage"
/>
</ui5-textarea>
</div>
</DocumentFragment>
`;

0 comments on commit 22416da

Please sign in to comment.