Skip to content

Commit

Permalink
fix: added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nada-deriv committed Aug 4, 2023
1 parent 68c5db6 commit f56f129
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import BuySell from '../buy-sell';
const mock_store = {
general_store: {
should_show_popup: false,
setActiveIndex: jest.fn(),
active_index: 1,
},
buy_sell_store: {
registerIsListedReaction: jest.fn(),
Expand Down Expand Up @@ -37,6 +39,10 @@ jest.mock('@sendbird/chat/message', () => ({
}));

describe('<BuySellPage/>', () => {
it('should render the buy/sell page', () => {
render(<BuySell />);
expect(mock_store.general_store.setActiveIndex).toHaveBeenCalledWith(0);
});
it('should render Verification Section when user is not verified', () => {
render(<BuySell />);

Expand Down

0 comments on commit f56f129

Please sign in to comment.