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

Fasih/BL-406/Removed platformContext #14951

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import { RouteWithSubRoutesRender } from '../route-with-sub-routes';
import { Redirect } from 'react-router-dom';
import { PlatformContext } from '@deriv/shared';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand All @@ -21,22 +20,14 @@ afterEach(() => {

describe('<RouteWithSubRoutes />', () => {
it('should render one <RouteWithSubRoutesRender /> component', () => {
render(
<PlatformContext.Provider>
<RouteWithSubRoutesRender />
</PlatformContext.Provider>
);
render(<RouteWithSubRoutesRender />);

expect(screen.getByText(/Route loaded/)).toBeInTheDocument();
});

it('should have props as passed as route', () => {
const route = { path: '/test', component: Redirect, title: '', exact: true, to: '/root' };
render(
<PlatformContext.Provider>
<RouteWithSubRoutesRender {...route} />
</PlatformContext.Provider>
);
render(<RouteWithSubRoutesRender {...route} />);
expect(screen.getByText(/route loaded true \/test/i)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import { formatMoney, isDesktop, isMobile, PlatformContext } from '@deriv/shared';
import { formatMoney, isDesktop, isMobile } from '@deriv/shared';
import AccountLimits from '../account-limits';
import { BrowserRouter } from 'react-router-dom';
import { StoreProvider, mockStore } from '@deriv/stores';
Expand Down Expand Up @@ -362,25 +362,6 @@ describe('<AccountLimits/>', () => {
).toBeInTheDocument();
});

it('withdrawal_limits_table should show `Total withdrawal limit` if is_fully_authenticated is false and is_appstore is true', () => {
store = mockStore({
client: {
...mock.client,
is_fully_authenticated: false,
},
});
render(
<PlatformContext.Provider value={{ is_appstore: true, is_deriv_crypto: false, is_pre_appstore: false }}>
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
</BrowserRouter>
</PlatformContext.Provider>
);
expect(screen.getByText(/total withdrawal limit/i)).toBeInTheDocument();
});

it('withdrawal_limits_table should show `Total withdrawal allowed` when is_fully_authenticated is false and is_appstore is true', () => {
store = mockStore({
client: {
Expand All @@ -389,66 +370,13 @@ describe('<AccountLimits/>', () => {
},
});
render(
<PlatformContext.Provider value={{ is_appstore: false, is_deriv_crypto: false, is_pre_appstore: false }}>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
</PlatformContext.Provider>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
);
expect(screen.getByText(/total withdrawal allowed/i)).toBeInTheDocument();
});

it('withdrawal_limits_table should show the verfiy button when is_fully_authenticated is false and is_appstore is true', () => {
store = mockStore({
client: {
...mock.client,
is_fully_authenticated: false,
},
});
render(
<PlatformContext.Provider value={{ is_appstore: true, is_deriv_crypto: false, is_pre_appstore: false }}>
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
</BrowserRouter>
</PlatformContext.Provider>
);
expect(screen.getByText(/to increase limit please verify your identity/i)).toBeInTheDocument();
expect(
screen.getByRole('link', {
name: /verify/i,
})
).toHaveAttribute('href', '/account/proof-of-identity');
const { num_of_days_limit } = store.client.account_limits;
expect(formatMoney).toHaveBeenCalledWith(store.client.currency, num_of_days_limit, true);
});

it('withdrawal_limits_table should show total withdrawn and withdrawn remaining details', () => {
store = mockStore({
client: {
...mock.client,
is_fully_authenticated: false,
},
});
render(
<PlatformContext.Provider value={{ is_appstore: true, is_deriv_crypto: false, is_pre_appstore: false }}>
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
</BrowserRouter>
</PlatformContext.Provider>
);
const { withdrawal_since_inception_monetary, remainder } = store.client.account_limits;

expect(screen.getByText(/total withdrawn/i)).toBeInTheDocument();
expect(formatMoney).toHaveBeenCalledWith(store.client.currency, withdrawal_since_inception_monetary, true);

expect(screen.getByText(/maximum withdrawal remaining/i)).toBeInTheDocument();
expect(formatMoney).toHaveBeenCalledWith(store.client.currency, remainder, true);
});

it('should show limit_notice message when is_appstore is false and is_fully_authenticated is false in mobile mode', () => {
store = mockStore({
client: {
Expand All @@ -459,13 +387,11 @@ describe('<AccountLimits/>', () => {
(isMobile as jest.Mock).mockReturnValue(true);
(isDesktop as jest.Mock).mockReturnValue(false);
render(
<PlatformContext.Provider value={{ is_appstore: false, is_deriv_crypto: false, is_pre_appstore: false }}>
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
</BrowserRouter>
</PlatformContext.Provider>
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
</BrowserRouter>
);
expect(screen.getByText(/stated limits are subject to change without prior notice\./i)).toBeInTheDocument();
});
Expand All @@ -480,13 +406,11 @@ describe('<AccountLimits/>', () => {
(isMobile as jest.Mock).mockReturnValue(false);
(isDesktop as jest.Mock).mockReturnValue(true);
render(
<PlatformContext.Provider value={{ is_appstore: false, is_deriv_crypto: false, is_pre_appstore: false }}>
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} is_app_settings={false} />
</StoreProvider>
</BrowserRouter>
</PlatformContext.Provider>
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} is_app_settings={false} />
</StoreProvider>
</BrowserRouter>
);
expect(
screen.queryByText(/your account is fully authenticated and your withdrawal limits have been lifted\./i)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { FormikValues } from 'formik';
import classNames from 'classnames';
import { formatMoney, isDesktop, isMobile, useIsMounted, PlatformContext } from '@deriv/shared';
import { formatMoney, isDesktop, isMobile, useIsMounted } from '@deriv/shared';
fasihali-deriv marked this conversation as resolved.
Show resolved Hide resolved
import { Loading, ThemedScrollbars } from '@deriv/components';
import { Localize, localize } from '@deriv/translations';
import { observer, useStore } from '@deriv/stores';
Expand Down Expand Up @@ -49,7 +49,6 @@ const AccountLimits = observer(
const isMounted = useIsMounted();
const [is_loading, setLoading] = React.useState(true);
const [is_overlay_shown, setIsOverlayShown] = React.useState(false);
const { is_appstore } = React.useContext(PlatformContext);

const handleGetLimitsResponse = () => {
if (isMounted()) setLoading(false);
Expand Down Expand Up @@ -84,13 +83,8 @@ const AccountLimits = observer(

if (is_virtual) {
return (
<div
data-testid='dt_account_demo_message_wrapper'
className={classNames('account__demo-message-wrapper', {
'account__demo-message-wrapper-dashboard': is_appstore,
})}
>
<DemoMessage has_demo_icon={is_appstore} has_button={is_appstore} />
<div data-testid='dt_account_demo_message_wrapper' className={'account__demo-message-wrapper'}>
fasihali-deriv marked this conversation as resolved.
Show resolved Hide resolved
<DemoMessage />
fasihali-deriv marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { render, screen } from '@testing-library/react';
import { PlatformContext } from '@deriv/shared';
import { MissingPersonalDetails } from '../missing-personal-details';

jest.mock('@deriv/components', () => {
Expand All @@ -13,12 +12,7 @@ jest.mock('@deriv/components', () => {
});

describe('<MissingPersonalDetails />', () => {
const renderWithRouter = component =>
render(
<PlatformContext.Provider value={{ is_appstore: true, is_deriv_crypto: false, is_pre_appstore: false }}>
<BrowserRouter>{component}</BrowserRouter>
</PlatformContext.Provider>
);
const renderWithRouter = component => render(<BrowserRouter>{component}</BrowserRouter>);

it('should render the MissingPersonalDetails component', () => {
renderWithRouter(<MissingPersonalDetails />);
Expand Down Expand Up @@ -52,7 +46,7 @@ describe('<MissingPersonalDetails />', () => {
expect(
screen.getByText(/please complete your personal details before you verify your identity\./i)
).toBeInTheDocument();
expect(screen.getByText('IcAccountMissingDetailsDashboard')).toBeInTheDocument();
expect(screen.getByText('IcAccountMissingDetails')).toBeInTheDocument();

const btn = screen.getByRole('link', { name: /go to personal details/i });
expect(btn).toBeInTheDocument();
Expand All @@ -62,11 +56,9 @@ describe('<MissingPersonalDetails />', () => {

it('should show missing msg with proper icon if has_invalid_postal_code is false and is_appstore is false', () => {
render(
<PlatformContext.Provider value={{ is_appstore: false, is_deriv_crypto: false, is_pre_appstore: false }}>
<BrowserRouter>
<MissingPersonalDetails />
</BrowserRouter>
</PlatformContext.Provider>
<BrowserRouter>
<MissingPersonalDetails />
</BrowserRouter>
);

expect(screen.getByText(/your personal details are missing/i)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { PlatformContext } from '@deriv/shared';
import { ButtonLink, Icon, Text } from '@deriv/components';
import { localize } from '@deriv/translations';
import IconMessageContent from '../../icon-message-content';
Expand All @@ -24,7 +23,6 @@ const GoToPersonalDetailsButton = ({ anchor, from, text }: TGoToPersonalDetailsB
};

export const MissingPersonalDetails = ({ has_invalid_postal_code, from }: TGoToPersonalDetailsButton) => {
const { is_appstore } = React.useContext(PlatformContext);
if (has_invalid_postal_code)
return (
<IconMessageContent
Expand All @@ -43,9 +41,7 @@ export const MissingPersonalDetails = ({ has_invalid_postal_code, from }: TGoToP
<IconMessageContent
message={localize('Your personal details are missing')}
text={localize('Please complete your personal details before you verify your identity.')}
icon={
<Icon icon={is_appstore ? 'IcAccountMissingDetailsDashboard' : 'IcAccountMissingDetails'} size={128} />
}
icon={<Icon icon='IcAccountMissingDetails' size={128} />}
>
<GoToPersonalDetailsButton from={from} />
</IconMessageContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Button } from '@deriv/components';
import { PlatformContext } from '@deriv/shared';
import { UploadComplete } from '../upload-complete';
import { BrowserRouter } from 'react-router-dom';

Expand All @@ -23,29 +22,24 @@ describe('<UploadComplete />', () => {
const redirect_button = <Button>Lorem Ipsom</Button>;
const needs_poa_extra_submit_message = /you must also submit a proof of address./i;

const renderWithRouter = (component, is_appstore) =>
render(
<PlatformContext.Provider value={{ is_appstore }}>
<BrowserRouter>{component}</BrowserRouter>
</PlatformContext.Provider>
);
const renderWithRouter = component => render(<BrowserRouter>{component}</BrowserRouter>);

it('should display Icon if is_appstore is false', () => {
renderWithRouter(<UploadComplete />, false);
renderWithRouter(<UploadComplete />);

expect(screen.getByTestId(/dt_mocked_icon/)).toBeInTheDocument();
});

it('should render <UploadComplete /> component for manual upload', () => {
renderWithRouter(<UploadComplete is_manual_upload />, true);
renderWithRouter(<UploadComplete is_manual_upload />);

expect(screen.getByText(successful_upload_message)).toBeInTheDocument();
expect(screen.getByText(poi_under_review_message_for_manual)).toBeInTheDocument();
expect(screen.getByTestId(/dt_mocked_icon/i)).toBeInTheDocument();
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
it('should render <UploadComplete /> component for manual upload', () => {
renderWithRouter(<UploadComplete is_manual_upload />, true);
renderWithRouter(<UploadComplete is_manual_upload />);

expect(screen.getByText(successful_upload_message)).toBeInTheDocument();
expect(screen.getByText(poi_under_review_message_for_manual)).toBeInTheDocument();
Expand All @@ -54,19 +48,19 @@ describe('<UploadComplete />', () => {
});

it('should not show redirect_button if it redirect_button passed and is_from_external is true, but needs_poa is false', () => {
renderWithRouter(<UploadComplete is_from_external redirect_button={redirect_button} />, true);
renderWithRouter(<UploadComplete is_from_external redirect_button={redirect_button} />);

expect(screen.queryByRole('button')).not.toBeInTheDocument();
});

it('should show redirect button if needs_poa and is_from_external are false and have redirect button', () => {
renderWithRouter(<UploadComplete redirect_button={redirect_button} />, true);
renderWithRouter(<UploadComplete redirect_button={redirect_button} />);

expect(screen.getByRole('button')).toBeInTheDocument();
});

it('should show needs_poa review message and extra submission message, and poa_buttons', () => {
renderWithRouter(<UploadComplete needs_poa redirect_button={redirect_button} />, true);
renderWithRouter(<UploadComplete needs_poa redirect_button={redirect_button} />);

expect(screen.getByTestId('dt_poa_button')).toBeInTheDocument();
expect(screen.getByText(poi_under_review_message)).toBeInTheDocument();
Expand All @@ -75,7 +69,7 @@ describe('<UploadComplete />', () => {
});

it('should show needs_poa review message and extra submission message, and poa_buttons but redirect_button will not display', () => {
renderWithRouter(<UploadComplete needs_poa is_from_external redirect_button={redirect_button} />, true);
renderWithRouter(<UploadComplete needs_poa is_from_external redirect_button={redirect_button} />);

expect(screen.getByTestId('dt_poa_button')).toBeInTheDocument();
expect(screen.getByText(poi_under_review_message)).toBeInTheDocument();
Expand Down
Loading
Loading