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 #5 from ameerul-deriv/P2PS-899-refactor-my-profile…
…-form P2PS 899 refactor my profile form
- Loading branch information
Showing
4 changed files
with
101 additions
and
24 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/p2p/src/components/my-profile/my-profile-form/__test__/my-profile-form.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,69 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { useStores } from 'Stores/index'; | ||
import MyProfileForm from '../my-profile-form'; | ||
|
||
let mock_store: DeepPartial<ReturnType<typeof useStores>>; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store), | ||
})); | ||
|
||
jest.mock('@deriv/components', () => ({ | ||
...jest.requireActual('@deriv/components'), | ||
DesktopWrapper: jest.fn(({ children }) => children), | ||
MobileWrapper: jest.fn(({ children }) => children), | ||
MobileFullPageModal: ({ | ||
children, | ||
pageHeaderReturnFn = mock_store.setActiveTab, | ||
page_header_text = 'Ad details', | ||
}) => ( | ||
<div> | ||
{page_header_text} | ||
<button onClick={pageHeaderReturnFn}>Return</button> | ||
{children} | ||
</div> | ||
), | ||
})); | ||
|
||
describe('<MyProfileForm />', () => { | ||
beforeEach(() => { | ||
mock_store = { | ||
my_profile_store: { | ||
is_loading: false, | ||
setActiveTab: jest.fn(), | ||
}, | ||
general_store: { | ||
contact_info: '', | ||
default_advert_description: '', | ||
}, | ||
}; | ||
}); | ||
|
||
it('should render MyProfileForm component', () => { | ||
render(<MyProfileForm />); | ||
|
||
expect(screen.getAllByText('Contact details').length).toBe(2); | ||
expect(screen.getAllByText('Instructions').length).toBe(2); | ||
}); | ||
|
||
it('should render the Loading component when my_profile_store.is_loading is set to true', () => { | ||
mock_store.my_profile_store.is_loading = true; | ||
|
||
render(<MyProfileForm />); | ||
|
||
expect(screen.getByTestId('dt_initial_loader')).toBeInTheDocument(); | ||
}); | ||
|
||
it('expects the setActiveTab function to be called when return function is clicked', () => { | ||
render(<MyProfileForm />); | ||
|
||
const returnButton = screen.getByRole('button', { name: 'Return' }); | ||
userEvent.click(returnButton); | ||
|
||
expect(screen.getByText('Ad details')).toBeInTheDocument(); | ||
expect(mock_store.my_profile_store.setActiveTab).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...nents/my-profile/my-profile-form/index.js → ...nents/my-profile/my-profile-form/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 MyProfileForm from './my-profile-form.jsx'; | ||
import MyProfileForm from './my-profile-form'; | ||
import './my-profile-form.scss'; | ||
|
||
export default MyProfileForm; |
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