-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BOT] feature/server-side-bot (#15701)
* [BOT] [Experemental]Maryia/bot-1230/feat: ui server-side bot MVP (#12985) * feat: add new Bot UI * feat: form for server side bot * feat: implement new UI with components * feat: add interface, type, etc for server side bot * chore: organize/sort files in a new way as in the master branch(2) * feat: ui bot list * refactor: move methods to the class, add ts * chore: fix sonar cloud code smell * feat: add api calls start_bot, stop_bot * feat: add @deriv/hooks to package.json * feat: notify bot * fix: comment setItem() * feat: apply handle submit for qs server side form, fix bugs, apply ts * feat: handle notification messages * refactor: naming * chore: resolve conflicts (part2) * chore: resolve conflicts (part3) * chore: resolve conflicts (part4) * chore: resolve conflicts (part5) * chore: revert a file * chore: revert a file * chore: revert a file * [BOT] [Server Side Bot]maryia/bot 1913/Test link bug fixing and improvements (#15719) * fix: integrate a toggle button which will switch to stop if the bot is running * feat: make available bot subscription after reloading the page * feat: 🔥 fixing server side bot bugs and ui issues * feat: 🔥 server side bot improvements after api update * fix: 🔥 style fix * fix: 🔥 fixing style issues * Feature/server side bot (#16067) * feat: 🔥 fixing server side bot bugs and ui issues * feat: 🔥 server side bot improvements after api update * fix: 🔥 style fix * fix: 🔥 fixing style issues * feat: removed dvh and added exceptions for temporary consoles * feat: 🔥 added mobile/desktop UI for server side bot * feat: server side bot adding functionalities * feat: 🔥 server bot journal implementation * fix: login and server bot (#16259) * feat: 🔥 working on journal/summary * chore: name validation and stop bot issue (#16273) * feat: 🚧 added performance, made minor improvements * feat: 🚧 fixed summary and made mobile improvements * feat: 🚧 tracking bot subscriptions * refactor: 🚧 fixed sonar cloud warnings * feat: 🚧 added download and reset feature * fix: server side bot test cases (#16289) * feat: ✨ added country check * feat: ✨ Cleanup and updated content messages * chore: 🧪 improved test coverage variables * refactor: remove extra line breaks * refactor: replace small localize with big Localize * refactor: replace small localize with big Localize * feat: 🚧 nit picks and file renaming * chore: 🔥 indentation and eslint suggestions * chore: 🔥 cleanup consoles --------- Co-authored-by: maryia-matskevich-deriv <103181650+maryia-matskevich-deriv@users.noreply.github.com> Co-authored-by: rupato-deriv <97010868+rupato-deriv@users.noreply.github.com> Co-authored-by: Shafin Al Karim <129021108+shafin-deriv@users.noreply.github.com> Co-authored-by: Farabi <102643568+farabi-deriv@users.noreply.github.com> Co-authored-by: Maryia <103177211+maryia-deriv@users.noreply.github.com>
- Loading branch information
1 parent
da24792
commit 9991e86
Showing
67 changed files
with
6,204 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
229 changes: 229 additions & 0 deletions
229
packages/bot-web-ui/src/pages/server-side-bot/add-bot/__tests__/add-bot.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
import React from 'react'; | ||
import { mockStore, StoreProvider } from '@deriv/stores'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import { mock_ws } from 'Utils/mock'; | ||
import { DBotStoreProvider, mockDBotStore } from 'Stores/useDBotStore'; | ||
import AddBot from '../add-bot'; | ||
|
||
jest.mock('@deriv/bot-skeleton/src/scratch/blockly', () => jest.fn()); | ||
jest.mock('@deriv/bot-skeleton/src/scratch/dbot', () => jest.fn()); | ||
jest.mock('@deriv/bot-skeleton/src/scratch/hooks/block_svg', () => jest.fn()); | ||
|
||
jest.mock('@deriv/components', () => ({ | ||
...jest.requireActual('@deriv/components'), | ||
Modal: ({ children, is_open }: { children: JSX.Element; is_open: boolean }) => is_open && <div>{children}</div>, | ||
})); | ||
|
||
jest.mock('@deriv/bot-skeleton', () => ({ | ||
...jest.requireActual('@deriv/bot-skeleton'), | ||
ApiHelpers: { | ||
instance: { | ||
contracts_for: { | ||
getDurations: () => [ | ||
{ | ||
display: 'Ticks', | ||
unit: 't', | ||
min: 1, | ||
max: 10, | ||
}, | ||
{ | ||
display: 'sample', | ||
unit: 's', | ||
min: 10, | ||
max: 20, | ||
}, | ||
], | ||
getMarketBySymbol: jest.fn(), | ||
getSubmarketBySymbol: jest.fn(), | ||
getTradeTypeCategoryByTradeType: jest.fn(), | ||
getTradeTypesForQuickStrategy: () => [ | ||
{ | ||
text: 'Rise/Fall', | ||
value: 'callput', | ||
group: 'Up/Down', | ||
icon: ['CALL', 'PUT'], | ||
}, | ||
{ | ||
text: 'Rise Equals/Fall Equals', | ||
value: 'callputequal', | ||
group: 'Up/Down', | ||
icon: ['CALLE', 'PUTE'], | ||
}, | ||
], | ||
}, | ||
active_symbols: { | ||
getSymbolsForBot: () => [ | ||
{ | ||
text: 'AUD Basket', | ||
value: 'WLDAUD', | ||
group: 'Forex Basket', | ||
}, | ||
{ | ||
text: 'Bear Market Index', | ||
value: 'RDBULL', | ||
group: 'Daily Reset Indices', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
config: { | ||
...jest.requireActual('@deriv/bot-skeleton').config, | ||
QUICK_STRATEGY: { | ||
DISABLED: { | ||
SYMBOLS: ['1HZ150V', '1HZ250V'], | ||
SUBMARKETS: ['crash_index', 'non_stable_coin'], | ||
}, | ||
DEFAULT: { | ||
symbol: '1HZ100V', | ||
tradetype: 'callput', | ||
durationtype: 't', | ||
size: 2, | ||
unit: 1, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
jest.mock('../../../../xml/martingale.xml', () => ''); | ||
|
||
window.Blockly = { | ||
Xml: { | ||
textToDom: jest.fn(), | ||
domToText: jest.fn(), | ||
}, | ||
utils: { | ||
xml: { textToDom: jest.fn() }, | ||
}, | ||
}; | ||
|
||
jest.mock('../config', () => ({ | ||
...jest.requireActual('../config'), | ||
STRATEGIES: { | ||
MARTINGALE: { | ||
name: 'martingale', | ||
label: 'martingale', | ||
description: 'martingale', | ||
fields: [ | ||
[ | ||
{ | ||
type: 'symbol', | ||
name: 'symbol', | ||
}, | ||
{ | ||
type: 'tradetype', | ||
name: 'tradetype', | ||
dependencies: ['symbol'], | ||
}, | ||
{ | ||
type: 'durationtype', | ||
name: 'durationtype', | ||
dependencies: ['symbol', 'tradetype'], | ||
attached: true, | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'duration', | ||
validation: ['required', 'number', 'floor', 'min', 'max'], | ||
}, | ||
{ | ||
type: 'duration', | ||
name: 'duration', | ||
validation: ['required', 'number', 'floor', 'min', 'max'], | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'size', | ||
validation: ['required'], | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'profit', | ||
validation: ['number', 'ceil'], | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'loss', | ||
validation: [ | ||
'number', | ||
{ | ||
type: 'max', | ||
value: 10, | ||
getMessage: () => 'some message', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'label', | ||
label: 'Duration', | ||
description: 'The trade length of your purchased contract.', | ||
hide: ['desktop'], | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'last_digit_prediction', | ||
validation: ['number', 'integer'], | ||
should_have: [{ key: 'symbol', value: 'WLDAUD' }], | ||
hide_without_should_have: true, | ||
}, | ||
{ | ||
type: 'number', | ||
name: 'max_stake', | ||
validation: ['number', 'integer'], | ||
should_have: [{ key: 'symbol', value: '', multiple: ['WLDAUD'] }], | ||
hide_without_should_have: true, | ||
}, | ||
], | ||
[], | ||
], | ||
}, | ||
}, | ||
})); | ||
|
||
describe('<QuickStrategy />', () => { | ||
let wrapper: ({ children }: { children: JSX.Element }) => JSX.Element; | ||
let mock_store = mockStore({ | ||
ui: { | ||
is_mobile: true, | ||
}, | ||
}); | ||
const mock_dbot_store = mockDBotStore(mock_store, mock_ws); | ||
|
||
beforeEach(() => { | ||
mock_dbot_store?.quick_strategy?.setValue('durationtype', 't'); | ||
mock_dbot_store?.quick_strategy?.setSelectedStrategy('MARTINGALE'); | ||
mock_dbot_store?.quick_strategy?.setFormVisibility(true); | ||
wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock_store}> | ||
<DBotStoreProvider ws={mock_ws} mock={mock_dbot_store}> | ||
{children} | ||
</DBotStoreProvider> | ||
</StoreProvider> | ||
); | ||
}); | ||
|
||
it('should render QuickStrategy', async () => { | ||
const mock_setVisibility = jest.fn(); | ||
const is_open = false; | ||
const { container } = render(<AddBot setFormVisibility={mock_setVisibility} is_open={is_open} />, { | ||
wrapper, | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('It should render desktop', () => { | ||
mock_store = mockStore({ | ||
ui: { | ||
is_mobile: false, | ||
}, | ||
}); | ||
const mock_setVisibility = jest.fn(); | ||
const is_open = false; | ||
render(<AddBot setFormVisibility={mock_setVisibility} is_open={is_open} />, { | ||
wrapper, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.