Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yauheni/74112/formbodysection ts migration #19

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import FormBodySection from '../form-body-section';
import FormBodySection, { TFormBodySection } from '../form-body-section';

const MockFormBodySection = props => {
const MockFormBodySection = (props: TFormBodySection) => {
return (
<FormBodySection {...props}>
<p>Lorem Ipsum</p>
Expand All @@ -28,9 +28,9 @@ describe('Test coverage for FormBodySection component', () => {
});

it('When "side_note" value is not string, it should not render inside Text component', () => {
const test_side_note = 80;
const test_side_note = <div>test side note component</div>;
render(<MockFormBodySection has_side_note side_note={test_side_note} />);
expect(screen.getByText(test_side_note)).toBeInTheDocument();
expect(screen.getByText('test side note component')).toBeInTheDocument();
expect(screen.queryByTestId('side-note-text')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react';
import classNames from 'classnames';
import { PropTypes } from 'prop-types';
import { Text } from '@deriv/components';
import { PlatformContext } from '@deriv/shared';
import { TPlatformContext } from 'Types';

const FormBodySection = ({ children, has_side_note, side_note }) => {
const { is_appstore } = React.useContext(PlatformContext);
export type TFormBodySection = {
has_side_note?: boolean;
side_note?: string | React.ReactElement;
};

const FormBodySection = ({ children, has_side_note, side_note }: React.PropsWithChildren<TFormBodySection>) => {
const { is_appstore }: Partial<TPlatformContext> = React.useContext(PlatformContext);
if (has_side_note) {
return (
<div

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the test-id be replaced as per the coding guide?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. sure. Thanks for this 👍

Expand All @@ -25,11 +30,7 @@ const FormBodySection = ({ children, has_side_note, side_note }) => {
</div>
);
}
return children;
};
FormBodySection.prototype = {
children: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
has_side_note: PropTypes.bool,
side_note: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
return children as JSX.Element;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Rather than typecasting, may be it is better to return <React.Fragment>{children}</React.Fragment>

Copy link
Author

@yauheni-deriv yauheni-deriv Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@likhith-deriv, it makes tests broken. I also changed the same part of code for other components in other PRs

};

export default FormBodySection;
3 changes: 0 additions & 3 deletions packages/account/src/Components/form-body-section/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/account/src/Components/form-body-section/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import FormBodySection from './form-body-section';

export default FormBodySection;