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.
Maryia/BOT-755/test: test case for recent component (deriv-com#10964)
* test: recent component * fix: improve test-case * fix: refactor test * refactor: improve test case
- Loading branch information
1 parent
02af38b
commit 6c89b4d
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
...i/src/components/dashboard/dashboard-component/load-bot-preview/__tests__/recent.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,80 @@ | ||
import React from 'react'; | ||
import { mockStore, StoreProvider } from '@deriv/stores'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { render, screen } from '@testing-library/react'; | ||
import { mock_ws } from 'Utils/mock'; | ||
import RootStore from 'Stores/root-store'; | ||
import { DBotStoreProvider, mockDBotStore } from 'Stores/useDBotStore'; | ||
import RecentComponent from '../recent'; | ||
|
||
jest.mock('@deriv/shared', () => ({ | ||
...jest.requireActual('@deriv/shared'), | ||
isMobile: jest.fn(() => true), | ||
})); | ||
|
||
jest.mock('@deriv/bot-skeleton/src/scratch/blockly', () => jest.fn()); | ||
|
||
jest.mock('@deriv/bot-skeleton/src/scratch/dbot', () => ({})); | ||
|
||
jest.mock('@deriv/bot-skeleton/src/scratch/hooks/block_svg', () => jest.fn()); | ||
|
||
const dashboard_strategy = { | ||
name: '', | ||
xml: '', | ||
save_type: '', | ||
timestamp: 1, | ||
}; | ||
|
||
const dashboard_strategies = [ | ||
{ ...dashboard_strategy, name: 'Strategy1', id: '1' }, | ||
{ ...dashboard_strategy, name: 'Strategy2', id: '2' }, | ||
]; | ||
|
||
describe('RecentComponent', () => { | ||
let wrapper: ({ children }: { children: JSX.Element }) => JSX.Element, mock_DBot_store: RootStore | undefined; | ||
|
||
beforeEach(() => { | ||
const mock_store = mockStore({}); | ||
mock_DBot_store = mockDBotStore(mock_store, mock_ws); | ||
|
||
mock_DBot_store?.load_modal.setDashboardStrategies(dashboard_strategies); | ||
|
||
wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock_store}> | ||
<DBotStoreProvider ws={mock_ws} mock={mock_DBot_store}> | ||
{children} | ||
</DBotStoreProvider> | ||
</StoreProvider> | ||
); | ||
}); | ||
|
||
it('Should display the list of strategies', () => { | ||
render(<RecentComponent />, { wrapper }); | ||
|
||
const recent_сomponent = screen.getByText('Your bots:'); | ||
const strategy_one = screen.getByText('Strategy1'); | ||
const strategy_two = screen.getByText('Strategy2'); | ||
|
||
expect(recent_сomponent).toBeInTheDocument(); | ||
expect(strategy_one).toBeInTheDocument(); | ||
expect(strategy_two).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should display text size equal to "xs" when using the mobile version', () => { | ||
render(<RecentComponent />, { wrapper }); | ||
|
||
const load_strategy_label = screen.getByText('Your bots:'); | ||
|
||
expect(load_strategy_label).toBeInTheDocument(); | ||
expect(load_strategy_label).toHaveStyle('--text-size: var(--text-size-xs)'); | ||
}); | ||
|
||
it('Should not display anything if the list of strategies is empty', () => { | ||
mock_DBot_store?.load_modal.setDashboardStrategies([]); | ||
|
||
render(<RecentComponent />, { wrapper }); | ||
|
||
const recent_component = screen.queryByText('Your bots:'); | ||
expect(recent_component).not.toBeInTheDocument(); | ||
}); | ||
}); |