Skip to content

Commit

Permalink
DTRA / Kate / Fix failing tests (deriv-com#17013)
Browse files Browse the repository at this point in the history
* fix: first test

* fix: another test
  • Loading branch information
kate-deriv authored Sep 30, 2024
1 parent 43a8075 commit 44b6901
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { toMoment } from '@deriv/shared';
import { getStartTime, hasForwardContractStarted, isForwardStarting, toMoment } from '@deriv/shared';
import ForwardStartingBanner from '../forward-starting-banner';

jest.mock('@deriv/shared', () => ({
...jest.requireActual('@deriv/shared'),
isForwardStarting: jest.fn(),
getStartTime: jest.fn(),
hasForwardContractStarted: jest.fn(),
}));

const mocked_date = 1727251488;
const banner_text = 'This contract starts on';
const mocked_open_positions = [
Expand Down Expand Up @@ -89,6 +96,9 @@ const mocked_props = {

describe('ForwardStartingBanner', () => {
it('should render component if it is a forward starting contract and it has not started yet', () => {
(isForwardStarting as jest.Mock).mockReturnValueOnce(true);
(hasForwardContractStarted as jest.Mock).mockReturnValueOnce(false);
(getStartTime as jest.Mock).mockReturnValueOnce(124525522);
render(<ForwardStartingBanner {...mocked_props} />);

expect(screen.getByText(banner_text)).toBeInTheDocument();
Expand Down
34 changes: 16 additions & 18 deletions packages/trader/src/AppV2/Hooks/__tests__/useOrderDetails.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { renderHook } from '@testing-library/react-hooks';
import { CONTRACT_TYPES, TContractInfo, getCardLabelsV2, mockContractInfo } from '@deriv/shared';
import {
CONTRACT_TYPES,
TContractInfo,
getCardLabelsV2,
mockContractInfo,
getStartTime,
hasForwardContractStarted,
isForwardStarting,
} from '@deriv/shared';
import useOrderDetails from '../useOrderDetails';

jest.mock('@deriv/translations', () => ({
Expand All @@ -15,13 +23,15 @@ jest.mock('@deriv/shared', () => ({
isResetContract: jest.fn(),
addComma: jest.fn(),
...jest.requireActual('@deriv/shared'),
isForwardStarting: jest.fn(),
getStartTime: jest.fn(),
hasForwardContractStarted: jest.fn(),
}));

jest.mock('App/Components/Elements/PositionsDrawer/helpers', () => ({
getBarrierValue: jest.fn(),
}));

const mocked_date = 1727251488;
const mockData: TContractInfo = mockContractInfo({
transaction_ids: { buy: 12345, sell: 67890 },
buy_price: 100,
Expand Down Expand Up @@ -78,22 +88,10 @@ describe('useOrderDetails', () => {
});

it('should return correct barriers details for Forward starting contract', () => {
const { result } = renderHook(() =>
useOrderDetails(
mockContractInfo({
contract_type: 'CALL',
date_expiry: mocked_date + 3000,
date_settlement: mocked_date + 3000,
date_start: mocked_date + 2000,
expiry_time: mocked_date + 3000,
is_forward_starting: 1,
is_sold: 0,
purchase_time: 1727096132,
shortcode: `CALL_1HZ10V_19.54_${mocked_date + 2000}F_${mocked_date + 3000}_S0P_0`,
status: 'open',
})
)
);
(isForwardStarting as jest.Mock).mockReturnValue(true);
(hasForwardContractStarted as jest.Mock).mockReturnValue(false);
(getStartTime as jest.Mock).mockReturnValue(124525522);
const { result } = renderHook(() => useOrderDetails(mockData));
expect(result.current?.details[CARD_LABELS.BARRIER]).toEqual('TBD');
});

Expand Down

0 comments on commit 44b6901

Please sign in to comment.