-
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.
- Loading branch information
1 parent
68c5db6
commit f56f129
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
packages/p2p/src/components/advertiser-page/__tests__/advertiser-page.spec.jsx
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 { render } from '@testing-library/react'; | ||
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context'; | ||
import AdvertiserPage from '../advertiser-page.jsx'; | ||
|
||
jest.mock('@sendbird/chat', () => ({ | ||
SendbirdChat: jest.fn().mockReturnValue({}), | ||
})); | ||
|
||
jest.mock('@sendbird/chat/groupChannel', () => ({ | ||
SendbirdChat: jest.fn().mockReturnValue({}), | ||
})); | ||
|
||
jest.mock('@sendbird/chat/message', () => ({ | ||
SendbirdChat: jest.fn().mockReturnValue({}), | ||
})); | ||
|
||
const mock_modal_manager = { | ||
showModal: jest.fn(), | ||
hideModal: jest.fn(), | ||
useRegisterModalProps: jest.fn(), | ||
is_modal_open: true, | ||
}; | ||
|
||
jest.mock('Components/modal-manager/modal-manager-context'); | ||
|
||
useModalManagerContext.mockImplementation(() => mock_modal_manager); | ||
|
||
const mocked_store_values = { | ||
advertiser_page_store: { | ||
advertiser_details_id: 'id1', | ||
advertiser_details_name: 'test name', | ||
counterparty_advertiser_info: { | ||
name: 'name', | ||
}, | ||
is_counterparty_advertiser_blocked: false, | ||
onMount: jest.fn(), | ||
onTabChange: jest.fn(), | ||
setIsDropdownMenuVisible: jest.fn(), | ||
onUnmount: jest.fn(), | ||
onCancel: jest.fn(), | ||
is_loading: false, | ||
info: { | ||
name: 'name', | ||
}, | ||
onAdvertiserIdUpdate: jest.fn(), | ||
}, | ||
general_store: { | ||
advertiser_id: 'id2', | ||
advertiser_info: { | ||
name: 'my name', | ||
}, | ||
}, | ||
buy_sell_store: { | ||
show_advertiser_page: true, | ||
hideAdvertiserPage: jest.fn(), | ||
setShowAdvertiserPage: jest.fn(), | ||
}, | ||
}; | ||
|
||
jest.mock('../block-user/block-user-overlay', () => jest.fn(() => <div>overlay</div>)); | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mocked_store_values), | ||
})); | ||
|
||
describe('<AdvertiserPage />', () => { | ||
it('should render advertiser page', () => { | ||
render(<AdvertiserPage />); | ||
expect(mocked_store_values.advertiser_page_store.onMount).toHaveBeenCalledTimes(1); | ||
expect(mocked_store_values.buy_sell_store.setShowAdvertiserPage).toHaveBeenCalledWith(true); | ||
}); | ||
it('should handle unmount of advertiser page', () => { | ||
const { unmount } = render(<AdvertiserPage />); | ||
unmount(); | ||
expect(mocked_store_values.advertiser_page_store.onUnmount).toHaveBeenCalledTimes(1); | ||
expect(mocked_store_values.buy_sell_store.setShowAdvertiserPage).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