Skip to content

Commit

Permalink
fix: conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-deriv committed Aug 9, 2023
2 parents 548c578 + ae6293d commit e82b1a2
Show file tree
Hide file tree
Showing 143 changed files with 2,771 additions and 1,251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,20 @@ describe('<PersonalDetails/>', () => {
const el_tax_residence = screen.getByTestId('selected_value');
expect(el_tax_residence).toHaveTextContent('Malta');
});

it('should disable tax_residence field if it is immutable from BE', () => {
isMobile.mockReturnValue(false);
isDesktop.mockReturnValue(true);
const new_props = {
...props,
is_mf: true,
value: {
...props.value,
tax_residence: 'France',
},
disabled_items: ['salutation', 'first_name', 'last_name', 'date_of_birth', 'tax_residence'],
};
renderwithRouter(<PersonalDetails {...new_props} />);
expect(screen.getByTestId('tax_residence')).toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('<IdvDocumentSubmit/>', () => {
document_1: { display_name: 'Test document 1 name', format: '5436454364243' },
document_2: { display_name: 'Test document 2 name', format: 'A54321' },
},
has_visual_sample: true,
has_visual_sample: 1,
},
},
},
Expand All @@ -80,7 +80,7 @@ describe('<IdvDocumentSubmit/>', () => {
expect(screen.queryByText('Please select a document type.')).not.toBeInTheDocument();

const inputs = screen.getAllByRole<HTMLTextAreaElement>('textbox');
expect(inputs.length).toBe(5);
expect(inputs).toHaveLength(5);
expect(inputs[0].name).toBe('document_type');
expect(inputs[1].name).toBe('document_number');
});
Expand Down
109 changes: 109 additions & 0 deletions packages/account/src/Configs/__test__/personal-details-config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { personal_details_config } from 'Configs/personal-details-config';

jest.mock('@deriv/shared', () => ({
...jest.requireActual('@deriv/shared'),
getErrorMessages: jest.fn().mockReturnValue({
name: jest.fn(),
password: jest.fn(),
}),
generateValidationFunction: jest.fn(),
getDefaultFields: jest.fn(),
toMoment: jest.fn(),
validLength: jest.fn(),
}));
describe('personal-details-config', () => {
const mock_props = {
residence_list: [
{
services: {
idv: {
documents_supported: {},
has_visual_sample: 0,
is_country_supported: 0,
},
onfido: {
documents_supported: {
passport: {
display_name: 'Passport',
},
},
is_country_supported: 0,
},
},
phone_idd: '93',
text: 'Afghanistan',
value: 'af',
tin_format: [],
disabled: '1',
},
{
services: {
idv: {
documents_supported: {},
has_visual_sample: 0,
is_country_supported: 0,
},
onfido: {
documents_supported: {
driving_licence: {
display_name: 'Driving Licence',
},
national_identity_card: {
display_name: 'National Identity Card',
},
passport: {
display_name: 'Passport',
},
residence_permit: {
display_name: 'Residence Permit',
},
},
is_country_supported: 1,
},
phone_idd: '93',
text: 'Indonesia',
value: 'af',
tin_format: [],
disabled: '1',
},
},
],
account_settings: {
tax_residence: 'af',
residence: 'Indonesia',
},
is_appstore: false,
real_account_signup_target: 'maltainvest',
account_status: { cashier_validation: ['system_maintenance'] },
};

it('should return account tax residence as default value if it is already set', () => {
const personal_details = personal_details_config(mock_props);
expect(personal_details[0].tax_residence.default_value).toEqual('Afghanistan');
});

it('should return residence as the default value for MF clients, If the account tax residence is not set', () => {
const new_props = {
...mock_props,
account_settings: {
...mock_props.account_settings,
tax_residence: '',
},
};
const personal_details = personal_details_config(new_props);
expect(personal_details[0].tax_residence.default_value).toEqual(new_props.account_settings.residence);
});

it('should not set default value for CR clients, If the account tax residence is not set', () => {
const new_props = {
...mock_props,
real_account_signup_target: 'svg',
account_settings: {
...mock_props.account_settings,
tax_residence: '',
},
};
const personal_details = personal_details_config(new_props);
expect(personal_details[0].tax_residence.default_value).toEqual('');
});
});
12 changes: 7 additions & 5 deletions packages/account/src/Configs/personal-details-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type TPersonalDetailsConfig = {
account_status: GetAccountStatus;
};

const personal_details_config = ({
export const personal_details_config = ({
residence_list,
account_settings,
is_appstore,
Expand All @@ -38,6 +38,8 @@ const personal_details_config = ({
const min_phone_number = 9;
const max_phone_number = 35;

const default_residence = real_account_signup_target === 'maltainvest' ? account_settings?.residence : '';

const config = {
account_opening_reason: {
supported_in: ['iom', 'malta', 'maltainvest'],
Expand Down Expand Up @@ -114,10 +116,10 @@ const personal_details_config = ({
],
},
tax_residence: {
default_value:
real_account_signup_target === 'maltainvest'
? account_settings.residence
: residence_list.find(item => item.value === account_settings.tax_residence)?.text || '',
//if tax_residence is already set, we will use it as default value else for mf clients we will use residence as default value
default_value: account_settings?.tax_residence
? residence_list.find(item => item.value === account_settings?.tax_residence)?.text ?? ''
: default_residence,
supported_in: ['maltainvest'],
rules: [['req', localize('Tax residence is required.')]],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const EmailVerificationEmptyState = ({ type }: TEmailVerificationEmptyStateProps

const action = {
label: localize("Didn't receive the email?"),
onClick: verify.send,
onClick: () => verify.send(),
tertiary: true,
};

Expand All @@ -30,7 +30,7 @@ const EmailVerificationEmptyState = ({ type }: TEmailVerificationEmptyStateProps
<EmailVerificationResendEmptyState
is_counter_running={verify.is_counter_running}
counter={verify.counter}
resend={verify.send}
resend={() => verify.send()}
/>
)}
</div>
Expand Down
7 changes: 5 additions & 2 deletions packages/cashier/src/containers/cashier/cashier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ const Cashier = observer(({ history, location, routes: routes_config }: TCashier
}, [history, is_payment_agent_transfer_visible, is_payment_agent_transfer_visible_is_success]);

React.useEffect(() => {
if (is_p2p_enabled_success && !is_p2p_enabled && history.location.pathname === routes.cashier_p2p) {
if (
(is_p2p_enabled_success && !is_p2p_enabled && history.location.pathname === routes.cashier_p2p) ||
(tab_index === 0 && !is_p2p_enabled)
) {
history.push(routes.cashier_deposit);
}
}, [history, is_p2p_enabled, is_p2p_enabled_success]);
}, [history, is_p2p_enabled, is_p2p_enabled_success, tab_index]);

const onClickClose = () => history.push(routes.traders_hub);
const getMenuOptions = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

&__button-link {
cursor: pointer;
margin: 3.4rem auto 2.4rem 1.6rem;
margin: 3.2rem auto 2.4rem 1.6rem;

@include mobile {
margin-top: 2.4rem;
margin-left: 0;
}

Expand Down Expand Up @@ -121,6 +122,10 @@
&__wrapper {
.cashier__form-submit {
margin-top: 0;

@include mobile {
margin-top: 0.8rem;
}
}
.account-transfer-form__input {
margin-bottom: -0.8rem !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const WithdrawalVerificationEmail = observer(() => {
}
action={{
label: localize('Send email'),
onClick: verify.send,
onClick: () => verify.send(),
}}
/>
<MobileWrapper>{isCryptocurrency(client.currency) && <RecentTransaction />}</MobileWrapper>
Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/src/Components/Errors/error-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ErrorComponent = ({
return (
<PageErrorContainer
error_header={header ?? ''}
error_messages={message ? message[(message, refresh_message)] : []}
error_messages={message ? [message, refresh_message] : []}
redirect_urls={[routes.trade]}
redirect_labels={[redirect_label || localize('Refresh')]}
buttonOnClick={redirectOnClick || (() => location.reload())}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
.trade-container {
&__fieldset {
flex: 1;
margin-left: 0.4rem;

.dc-button-menu__wrapper {
height: 4rem;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { render, screen } from '@testing-library/react';
import { TContractInfo } from '@deriv/shared/src/utils/contract/contract-types';
import TurbosCardBody from '../turbos-card-body';

const contract_info: TContractInfo = {
contract_id: 1,
bid_price: 1044.02,
buy_price: 1044.0,
profit: 50,
barrier: '10904.80',
entry_spot_display_value: '1046.80',
sell_price: 1046.8,
};

const mockCardLabels = () => ({
BARRIER: 'Barrier',
CONTRACT_VALUE: 'Contract value',
ENTRY_SPOT: 'Entry spot',
TAKE_PROFIT: 'Take profit',
TOTAL_PROFIT_LOSS: 'Total profit/loss',
PURCHASE_PRICE: 'Buy price',
});

describe('TurbosCardBody', () => {
const mock_props = {
addToast: jest.fn(),
connectWithContractUpdate: jest.fn(),
contract_info,
contract_update: {
take_profit: {
display_name: 'Take profit',
order_amount: 0,
order_date: 1678948046,
},
},
currency: 'USD',
current_focus: null,
error_message_alignment: 'left',
getCardLabels: mockCardLabels,
getContractById: jest.fn(),
is_sold: false,
onMouseLeave: jest.fn(),
removeToast: jest.fn(),
setCurrentFocus: jest.fn(),
status: 'profit',
progress_slider_mobile_el: false,
};
beforeAll(() => {
(ReactDOM.createPortal as jest.Mock) = jest.fn(component => {
return component;
});
});

it('renders header and values correctly', () => {
render(<TurbosCardBody {...mock_props} />);
const buy_price_header = screen.getByText(mockCardLabels().PURCHASE_PRICE);
expect(buy_price_header).toBeInTheDocument();
const buy_price_amount = screen.getByText('1,044.00');
expect(buy_price_amount).toBeInTheDocument();

const entry_spot_header = screen.getByText(mockCardLabels().ENTRY_SPOT);
expect(entry_spot_header).toBeInTheDocument();
const entry_spot_amount = screen.getByText('1,046.80');
expect(entry_spot_amount).toBeInTheDocument();

const barrier_header = screen.getByText(mockCardLabels().BARRIER);
expect(barrier_header).toBeInTheDocument();
const barrier_level = screen.getByText('10,904.80');
expect(barrier_level).toBeInTheDocument();

const take_profit_header = screen.getByText(mockCardLabels().TAKE_PROFIT);
expect(take_profit_header).toBeInTheDocument();
const take_profit_amount = screen.getByText('-');
expect(take_profit_amount).toBeInTheDocument();

const total_profit_loss_header = screen.getByText(mockCardLabels().TOTAL_PROFIT_LOSS);
expect(total_profit_loss_header).toBeInTheDocument();
const total_profit_loss_amount = screen.getByText('50.00');
expect(total_profit_loss_amount).toBeInTheDocument();
});
});
Loading

0 comments on commit e82b1a2

Please sign in to comment.