-
Notifications
You must be signed in to change notification settings - Fork 323
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
[DTRA] Maryia/DTRA-739/Add tooltips for Take profit & Stop loss in ContractUpdateForm #13103
Changes from 14 commits
96f8bb6
d7a62a3
47570dc
c9273da
bb9498e
e73d3ab
3331b9f
19eb703
0643438
ed0c015
b6c2ce7
c85ece0
54a1a15
aedbefe
d62021c
93551e4
0079495
104793a
247068e
22275de
2011e19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ describe('MultiplierCardBody', () => { | |
setCurrentFocus: jest.fn(), | ||
should_show_cancellation_warning: false, | ||
toggleCancellationWarning: jest.fn(), | ||
totalProfit: -0.44, | ||
}; | ||
}); | ||
|
||
|
@@ -61,6 +62,7 @@ describe('MultiplierCardBody', () => { | |
}; | ||
|
||
it('should render the correct content for a Cancelled contract with Deal cancel.fee and negative Total profit/loss', () => { | ||
// @ts-expect-error Check if error is gone after migrating MultiplierCardBody to TS | ||
render(<MultiplierCardBody {...mock_props} />); | ||
|
||
testCardContent(); | ||
|
@@ -76,7 +78,7 @@ describe('MultiplierCardBody', () => { | |
mock_props.contract_info.status = 'open'; | ||
mock_props.is_sold = false; | ||
delete mock_props.contract_info.sell_price; | ||
|
||
// @ts-expect-error Check if error is gone after migrating MultiplierCardBody to TS | ||
render(<MultiplierCardBody {...mock_props} />); | ||
|
||
testCardContent(); | ||
|
@@ -91,19 +93,22 @@ describe('MultiplierCardBody', () => { | |
delete mock_props.contract_info.cancellation; | ||
delete mock_props.contract_info.sell_price; | ||
|
||
// @ts-expect-error Check if error is gone after migrating MultiplierCardBody to TS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type error about MultiplierCardBody props type appeared here after I spread the props inside it. Needs to be checked after its TS migration. |
||
render(<MultiplierCardBody {...mock_props} />); | ||
|
||
expect(screen.getByText(mock_props.getCardLabels().NOT_AVAILABLE)).toBeInTheDocument(); | ||
expect(screen.getByText(progress_slider)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render arrow indicator if the contract was sold (is_sold === true)', () => { | ||
// @ts-expect-error Check if error is gone after migrating MultiplierCardBody to TS | ||
render(<MultiplierCardBody {...mock_props} />); | ||
|
||
expect(screen.queryByTestId('dt_arrow_indicator')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render arrow indicator if the contract is not sold (is_sold === false)', () => { | ||
// @ts-expect-error Check if error is gone after migrating MultiplierCardBody to TS | ||
render(<MultiplierCardBody {...mock_props} is_sold={false} />); | ||
|
||
expect(screen.getAllByTestId('dt_arrow_indicator')).not.toHaveLength(0); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { getCardLabels } from '@deriv/shared'; | ||
import ToggleCardDialog from '../toggle-card-dialog'; | ||
|
||
const contractUpdateForm = 'ContractUpdateForm'; | ||
|
||
jest.mock('../contract-update-form', () => jest.fn(() => <div>ContractUpdateForm</div>)); | ||
jest.mock('../../../icon', () => jest.fn((props: { icon: string }) => <div>{props.icon}</div>)); | ||
|
||
describe('ToggleCardDialog', () => { | ||
const mockProps = { | ||
addToast: jest.fn(), | ||
contract_id: 1, | ||
current_focus: null, | ||
error_message_alignment: 'left', | ||
getCardLabels: () => getCardLabels(), | ||
getContractById: jest.fn(), | ||
is_valid_to_cancel: false, | ||
onMouseLeave: jest.fn(), | ||
removeToast: jest.fn(), | ||
setCurrentFocus: jest.fn(), | ||
totalProfit: 50, | ||
}; | ||
beforeAll(() => { | ||
(ReactDOM.createPortal as jest.Mock) = jest.fn(component => { | ||
return component; | ||
}); | ||
}); | ||
afterAll(() => { | ||
(ReactDOM.createPortal as jest.Mock).mockClear(); | ||
}); | ||
it('should render ContractUpdateForm when edit icon is clicked', () => { | ||
render(<ToggleCardDialog {...mockProps} />); | ||
expect(screen.queryByText(contractUpdateForm)).not.toBeInTheDocument(); | ||
const editIcon = screen.getByText('IcEdit'); | ||
userEvent.click(editIcon); | ||
expect(screen.getByText(contractUpdateForm)).toBeInTheDocument(); | ||
}); | ||
it('should not render ContractUpdateForm when edit icon is clicked if is_valid_to_cancel === true', () => { | ||
render(<ToggleCardDialog {...mockProps} is_valid_to_cancel />); | ||
expect(screen.queryByText(contractUpdateForm)).not.toBeInTheDocument(); | ||
const editIcon = screen.getByText('IcEdit'); | ||
userEvent.click(editIcon); | ||
expect(screen.queryByText(contractUpdateForm)).not.toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ const contract_info = mockContractInfo({ | |
describe('TurbosCardBody', () => { | ||
const mock_props = { | ||
addToast: jest.fn(), | ||
connectWithContractUpdate: jest.fn(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
contract_info, | ||
contract_update: { | ||
take_profit: { | ||
|
@@ -37,6 +36,7 @@ describe('TurbosCardBody', () => { | |
setCurrentFocus: jest.fn(), | ||
status: 'profit', | ||
progress_slider_mobile_el: false, | ||
totalProfit: 50, | ||
}; | ||
beforeAll(() => { | ||
(ReactDOM.createPortal as jest.Mock) = jest.fn(component => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import ArrowIndicator from '../../arrow-indicator'; | |
|
||
type TAccumulatorCardBody = { | ||
addToast: (toast_config: TToastConfig) => void; | ||
connectWithContractUpdate?: React.ComponentProps<typeof ToggleCardDialog>['connectWithContractUpdate']; | ||
contract_info: TContractInfo; | ||
contract_update?: ContractUpdate; | ||
currency: Required<TContractInfo>['currency']; | ||
|
@@ -26,26 +25,20 @@ type TAccumulatorCardBody = { | |
is_sold: boolean; | ||
onMouseLeave?: () => void; | ||
removeToast: (toast_id: string) => void; | ||
setCurrentFocus: (value: string) => void; | ||
setCurrentFocus: (value: string | null) => void; | ||
totalProfit: number; | ||
is_positions?: boolean; | ||
}; | ||
|
||
const AccumulatorCardBody = ({ | ||
addToast, | ||
connectWithContractUpdate, | ||
contract_info, | ||
contract_update, | ||
currency, | ||
current_focus, | ||
error_message_alignment, | ||
getCardLabels, | ||
getContractById, | ||
indicative, | ||
is_sold, | ||
onMouseLeave, | ||
removeToast, | ||
setCurrentFocus, | ||
is_positions, | ||
...toggle_card_dialog_props | ||
}: TAccumulatorCardBody) => { | ||
const { buy_price, profit, limit_order, sell_price } = contract_info; | ||
const { take_profit } = getLimitOrderAmount(contract_update || limit_order); | ||
|
@@ -92,17 +85,10 @@ const AccumulatorCardBody = ({ | |
{take_profit ? <Money amount={take_profit} currency={currency} /> : <strong>-</strong>} | ||
{is_valid_to_sell && ( | ||
<ToggleCardDialog | ||
addToast={addToast} | ||
connectWithContractUpdate={connectWithContractUpdate} | ||
contract_id={contract_info.contract_id} | ||
current_focus={current_focus} | ||
error_message_alignment={error_message_alignment} | ||
getCardLabels={getCardLabels} | ||
getContractById={getContractById} | ||
is_accumulator | ||
onMouseLeave={onMouseLeave} | ||
removeToast={removeToast} | ||
setCurrentFocus={setCurrentFocus} | ||
{...toggle_card_dialog_props} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm spreading all the props that are only passed through and not used in the component itself for Accumulators and Multipliers contract cards. They have been already spread in Turbos contract card. |
||
/> | ||
)} | ||
</ContractCardItem> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { isCryptocurrency, getIndicativePrice, getCurrentTick, getDisplayStatus } from '@deriv/shared'; | ||
import { isCryptocurrency, getIndicativePrice, getCurrentTick, getDisplayStatus, getTotalProfit } from '@deriv/shared'; | ||
import ContractCardItem from './contract-card-item'; | ||
import CurrencyBadge from '../../currency-badge'; | ||
import DesktopWrapper from '../../desktop-wrapper'; | ||
|
@@ -25,7 +25,6 @@ export type TContractCardBodyProps = { | |
|
||
const ContractCardBody = ({ | ||
addToast, | ||
connectWithContractUpdate, | ||
contract_info, | ||
contract_update, | ||
currency, | ||
|
@@ -68,13 +67,13 @@ const ContractCardBody = ({ | |
|
||
const toggle_card_dialog_props = { | ||
addToast, | ||
connectWithContractUpdate, | ||
current_focus, | ||
error_message_alignment, | ||
getContractById, | ||
onMouseLeave, | ||
removeToast, | ||
setCurrentFocus, | ||
totalProfit: is_multiplier && !isNaN(Number(profit)) ? getTotalProfit(contract_info) : Number(profit), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bug fix: Passing the |
||
}; | ||
|
||
let card_body; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to mock the deprecated
isMobile
in order to test the usage of ContractUpdateForm in mobile where it's rendering MobileWrapper. MobileWrapper is dependent onisMobile
.