From 07e59fc31ef71680300628ee74c82d59ba366671 Mon Sep 17 00:00:00 2001 From: henry-deriv <118344354+henry-deriv@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:08:57 +0800 Subject: [PATCH] henry/dtra-434/fix: failing test cases on master (#10392) * fix: failing test cases on master * fix: test cases --- .../__tests__/purchase-button.spec.tsx | 7 +++--- .../Form/__tests__/form-layout.spec.tsx | 22 ++++++++++++++++--- .../Form/__tests__/screen-large.spec.tsx | 2 +- .../Containers/__tests__/purchase.spec.tsx | 14 +++++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/packages/trader/src/Modules/Trading/Components/Elements/__tests__/purchase-button.spec.tsx b/packages/trader/src/Modules/Trading/Components/Elements/__tests__/purchase-button.spec.tsx index fda406c1181a..6fbdf17615dd 100644 --- a/packages/trader/src/Modules/Trading/Components/Elements/__tests__/purchase-button.spec.tsx +++ b/packages/trader/src/Modules/Trading/Components/Elements/__tests__/purchase-button.spec.tsx @@ -79,11 +79,10 @@ describe('', () => { expect(screen.getByText(/MoneyComponent/i)).toBeInTheDocument(); }); - it('should render the button with growth rate info inside for accumulators', () => { + it('should render the button for accumulators', () => { render(); expect(screen.getByText(/Buy/i)).toBeInTheDocument(); - expect(screen.getByText(/3%/i)).toBeInTheDocument(); }); it('should render icon with specific type if is_high_low === true', () => { @@ -93,10 +92,10 @@ describe('', () => { expect(screen.getByTestId(/call_barrier/i)).toBeInTheDocument(); }); - it('should render ContractInfo for mobile if contract type is not turbos or vanillas', () => { + it('should render ContractInfo for mobile if contract type is not accumulators, turbos or vanillas', () => { (isMobile as jest.Mock).mockReturnValueOnce(true); (isDesktop as jest.Mock).mockReturnValueOnce(false); - render(); + render(); expect(screen.getByText(/ContractInfo/i)).toBeInTheDocument(); }); diff --git a/packages/trader/src/Modules/Trading/Components/Form/__tests__/form-layout.spec.tsx b/packages/trader/src/Modules/Trading/Components/Form/__tests__/form-layout.spec.tsx index 786300f73bea..aac71ab5a862 100644 --- a/packages/trader/src/Modules/Trading/Components/Form/__tests__/form-layout.spec.tsx +++ b/packages/trader/src/Modules/Trading/Components/Form/__tests__/form-layout.spec.tsx @@ -2,6 +2,8 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; import FormLayout from '../form-layout'; import Loadable from 'react-loadable'; +import TraderProviders from '../../../../../trader-providers'; +import { mockStore } from '@deriv/stores'; Loadable.preloadAll(); @@ -10,6 +12,14 @@ const mock_props = { is_trade_enabled: false, }; +const mock_store = { + common: { + current_language: 'en', + }, +}; + +const store = mockStore(mock_store); + jest.mock('@deriv/shared', () => ({ ...jest.requireActual('@deriv/shared'), isMobile: jest.fn(() => false), @@ -17,9 +27,15 @@ jest.mock('@deriv/shared', () => ({ jest.mock('../screen-large', () => jest.fn(() => 'ScreenLarge')); describe('FormLayout', () => { - it('should render the componet', () => { - render(); - + const mockedFormLayout = (mock_props: { is_market_closed: boolean; is_trade_enabled: boolean }) => { + return ( + + + + ); + }; + it('should render the component', () => { + render(mockedFormLayout(mock_props)); expect(screen.queryByText('ScreenLarge')).toBeInTheDocument(); }); }); diff --git a/packages/trader/src/Modules/Trading/Components/Form/__tests__/screen-large.spec.tsx b/packages/trader/src/Modules/Trading/Components/Form/__tests__/screen-large.spec.tsx index c209ca740d5d..e55433a5e35b 100644 --- a/packages/trader/src/Modules/Trading/Components/Form/__tests__/screen-large.spec.tsx +++ b/packages/trader/src/Modules/Trading/Components/Form/__tests__/screen-large.spec.tsx @@ -6,7 +6,7 @@ jest.mock('App/Components/Elements/ContentLoader', () => ({ ...jest.requireActual('App/Components/Elements/ContentLoader'), TradeParamsLoader: jest.fn(() => 'MockedLoader'), })); -jest.mock('../../../Containers/contract-type.jsx', () => jest.fn(() => 'MockedContractType')); +jest.mock('../../../Containers/contract-type', () => jest.fn(() => 'MockedContractType')); jest.mock('../../../Containers/purchase', () => jest.fn(() => 'MockedPurchase')); jest.mock('../../../Containers/trade-params.jsx', () => jest.fn(() => 'MockedTradeParams')); diff --git a/packages/trader/src/Modules/Trading/Containers/__tests__/purchase.spec.tsx b/packages/trader/src/Modules/Trading/Containers/__tests__/purchase.spec.tsx index ae311d5e15ea..1e2a0d93dd38 100644 --- a/packages/trader/src/Modules/Trading/Containers/__tests__/purchase.spec.tsx +++ b/packages/trader/src/Modules/Trading/Containers/__tests__/purchase.spec.tsx @@ -15,6 +15,7 @@ const default_mock_store = { is_multiplier: false, growth_rate: 0.03, has_cancellation: false, + has_open_accu_contract: false, is_purchase_enabled: false, is_turbos: false, is_vanilla: false, @@ -40,6 +41,9 @@ jest.mock('Modules/Trading/Components/Elements/purchase-fieldset', () => jest.mock('Modules/Trading/Components/Elements/purchase-buttons-overlay.jsx', () => jest.fn(() =>
PurchaseButtonsOverlay component
) ); +jest.mock('Modules/Trading/Components/Form/TradeParams/Accumulator/accumulators-sell-button', () => + jest.fn(() =>
Accu sell button
) +); describe('', () => { const mockPurchaseModal = (mocked_store: TCoreStores) => { @@ -57,7 +61,7 @@ describe('', () => { expect(screen.getAllByText(/PurchaseField component/i)).toHaveLength(2); }); - it('should render PurchaseButtonsOverlay component over PurchaseField if accumulator contract is already in active positions', () => { + it('should render Sell button if accumulator contract is already in active positions', () => { const new_mocked_store: TNewMockedProps = { ...default_mock_store, portfolio: { @@ -66,11 +70,12 @@ describe('', () => { }; new_mocked_store.modules.trade.trade_types = { ACCU: 'Accumulator Up' }; new_mocked_store.modules.trade.is_accumulator = true; + new_mocked_store.modules.trade.has_open_accu_contract = true; const mock_root_store = mockStore(new_mocked_store); render(mockPurchaseModal(mock_root_store)); - expect(screen.getByText(/PurchaseField component/i)).toBeInTheDocument(); - expect(screen.getByText(/PurchaseButtonsOverlay component/i)).toBeInTheDocument(); + expect(screen.queryByText(/PurchaseField component/i)).not.toBeInTheDocument(); + expect(screen.getByText(/accu sell button/i)).toBeInTheDocument(); }); it('should render only one PurchaseField component if it is vanilla trade type', () => { @@ -79,8 +84,7 @@ describe('', () => { new_mocked_store.modules.trade.is_vanilla = true; new_mocked_store.modules.trade.contract_type = 'vanilla'; new_mocked_store.modules.trade.trade_types = { - VANILLALONGCALL: 'Vanilla Long Call', - VANILLALONGPUT: 'Vanilla Long Put', + VANILLA: 'Vanilla Long Call', }; const mock_root_store = mockStore(new_mocked_store); render(mockPurchaseModal(mock_root_store));