Skip to content

Commit

Permalink
Merge pull request #30 from suisin-deriv/suisin/74076/ts_migration_fo…
Browse files Browse the repository at this point in the history
…r_account_limits_extra_info_and_tests

Suisin/74076/ts migration for account limits extra info and tests
  • Loading branch information
suisin-deriv committed Nov 2, 2022
2 parents bffa8ef + 66fe8c2 commit 3bf58d1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 36 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import { isMobile } from '@deriv/shared';
import AccountLimitsExtraInfo from '../account-limits-extra-info';

jest.mock('@deriv/shared', () => ({
...jest.requireActual('@deriv/shared'),
isMobile: jest.fn(() => true),
}));

describe('<AccountLimitsExtraInfo/>', () => {
it('should render AccountLimitsExtraInfo component', () => {
render(<AccountLimitsExtraInfo message='Lorem ipsum' />);
expect(screen.getByText(/lorem ipsum/i)).toBeInTheDocument();
});

it('should render PopoverComponent if isMobile is false', () => {
(isMobile as jest.Mock).mockReturnValue(false);
render(<AccountLimitsExtraInfo message='Lorem ipsum' />);
expect(screen.queryByTestId('dt_acc_limits_popover')).toHaveClass('da-account-limits__popover');
});

it('should pass props to PopoverComponent if isMobile is false', async () => {
(isMobile as jest.Mock).mockReturnValue(false);
render(<AccountLimitsExtraInfo message='Lorem ipsum' className='test_class' />);
const popover = await screen.findByTestId('dt_acc_limits_popover');
expect(popover).toHaveClass('test_class');
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import PropTypes from 'prop-types';
import * as React from 'react';
import { Popover, Text } from '@deriv/components';
import { isMobile } from '@deriv/shared';

const AccountLimitsExtraInfo = ({ message, ...props }) => {
type TAccountLimitsExtraInfo = {
message: string;
className?: string;
};

const AccountLimitsExtraInfo = ({ message, ...props }: TAccountLimitsExtraInfo) => {
if (isMobile()) {
return (
<Text color='less-prominent' line_height='s' size='xxxs'>
Expand All @@ -14,6 +18,7 @@ const AccountLimitsExtraInfo = ({ message, ...props }) => {

return (
<Popover
data_testid='dt_acc_limits_popover'
alignment='right'
className='da-account-limits__popover'
icon='info'
Expand All @@ -25,8 +30,4 @@ const AccountLimitsExtraInfo = ({ message, ...props }) => {
);
};

AccountLimitsExtraInfo.propTypes = {
message: PropTypes.string.isRequired,
};

export default AccountLimitsExtraInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import LoadErrorMessage from 'Components/load-error-message';
import DemoMessage from 'Components/demo-message';
import AccountLimitsArticle from './account-limits-article.jsx';
import AccountLimitsContext from './account-limits-context';
import AccountLimitsExtraInfo from './account-limits-extra-info.jsx';
import AccountLimitsExtraInfo from './account-limits-extra-info';
import AccountLimitsFooter from './account-limits-footer.jsx';
import AccountLimitsOverlay from './account-limits-overlay.jsx';
import AccountLimitsTableCell from './account-limits-table-cell';
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ const Popover = ({
should_show_cursor,
window_border,
zIndex = '1',
data_testid,
}: React.PropsWithChildren<Partial<TPopoverProps>>) => {
const ref = React.useRef<HTMLDivElement | undefined>();
const [popover_ref, setPopoverRef] = React.useState<HTMLDivElement | undefined>(undefined);

const [hover_ref, is_hovered] = useHover(null, true);
const [bubble_hover_ref, is_bubble_hovered] = useHoverCallback();

Expand Down Expand Up @@ -173,7 +175,7 @@ const Popover = ({
);
}}
>
<div className={classNames('dc-popover', className)} id={id}>
<div data-testid={data_testid} className={classNames('dc-popover', className)} id={id}>
<div className={classNames(classNameTarget, 'dc-popover__target')}>
{!disable_target_icon && (
<i
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/components/types/popover.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export type TPopoverProps = {
should_show_cursor?: boolean;
zIndex: string;
window_border: number;
data_testid?: string;
};

0 comments on commit 3bf58d1

Please sign in to comment.