Skip to content

Commit

Permalink
refactor: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-deriv committed Sep 23, 2024
1 parent 57ad041 commit 3588318
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getContractDetailsConfig } from 'AppV2/Utils/contract-details-config';

jest.mock('AppV2/Hooks/useContractDetails', () => jest.fn());
jest.mock('AppV2/Hooks/useOrderDetails', () => jest.fn());
jest.mock('AppV2/Components/ForwardStartingBanner', () => jest.fn(() => <div>ForwardStartingBanner</div>));

jest.mock('AppV2/Components/ContractCard', () => {
const ContractCard = () => <div data-testid='contract-card'>ContractCard</div>;
Expand Down Expand Up @@ -179,6 +180,11 @@ describe('ContractDetails', () => {
);
};

it('should render the ForwardStartingBanner component', async () => {
await waitFor(() => renderContractDetails());
expect(screen.getByText('ForwardStartingBanner')).toBeInTheDocument();
});

it('should render the ContractCard component', async () => {
await waitFor(() => renderContractDetails());
expect(screen.getByText('ContractCard')).toBeInTheDocument();
Expand Down
21 changes: 21 additions & 0 deletions packages/trader/src/AppV2/Hooks/__tests__/useOrderDetails.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jest.mock('App/Components/Elements/PositionsDrawer/helpers', () => ({
getBarrierValue: jest.fn(),
}));

const mocked_now = Math.floor(Date.now() / 1000);
const mockData: TContractInfo = mockContractInfo({
transaction_ids: { buy: 12345, sell: 67890 },
buy_price: 100,
Expand Down Expand Up @@ -76,6 +77,26 @@ describe('useOrderDetails', () => {
});
});

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

it('should return correct details for Turbos contract', () => {
mockData.contract_type = CONTRACT_TYPES.TURBOS.LONG;
const { result } = renderHook(() => useOrderDetails(mockData));
Expand Down

0 comments on commit 3588318

Please sign in to comment.