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.
[DTRA] Farhan/WEBREL-56/tTest coverage: app.tsx + init-store.ts in Tr…
…ader package (deriv-com#14130) * chore: test cases for app.tsx and init-store * refactor: variable names * refactor: update mock store
- Loading branch information
1 parent
419d100
commit 11c06a1
Showing
2 changed files
with
148 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import App from '../app'; | ||
import { mockStore } from '@deriv/stores'; | ||
import moment from 'moment'; | ||
|
||
const rootStore = mockStore({ | ||
common: { | ||
server_time: moment(new Date()).utc(), | ||
}, | ||
client: { | ||
is_landing_company_loaded: true, | ||
is_logged_in: false, | ||
}, | ||
modules: { | ||
cashier: { | ||
general_store: { | ||
onMountCommon: jest.fn(), | ||
setAccountSwitchListener: jest.fn(), | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const mockWs = { | ||
activeSymbols: jest.fn(), | ||
authorized: { | ||
activeSymbols: jest.fn(), | ||
subscribeProposalOpenContract: jest.fn(), | ||
send: jest.fn(), | ||
}, | ||
buy: jest.fn(), | ||
storage: { | ||
contractsFor: jest.fn(), | ||
send: jest.fn(), | ||
}, | ||
contractUpdate: jest.fn(), | ||
contractUpdateHistory: jest.fn(), | ||
subscribeTicksHistory: jest.fn(), | ||
forgetStream: jest.fn(), | ||
forget: jest.fn(), | ||
forgetAll: jest.fn(), | ||
send: jest.fn(), | ||
subscribeProposal: jest.fn(), | ||
subscribeTicks: jest.fn(), | ||
time: jest.fn(), | ||
tradingTimes: jest.fn(), | ||
wait: jest.fn(), | ||
}; | ||
|
||
jest.mock('App/Containers/Routes/routes', () => jest.fn(() => <div>Router</div>)); | ||
jest.mock('App/Containers/trade-footer-extensions', () => jest.fn(() => <div>TradeFooterExtensions</div>)); | ||
|
||
describe('App', () => { | ||
it('should render the app component', () => { | ||
const { container } = render( | ||
<App | ||
passthrough={{ | ||
root_store: rootStore, | ||
WS: mockWs, | ||
}} | ||
/> | ||
); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call setPromptHandler on unmount', () => { | ||
const setPromptHandler = jest.fn(); | ||
rootStore.ui.setPromptHandler = setPromptHandler; | ||
const { unmount } = render( | ||
<App | ||
passthrough={{ | ||
root_store: rootStore, | ||
WS: mockWs, | ||
}} | ||
/> | ||
); | ||
unmount(); | ||
expect(setPromptHandler).toHaveBeenCalledWith(false); | ||
}); | ||
}); |
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,67 @@ | ||
import { setWebsocket } from '@deriv/shared'; | ||
import { mockStore } from '@deriv/stores'; | ||
import initStore from 'App/init-store'; | ||
|
||
const mockWs = { | ||
activeSymbols: jest.fn(), | ||
authorized: { | ||
activeSymbols: jest.fn(), | ||
subscribeProposalOpenContract: jest.fn(), | ||
send: jest.fn(), | ||
}, | ||
buy: jest.fn(), | ||
storage: { | ||
contractsFor: jest.fn(), | ||
send: jest.fn(), | ||
}, | ||
contractUpdate: jest.fn(), | ||
contractUpdateHistory: jest.fn(), | ||
subscribeTicksHistory: jest.fn(), | ||
forgetStream: jest.fn(), | ||
forget: jest.fn(), | ||
forgetAll: jest.fn(), | ||
send: jest.fn(), | ||
subscribeProposal: jest.fn(), | ||
subscribeTicks: jest.fn(), | ||
time: jest.fn(), | ||
tradingTimes: jest.fn(), | ||
wait: jest.fn(), | ||
}; | ||
|
||
jest.mock('@deriv/shared', () => ({ | ||
...jest.requireActual('@deriv/shared'), | ||
setWebsocket: jest.fn(), | ||
})); | ||
|
||
describe('initStore', () => { | ||
const rootStore = mockStore({}); | ||
|
||
it('should return the root store', () => { | ||
const result = initStore(rootStore, mockWs); | ||
expect(result).toBeDefined(); | ||
expect(Object.keys(result)).toEqual([ | ||
'client', | ||
'common', | ||
'modules', | ||
'ui', | ||
'gtm', | ||
'notifications', | ||
'contract_replay', | ||
'contract_trade', | ||
'portfolio', | ||
'chart_barrier_store', | ||
'active_symbols', | ||
]); | ||
}); | ||
|
||
it('should set the websocket', () => { | ||
initStore(rootStore, mockWs); | ||
expect(setWebsocket).toHaveBeenCalledWith(mockWs); | ||
}); | ||
|
||
it('should return the same store if it already exists', () => { | ||
const result1 = initStore(rootStore, mockWs); | ||
const result2 = initStore(rootStore, mockWs); | ||
expect(result1).toBe(result2); | ||
}); | ||
}); |