forked from deriv-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 deriv-com#33 from nada-deriv/nada/P2PS-1086/curren…
…cy-selector-refactor refactor: currency selector modal refactor
- Loading branch information
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...s/modal-manager/modals/currency-selector-modal/__tests__/currency-selector-modal.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,60 @@ | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context'; | ||
import { useStores } from 'Stores'; | ||
import CurrenySelectorModal from '../currency-selector-modal'; | ||
|
||
const mock_store: DeepPartial<ReturnType<typeof useStores>> = { | ||
buy_sell_store: { | ||
onLocalCurrencySelect: jest.fn(), | ||
selected_local_currency: 'IDR', | ||
local_currencies: [ | ||
{ display_name: 'Indonesian Rupiah', text: 'IDR', value: 'IDR', is_default: true }, | ||
{ display_name: 'New Zealand Dollar', text: 'NZD', value: 'NZD', has_adverts: true }, | ||
], | ||
}, | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: () => mock_store, | ||
})); | ||
|
||
const mock_modal_manager = { | ||
hideModal: jest.fn(), | ||
is_modal_open: true, | ||
}; | ||
|
||
jest.mock('Components/modal-manager/modal-manager-context'); | ||
const mocked_useModalManagerContext = useModalManagerContext as jest.MockedFunction< | ||
() => Partial<ReturnType<typeof useModalManagerContext>> | ||
>; | ||
|
||
mocked_useModalManagerContext.mockImplementation(() => mock_modal_manager); | ||
|
||
describe('<CurrenySelectorModal/>', () => { | ||
let modal_root_el: HTMLElement; | ||
beforeAll(() => { | ||
modal_root_el = document.createElement('div'); | ||
modal_root_el.setAttribute('id', 'modal_root'); | ||
document.body.appendChild(modal_root_el); | ||
}); | ||
|
||
afterAll(() => { | ||
document.body.removeChild(modal_root_el); | ||
}); | ||
it('should render the CurrenySelectorModal', () => { | ||
render(<CurrenySelectorModal />); | ||
|
||
expect(screen.getByText('Preferred currency')).toBeInTheDocument(); | ||
}); | ||
it('should handle currency selection', () => { | ||
render(<CurrenySelectorModal />); | ||
|
||
userEvent.click(screen.getByText('NZD')); | ||
|
||
expect(mock_store.buy_sell_store.onLocalCurrencySelect).toBeCalledWith('NZD'); | ||
expect(mock_modal_manager.hideModal).toBeCalled(); | ||
}); | ||
}); |
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
File renamed without changes.