Skip to content

Commit

Permalink
refactor: chnage selecting title logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-deriv committed Oct 17, 2024
1 parent 25fdfe6 commit 8e46efa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@ describe('TakeProfitHistory component', () => {
expect(container).toBeEmptyDOMElement();
});

it('renders correct History title for both TP and Sl', () => {
render(<TakeProfitHistory history={mockHistory.slice(0, 4)} />);
it('renders correct History title for both TP and Sl if is_multiplier === true', () => {
render(<TakeProfitHistory history={mockHistory.slice(0, 4)} is_multiplier={true} />);
expect(screen.getByText('TP & SL history')).toBeInTheDocument();
});

it('renders correct History title for TP', () => {
it('renders correct History title for TP if is_multiplier !== true ', () => {
render(<TakeProfitHistory history={mockHistory.slice(0, 3)} />);
expect(screen.getByText('TP history')).toBeInTheDocument();
});

it('renders correct History title for SL', () => {
render(<TakeProfitHistory history={[mockHistory[3]]} />);
expect(screen.getByText('SL history')).toBeInTheDocument();
});

it('renders the correct number of history items', () => {
render(<TakeProfitHistory history={mockHistory.slice(0, 4)} currency='USD' />);
expect(screen.getAllByText(/Test Item/)).toHaveLength(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,25 @@ type THistory = TContractStore['contract_update_history'];
type TContractHistory = {
currency?: string;
history?: [] | THistory;
is_multiplier?: boolean;
};

type TPagination = {
currentPage: number;
totalPageCount: number;
};

const TakeProfitHistory = ({ history = [], currency }: TContractHistory) => {
const TakeProfitHistory = ({ history = [], currency, is_multiplier }: TContractHistory) => {
const [current_page, setCurrentPage] = useState(0);
const items_per_page = 4;
const total_pages = Math.ceil(history.length / items_per_page);
const has_tp = history.some(item => item.order_type === 'take_profit' || item.display_name === 'Take profit');
const has_sl = history.some(item => item.order_type === 'stop_loss' || item.display_name === 'Stop loss');

const handlePageChange = React.useCallback((pagination: TPagination) => {
setCurrentPage(pagination.currentPage - 1);
}, []);

const getHistoryTitle = () => {
if (has_tp && has_sl) return <Localize i18n_default_text='TP & SL history' />;
if (has_tp) return <Localize i18n_default_text='TP history' />;
if (has_sl) return <Localize i18n_default_text='SL history' />;
};
const getHistoryTitle = () =>
is_multiplier ? <Localize i18n_default_text='TP & SL history' /> : <Localize i18n_default_text='TP history' />;

if (!history.length) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const ContractDetails = observer(() => {
<PayoutInfo contract_info={contract_info} />
<EntryExitDetails contract_info={contract_info} />
{isTpHistoryVisible && update_history.length > 0 && (
<TakeProfitHistory history={update_history} currency={currency} />
<TakeProfitHistory history={update_history} currency={currency} is_multiplier={isMultiplier} />
)}
</div>
{shouldShowSell && <ContractDetailsFooter contract_info={contract_info} />}
Expand Down

0 comments on commit 8e46efa

Please sign in to comment.