-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nada/p2 ps 234/buy sell ads message #8273
Merged
DerivFE
merged 11 commits into
binary-com:master
from
nada-deriv:nada/P2PS-234/buy-sell-ads-message
Sep 18, 2023
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e42b9d8
fix: change content for my-ads empty
nada-deriv a759131
fix: updated with latest master
nada-deriv 9267743
fix: pr comments fixed
nada-deriv 837852c
Merge branch 'master' into nada/P2PS-234/buy-sell-ads-message
nada-deriv 72d1d43
feat: merge conflicts fix
nada-deriv 9f1986b
feat: refactor code
nada-deriv 982b1c1
feat: added unit test, style fix
nada-deriv 57bc234
feat: reorder imports
nada-deriv 194ddb3
fix: issue with sendbird mock
nada-deriv c4875a6
fix: route to buy tab only in buy sell section
nada-deriv 80f6814
fix: failing test
nada-deriv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/p2p/src/components/buy-sell/no-ads/__tests__/no-ads.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,78 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { createBrowserHistory } from 'history'; | ||
import { Router } from 'react-router'; | ||
import NoAds from '../no-ads'; | ||
|
||
const mock_store_values = { | ||
buy_sell_store: { | ||
is_buy: true, | ||
local_currencies: [ | ||
{ | ||
text: 'USD', | ||
value: 'USD', | ||
is_default: true, | ||
}, | ||
], | ||
selected_local_currency: 'USD', | ||
setCreateSellAdFromNoAds: jest.fn(), | ||
}, | ||
general_store: { | ||
handleTabClick: jest.fn(), | ||
is_barred: false, | ||
}, | ||
my_ads_store: { | ||
setShowAdForm: jest.fn(), | ||
}, | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store_values), | ||
})); | ||
|
||
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_props = { | ||
is_ads_page: false, | ||
}; | ||
|
||
describe('<NoAds/>', () => { | ||
it('should render the component', () => { | ||
render(<NoAds />); | ||
expect(screen.getByText('No ads for this currency 😞')).toBeInTheDocument(); | ||
expect(screen.getByText('Create ad')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText('Looking to buy or sell USD? You can post your own ad for others to respond.') | ||
).toBeInTheDocument(); | ||
}); | ||
it('should display "You have no ads" when is_ads_page is true', () => { | ||
render(<NoAds {...mock_props} is_ads_page />); | ||
expect(screen.getByText('You have no ads.')).toBeInTheDocument(); | ||
expect(screen.getByText('Create new ad')).toBeInTheDocument(); | ||
}); | ||
it('should handle onclick of create ad button', () => { | ||
const history = createBrowserHistory(); | ||
render( | ||
<Router history={history}> | ||
<NoAds is_ads_page /> | ||
</Router> | ||
); | ||
const create_ad_button = screen.getByRole('button', { name: 'Create new ad' }); | ||
expect(create_ad_button).toBeInTheDocument(); | ||
create_ad_button.click(); | ||
expect(mock_store_values.buy_sell_store.setCreateSellAdFromNoAds).toHaveBeenCalledWith(true); | ||
expect(mock_store_values.general_store.handleTabClick).toHaveBeenCalledTimes(0); | ||
expect(mock_store_values.my_ads_store.setShowAdForm).toHaveBeenCalledWith(true); | ||
}); | ||
}); |
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
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
58 changes: 58 additions & 0 deletions
58
packages/p2p/src/components/my-ads/__tests__/my-ads-table.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,58 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
import MyAdsTable from '../my-ads-table'; | ||
|
||
const mock_store_values = { | ||
general_store: { | ||
setP2PConfig: jest.fn(), | ||
}, | ||
my_ads_store: { | ||
setAdverts: jest.fn(), | ||
setSelectedAdId: jest.fn(), | ||
loadMoreAds: jest.fn(), | ||
is_table_loading: false, | ||
api_error_message: null, | ||
setApiErrorCode: jest.fn(), | ||
adverts: [], | ||
}, | ||
floating_rate_store: { | ||
setChangeAdAlert: jest.fn(), | ||
}, | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store_values), | ||
})); | ||
|
||
jest.mock('../../buy-sell/no-ads', () => jest.fn(() => <div>No Ads Component</div>)); | ||
|
||
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_use_store_values = mockStore({ | ||
client: { | ||
currency: 'USD', | ||
}, | ||
}); | ||
|
||
describe('<MyAdsTable/>', () => { | ||
it('should render the NoAds component when there are no ads', () => { | ||
render( | ||
<StoreProvider store={mock_use_store_values}> | ||
<MyAdsTable /> | ||
</StoreProvider> | ||
); | ||
expect(screen.getByText('No Ads Component')).toBeInTheDocument(); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: Can we update jest.config instead? So we dont need to refactor these test files in the future 🙏