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.
Merge pull request #9 from ameerul-deriv/P2PS-904-refactor-remaining-…
…components Ameerul /P2PS 904 Refactor remaining components
- Loading branch information
Showing
10 changed files
with
201 additions
and
30 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/p2p/src/components/my-profile/__tests__/my-profile.spec.tsx
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,42 @@ | ||
import React from 'react'; | ||
import { screen, render } from '@testing-library/react'; | ||
import { useStores } from 'Stores/index'; | ||
import MyProfile from '../my-profile'; | ||
|
||
const mock_store: DeepPartial<ReturnType<typeof useStores>> = { | ||
my_profile_store: { | ||
error_message: '', | ||
getSettings: jest.fn(), | ||
setActiveTab: jest.fn(), | ||
setShouldShowAddPaymentMethodForm: jest.fn(), | ||
}, | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store), | ||
})); | ||
|
||
jest.mock('../my-profile-content', () => jest.fn(() => <div>MyProfileContent</div>)); | ||
jest.mock('../my-profile-stats/my-profile-details-container', () => | ||
jest.fn(() => <div>MyProfileDetailsContainer</div>) | ||
); | ||
jest.mock('../my-profile-header', () => jest.fn(() => <div>MyProfileHeader</div>)); | ||
|
||
describe('<MyProfile />', () => { | ||
it('should render MyProfile component', () => { | ||
render(<MyProfile />); | ||
|
||
expect(screen.getByText('MyProfileContent')).toBeInTheDocument(); | ||
expect(screen.getByText('MyProfileDetailsContainer')).toBeInTheDocument(); | ||
expect(screen.getByText('MyProfileHeader')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show error message if error_message has value', () => { | ||
mock_store.my_profile_store.error_message = 'test error'; | ||
|
||
render(<MyProfile />); | ||
|
||
expect(screen.getByText('test error')).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
2 changes: 1 addition & 1 deletion
2
...es/p2p/src/components/my-profile/index.js → ...es/p2p/src/components/my-profile/index.ts
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import MyProfile from './my-profile.jsx'; | ||
import MyProfile from './my-profile'; | ||
import './my-profile.scss'; | ||
|
||
export default MyProfile; |
123 changes: 123 additions & 0 deletions
123
...es/p2p/src/components/my-profile/my-profile-content/__tests__/my-profile-content.spec.tsx
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,123 @@ | ||
import React from 'react'; | ||
import { screen, render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { my_profile_tabs } from 'Constants/my-profile-tabs'; | ||
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context'; | ||
import { useStores } from 'Stores/index'; | ||
import MyProfileContent from '../my-profile-content'; | ||
|
||
const mock_modal_manager: DeepPartial<ReturnType<typeof useModalManagerContext>> = { | ||
showModal: jest.fn(), | ||
}; | ||
|
||
let mock_store: DeepPartial<ReturnType<typeof useStores>>; | ||
|
||
jest.mock('@deriv/components', () => ({ | ||
...jest.requireActual('@deriv/components'), | ||
MobileWrapper: jest.fn(({ children }) => children), | ||
})); | ||
|
||
jest.mock('Components/modal-manager/modal-manager-context', () => ({ | ||
...jest.requireActual('Components/modal-manager/modal-manager-context'), | ||
useModalManagerContext: jest.fn(() => mock_modal_manager), | ||
})); | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store), | ||
})); | ||
|
||
jest.mock('../../my-profile-form', () => jest.fn(() => <div>MyProfileForm</div>)); | ||
jest.mock('../../my-profile-stats', () => jest.fn(() => <div>MyProfileStats</div>)); | ||
jest.mock('../../payment-methods', () => jest.fn(() => <div>PaymentMethods</div>)); | ||
jest.mock('../../block-user', () => jest.fn(() => <div>BlockUser</div>)); | ||
|
||
describe('<MyProfileContent />', () => { | ||
beforeEach(() => { | ||
mock_store = { | ||
general_store: { | ||
is_form_modified: false, | ||
}, | ||
my_profile_store: { | ||
active_tab: my_profile_tabs.MY_STATS, | ||
hideAddPaymentMethodForm: jest.fn(), | ||
selected_payment_method: 'alipay', | ||
setShouldShowEditPaymentMethodForm: jest.fn(), | ||
should_show_add_payment_method_form: false, | ||
should_show_edit_payment_method_form: false, | ||
}, | ||
}; | ||
}); | ||
|
||
it('should render MyProfileStats if active_tab is MY_STATS', () => { | ||
render(<MyProfileContent />); | ||
|
||
expect(screen.getByText('MyProfileStats')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render MyProfileForm if active_tab is AD_TEMPLATE', () => { | ||
mock_store.my_profile_store.active_tab = my_profile_tabs.AD_TEMPLATE; | ||
|
||
render(<MyProfileContent />); | ||
|
||
expect(screen.getByText('MyProfileForm')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render BlockUser if active_tab is MY_COUNTERPARTIES', () => { | ||
mock_store.my_profile_store.active_tab = my_profile_tabs.MY_COUNTERPARTIES; | ||
|
||
render(<MyProfileContent />); | ||
|
||
expect(screen.getByText('BlockUser')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render PaymentMethods if active_tab is PAYMENT_METHODS', () => { | ||
mock_store.my_profile_store.active_tab = my_profile_tabs.PAYMENT_METHODS; | ||
|
||
render(<MyProfileContent />); | ||
|
||
expect(screen.getAllByText('PaymentMethods').length).toBe(2); | ||
}); | ||
|
||
it('should call hideAddPaymentMethodForm and setShouldShowEditPaymentMethodForm when clicking return icon', () => { | ||
mock_store.my_profile_store.selected_payment_method = ''; | ||
mock_store.my_profile_store.active_tab = my_profile_tabs.PAYMENT_METHODS; | ||
|
||
render(<MyProfileContent />); | ||
|
||
const pageReturnIcon = screen.getByTestId('dt_mobile_full_page_return_icon'); | ||
|
||
userEvent.click(pageReturnIcon); | ||
|
||
expect(mock_store.my_profile_store.hideAddPaymentMethodForm).toBeCalled(); | ||
expect(mock_store.my_profile_store.setShouldShowEditPaymentMethodForm).toBeCalledWith(false); | ||
}); | ||
|
||
it('should call showModal with CancelAddPaymentMethodModal if is_form_modified is true and should_show_add_payment_method_form is true', () => { | ||
mock_store.my_profile_store.active_tab = my_profile_tabs.PAYMENT_METHODS; | ||
mock_store.general_store.is_form_modified = true; | ||
mock_store.my_profile_store.should_show_add_payment_method_form = true; | ||
|
||
render(<MyProfileContent />); | ||
|
||
const pageReturnIcon = screen.getByTestId('dt_mobile_full_page_return_icon'); | ||
|
||
userEvent.click(pageReturnIcon); | ||
|
||
expect(mock_modal_manager.showModal).toBeCalledWith({ key: 'CancelAddPaymentMethodModal' }); | ||
}); | ||
|
||
it('should call showModal with CancelEditPaymentMethodModal if is_form_modified is true and should_show_edit_payment_method_form is true', () => { | ||
mock_store.my_profile_store.active_tab = my_profile_tabs.PAYMENT_METHODS; | ||
mock_store.general_store.is_form_modified = true; | ||
mock_store.my_profile_store.should_show_edit_payment_method_form = true; | ||
|
||
render(<MyProfileContent />); | ||
|
||
const pageReturnIcon = screen.getByTestId('dt_mobile_full_page_return_icon'); | ||
|
||
userEvent.click(pageReturnIcon); | ||
|
||
expect(mock_modal_manager.showModal).toBeCalledWith({ key: 'CancelEditPaymentMethodModal' }); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/p2p/src/components/my-profile/my-profile-content/index.ts
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,3 @@ | ||
import MyProfileContent from './my-profile-content'; | ||
|
||
export default MyProfileContent; |
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
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
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