Skip to content

Commit

Permalink
henry/dtra-434/fix: failing test cases on master (deriv-com#10392)
Browse files Browse the repository at this point in the history
* fix: failing test cases on master

* fix: test cases
  • Loading branch information
henry-deriv authored Sep 29, 2023
1 parent a028efc commit 07e59fc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ describe('<PurchaseButton />', () => {
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(<PurchaseButton {...default_mocked_props} is_accumulator type='ACCU' />);

expect(screen.getByText(/Buy/i)).toBeInTheDocument();
expect(screen.getByText(/3%/i)).toBeInTheDocument();
});

it('should render icon with specific type if is_high_low === true', () => {
Expand All @@ -93,10 +92,10 @@ describe('<PurchaseButton />', () => {
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(<PurchaseButton {...default_mocked_props} is_accumulator type='ACCU' />);
render(<PurchaseButton {...default_mocked_props} is_multiplier type='MULTUP' />);

expect(screen.getByText(/ContractInfo/i)).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -10,16 +12,30 @@ 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),
}));
jest.mock('../screen-large', () => jest.fn(() => 'ScreenLarge'));

describe('FormLayout', () => {
it('should render the componet', () => {
render(<FormLayout {...mock_props} />);

const mockedFormLayout = (mock_props: { is_market_closed: boolean; is_trade_enabled: boolean }) => {
return (
<TraderProviders store={store}>
<FormLayout {...mock_props} />
</TraderProviders>
);
};
it('should render the component', () => {
render(mockedFormLayout(mock_props));
expect(screen.queryByText('ScreenLarge')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,6 +41,9 @@ jest.mock('Modules/Trading/Components/Elements/purchase-fieldset', () =>
jest.mock('Modules/Trading/Components/Elements/purchase-buttons-overlay.jsx', () =>
jest.fn(() => <div>PurchaseButtonsOverlay component</div>)
);
jest.mock('Modules/Trading/Components/Form/TradeParams/Accumulator/accumulators-sell-button', () =>
jest.fn(() => <div>Accu sell button</div>)
);

describe('<Purchase />', () => {
const mockPurchaseModal = (mocked_store: TCoreStores) => {
Expand All @@ -57,7 +61,7 @@ describe('<Purchase />', () => {
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: {
Expand All @@ -66,11 +70,12 @@ describe('<Purchase />', () => {
};
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', () => {
Expand All @@ -79,8 +84,7 @@ describe('<Purchase />', () => {
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));
Expand Down

0 comments on commit 07e59fc

Please sign in to comment.