forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Farabi/bot 399/hide bot too risky modal (deriv-com#9542)
* fix: removed bot too risky modal and updated stop icon * fix: added toast notification when user stops bot * fix: fixed snack bar for quick strategy run * fix: added close function on snackbar * fix: added clear and reset timeout on hovering on toast * fix: added test case for bot-stop-notification * fix: stop bot snack bar appearing with no trade again
- Loading branch information
1 parent
9e693c1
commit 363cb71
Showing
14 changed files
with
235 additions
and
103 deletions.
There are no files selected for viewing
10 changes: 0 additions & 10 deletions
10
packages/bot-web-ui/src/components/dashboard/bot-builder/toolbar/run-strategy.tsx
This file was deleted.
Oops, something went wrong.
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
101 changes: 101 additions & 0 deletions
101
packages/bot-web-ui/src/components/dashboard/bot-stop-notifiaction.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,101 @@ | ||
import React from 'react'; | ||
import { mockStore, StoreProvider } from '@deriv/stores'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { act, fireEvent, render, screen } from '@testing-library/react'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import userEvent from '@testing-library/user-event'; | ||
import RootStore from 'Stores/index'; | ||
import { DBotStoreProvider, mockDBotStore } from 'Stores/useDBotStore'; | ||
import BotStopNotification from './bot-stop-notification'; | ||
|
||
jest.mock('@deriv/bot-skeleton/src/scratch/blockly', () => jest.fn()); | ||
jest.mock('@deriv/bot-skeleton/src/scratch/dbot', () => ({ | ||
saveRecentWorkspace: jest.fn(), | ||
unHighlightAllBlocks: jest.fn(), | ||
})); | ||
jest.mock('@deriv/bot-skeleton/src/scratch/hooks/block_svg', () => jest.fn()); | ||
|
||
const mock_ws = { | ||
authorized: { | ||
subscribeProposalOpenContract: jest.fn(), | ||
send: jest.fn(), | ||
}, | ||
storage: { | ||
send: jest.fn(), | ||
}, | ||
contractUpdate: jest.fn(), | ||
subscribeTicksHistory: jest.fn(), | ||
forgetStream: jest.fn(), | ||
activeSymbols: jest.fn(), | ||
send: jest.fn(), | ||
}; | ||
describe('BotStopNotification', () => { | ||
let wrapper: ({ children }: { children: JSX.Element }) => JSX.Element, mock_DBot_store: RootStore | undefined; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
const mock_store = mockStore({}); | ||
mock_DBot_store = mockDBotStore(mock_store, mock_ws); | ||
|
||
wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock_store}> | ||
<DBotStoreProvider ws={mock_ws} mock={mock_DBot_store}> | ||
{children} | ||
</DBotStoreProvider> | ||
</StoreProvider> | ||
); | ||
}); | ||
|
||
it('should clear the notification timer and hide message after timer expires', () => { | ||
act(() => { | ||
mock_DBot_store?.run_panel.setShowBotStopMessage(false); | ||
}); | ||
jest.useFakeTimers(); | ||
|
||
render(<BotStopNotification />, { | ||
wrapper, | ||
}); | ||
|
||
// Advance timers to trigger notificationTimer | ||
jest.advanceTimersByTime(6000); | ||
|
||
// Expect that setShowBotStopMessage(false) was called | ||
expect(screen.queryByText('You’ve just stopped the bot.')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the toast component', () => { | ||
const { container } = render(<BotStopNotification />, { | ||
wrapper, | ||
}); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render to remove the toast component when clicking on close icon', () => { | ||
act(() => { | ||
mock_DBot_store?.run_panel.setShowBotStopMessage(false); | ||
}); | ||
|
||
render(<BotStopNotification />, { | ||
wrapper, | ||
}); | ||
userEvent.click(screen.getByTestId('notification-close')); | ||
expect(screen.queryByText('You’ve just stopped the bot.')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render toast', () => { | ||
act(() => { | ||
mock_DBot_store?.run_panel.setShowBotStopMessage(true); | ||
}); | ||
|
||
render(<BotStopNotification />, { | ||
wrapper, | ||
}); | ||
fireEvent.mouseOver(screen.getByTestId('bot-stop-notification')); | ||
jest.advanceTimersByTime(6000); | ||
expect(screen.queryByText('You’ve just stopped the bot.')).not.toBeInTheDocument(); | ||
|
||
fireEvent.mouseLeave(screen.getByTestId('bot-stop-notification')); | ||
jest.advanceTimersByTime(4000); | ||
expect(screen.queryByText('You’ve just stopped the bot.')).not.toBeInTheDocument(); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
packages/bot-web-ui/src/components/dashboard/bot-stop-notification.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,61 @@ | ||
import React, { useRef } from 'react'; | ||
import { observer } from 'mobx-react'; | ||
import { Icon, Toast } from '@deriv/components'; | ||
import { Localize } from '@deriv/translations'; | ||
import { useDBotStore } from 'Stores/useDBotStore'; | ||
|
||
const BotStopNotification = observer(() => { | ||
const { run_panel } = useDBotStore(); | ||
const { setShowBotStopMessage } = run_panel; | ||
const notification_timer = useRef(6000); | ||
|
||
const notificationTimer = setTimeout(() => { | ||
if (notification_timer.current) { | ||
setShowBotStopMessage(false); | ||
} | ||
}, notification_timer.current); | ||
|
||
const resetTimer = () => { | ||
setTimeout(() => { | ||
setShowBotStopMessage(false); | ||
}, 4000); | ||
}; | ||
|
||
return ( | ||
<div | ||
className='bot-stop-notification' | ||
onMouseOver={e => { | ||
clearTimeout(notificationTimer); | ||
}} | ||
onMouseLeave={e => { | ||
resetTimer(); | ||
}} | ||
data-testid='bot-stop-notification' | ||
> | ||
<Toast> | ||
<div> | ||
<Localize | ||
i18n_default_text='You’ve just stopped the bot. Any open contracts can be viewed on the <0>Reports</0> page.' | ||
components={[ | ||
<a | ||
key={0} | ||
style={{ color: 'var(--general-main-1)' }} | ||
rel='noopener noreferrer' | ||
target='_blank' | ||
href={'/reports'} | ||
/>, | ||
]} | ||
/> | ||
</div> | ||
<Icon | ||
icon='IcCross' | ||
className={'notification-close'} | ||
data_testid={'notification-close'} | ||
onClick={() => setShowBotStopMessage(false)} | ||
/> | ||
</Toast> | ||
</div> | ||
); | ||
}); | ||
|
||
export default BotStopNotification; |
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
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
Oops, something went wrong.