Skip to content

Commit

Permalink
fix: reverted the component change and utilized from test case
Browse files Browse the repository at this point in the history
  • Loading branch information
farabi-deriv committed Sep 11, 2024
1 parent 24b936b commit e4f93dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ describe('<DurationUnit />', () => {
mock_DBot_store = mockDBotStore(mock_store, mock_ws);
const mock_onSubmit = jest.fn();
const initial_value = {
durationtype: 1,
durationtype: 's',
symbol: 'R_100',
tradetype: 'callput',
duration: 15,
};

wrapper = ({ children }: { children: JSX.Element }) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { Formik } from 'formik';
import { ApiHelpers } from '@deriv/bot-skeleton';
import { mockStore, StoreProvider } from '@deriv/stores';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -49,22 +48,19 @@ window.Blockly = {
},
};

let initial_value = {
durationtype: 1,
symbol: 'R_100',
tradetype: 'callput',
};

describe('<TradeType />', () => {
let wrapper: ({ children }: { children: JSX.Element }) => JSX.Element, mock_DBot_store: RootStore | undefined;

beforeEach(() => {
const mock_store = mockStore({
ui: {
is_mobile: true,
},
});
const mock_store = mockStore({});
mock_DBot_store = mockDBotStore(mock_store, mock_ws);
const mock_onSubmit = jest.fn();
const initial_value = {
durationtype: 1,
symbol: 'R_100',
tradetype: 'callput',
};

wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock_store}>
Expand Down Expand Up @@ -97,16 +93,28 @@ describe('<TradeType />', () => {
expect(autocomplete_element).toHaveDisplayValue([/Rise\/Fall/i]);
});

it('should be empty list if value not found on the first time the browser is used', async () => {
const mockAPI = ApiHelpers.instance as unknown as {
contracts_for: {
getTradeTypesForQuickStrategy: jest.Mock<string, string[]>;
};
it('should be empty list if tradetype not found on the first time the browser is used', async () => {
initial_value = {
durationtype: 1,
symbol: 'R_100',
tradetype: '',
};
if (mockAPI) {
mockAPI.contracts_for.getTradeTypesForQuickStrategy = jest.fn().mockReturnValue([]);
}
render(<TradeType />, {
wrapper,
});

const autocomplete_element = screen.getByTestId('dt_qs_tradetype');
userEvent.click(autocomplete_element);

expect(autocomplete_element).toHaveDisplayValue('');
});

it('should be empty list if symbol not found on the first time the browser is used', async () => {
initial_value = {
durationtype: 1,
symbol: '',
tradetype: '',
};
render(<TradeType />, {
wrapper,
});
Expand All @@ -117,6 +125,7 @@ describe('<TradeType />', () => {
const option_element = screen.getByText('No results found');
userEvent.click(option_element);
});

expect(autocomplete_element).toHaveDisplayValue('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const TradeTypeSelect: React.FC = () => {
setTradeTypes(trade_types);
const has_selected = trade_types?.some(trade_type => trade_type.value === selected);
if (!has_selected && trade_types?.[0]?.value !== selected) {
setFieldValue?.('tradetype', trade_types?.[0]?.value || '');
setValue('tradetype', trade_types?.[0]?.value);
setFieldValue?.('tradetype', trade_types?.[0].value || '');
setValue('tradetype', trade_types?.[0].value);
}
};
getTradeTypes();
Expand Down

0 comments on commit e4f93dd

Please sign in to comment.