forked from binary-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.
refactor: added unit test for click icon, tooltip modal
- Loading branch information
1 parent
d49f8f9
commit 2ce91d0
Showing
4 changed files
with
232 additions
and
5 deletions.
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
...nts/modal-manager/modals/ad-error-tooltip-modal/__tests__/ad-error-tooltip-modal.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,160 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
import AdErrorTooltipModal from '../ad-error-tooltip-modal'; | ||
|
||
const mock_modal_manager = { | ||
hideModal: jest.fn(), | ||
is_modal_open: true, | ||
}; | ||
|
||
jest.mock('Components/modal-manager/modal-manager-context', () => ({ | ||
...jest.requireActual('Components/modal-manager/modal-manager-context'), | ||
useModalManagerContext: jest.fn(() => mock_modal_manager), | ||
})); | ||
|
||
const mock_props = { | ||
visibility_status: [], | ||
account_currency: 'USD', | ||
remaining_amount: 100, | ||
advert_type: 'buy', | ||
}; | ||
|
||
const el_modal = document.createElement('div'); | ||
|
||
describe('<AdErrorTooltipModal />', () => { | ||
beforeAll(() => { | ||
el_modal.setAttribute('id', 'modal_root'); | ||
document.body.appendChild(el_modal); | ||
}); | ||
|
||
afterAll(() => { | ||
document.body.removeChild(el_modal); | ||
}); | ||
|
||
it('should render the component in default state', () => { | ||
render(<AdErrorTooltipModal {...mock_props} />); | ||
expect( | ||
screen.getByText('Your ad isn’t listed on Buy/Sell due to the following reason(s):') | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advert_inactive"', () => { | ||
mock_props.visibility_status = ['advert_inactive']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText('Your ads with floating rates have been deactivated. Set fixed rates to reactivate them.') | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advert_max_limit"', () => { | ||
mock_props.visibility_status = ['advert_max_limit']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText('This ad is not listed on Buy/Sell because its minimum order is higher than 0 USD.') | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advert_min_limit"', () => { | ||
mock_props.visibility_status = ['advert_min_limit']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText( | ||
'This ad is not listed on Buy/Sell because its maximum order is lower than the minimum amount you can specify for orders in your ads.' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advert_remaining"', () => { | ||
mock_props.visibility_status = ['advert_remaining']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText( | ||
'This ad is not listed on Buy/Sell because its minimum order is higher than the ad’s remaining amount (100 USD).' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advertiser_ads_paused"', () => { | ||
mock_props.visibility_status = ['advertiser_ads_paused']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText('This ad is not listed on Buy/Sell because you have paused all your ads.') | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advertiser_balance"', () => { | ||
mock_props.visibility_status = ['advertiser_balance']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText( | ||
'This ad is not listed on Buy/Sell because its minimum order is higher than your Deriv P2P available balance ( USD).' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advertiser_daily_limit"', () => { | ||
mock_props.visibility_status = ['advertiser_daily_limit']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText( | ||
'This ad is not listed on Buy/Sell because its minimum order is higher than your remaining daily limit ( USD).' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display the error message for "advertiser_temp_ban"', () => { | ||
mock_props.visibility_status = ['advertiser_temp_ban']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText( | ||
'You’re not allowed to use Deriv P2P to advertise. Please contact us via live chat for more information.' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
it('should handle the error message when there are multiple visibility statuses', () => { | ||
mock_props.visibility_status = ['advertiser_temp_ban', 'advert_inactive']; | ||
render( | ||
<StoreProvider store={mockStore({})}> | ||
<AdErrorTooltipModal {...mock_props} /> | ||
</StoreProvider> | ||
); | ||
expect( | ||
screen.getByText('Your ad isn’t listed on Buy/Sell due to the following reason(s):') | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'1. You’re not allowed to use Deriv P2P to advertise. Please contact us via live chat for more information.' | ||
) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'2. Your ads with floating rates have been deactivated. Set fixed rates to reactivate them.' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
7 changes: 3 additions & 4 deletions
7
...p2p/src/components/modal-manager/modals/ad-error-tooltip-modal/ad-error-tooltip-modal.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
63 changes: 63 additions & 0 deletions
63
packages/p2p/src/pages/my-ads/__tests__/my-ads-row-renderer.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,63 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
import { adverts } from 'Components/my-ads/__mocks__/mock-data'; | ||
import MyAdsRowRenderer from '../my-ads-row-renderer'; | ||
|
||
const mock_store = { | ||
floating_rate_store: {}, | ||
general_store: { | ||
is_listed: 0, | ||
}, | ||
my_profile_store: { | ||
getAdvertiserPaymentMethods: jest.fn(), | ||
}, | ||
my_ads_store: { | ||
selected_ad_id: '1', | ||
}, | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store), | ||
})); | ||
|
||
const mock_modal_manager_context = { | ||
hideModal: jest.fn(), | ||
showModal: jest.fn(), | ||
}; | ||
|
||
jest.mock('Components/modal-manager/modal-manager-context', () => ({ | ||
useModalManagerContext: () => mock_modal_manager_context, | ||
})); | ||
|
||
const mock_use_store_values = mockStore({ | ||
client: { | ||
currency: 'USD', | ||
}, | ||
}); | ||
|
||
describe('<MyAdsRowRenderer/>', () => { | ||
it('should display tooltip for hidden ads', () => { | ||
render( | ||
<StoreProvider store={mock_use_store_values}> | ||
<MyAdsRowRenderer row={{ ...adverts, visibility_status: ['advert_inactive'] }} /> | ||
</StoreProvider> | ||
); | ||
const icon = screen.getByTestId('dt_popover_wrapper'); | ||
expect(icon).toBeInTheDocument(); | ||
userEvent.hover(icon); | ||
expect(screen.getByText('Ad not listed')).toBeInTheDocument(); | ||
}); | ||
it('should onClick for hidden ads', () => { | ||
render( | ||
<StoreProvider store={mock_use_store_values}> | ||
<MyAdsRowRenderer row={{ ...adverts, visibility_status: ['advert_inactive'] }} /> | ||
</StoreProvider> | ||
); | ||
const visibility_status_icon = screen.getByTestId('dt_visibility_alert_icon'); | ||
userEvent.click(visibility_status_icon); | ||
expect(mock_modal_manager_context.showModal).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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