forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: filter modal refactoring, ts migration #67
Merged
farrah-deriv
merged 5 commits into
farrah-deriv:p2p-modal-test
from
nada-deriv:nada/P2PS-1093/filter-modal-refactor
Sep 20, 2023
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48da061
refactor: filter modal refactoring, ts migration
nada-deriv 9ae6bdc
refactor: test changes
nada-deriv 27c78b8
fix: review comments
nada-deriv fcfc0eb
fix: moved interval id variable to global scope
nada-deriv 49d614a
fix: removed unused localize import
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
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
62 changes: 62 additions & 0 deletions
62
...p2p/src/components/modal-manager/modals/filter-modal/__tests__/filter-modal-body.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,62 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { useStores } from 'Stores'; | ||
import FilterModalBody from '../filter-modal-body'; | ||
|
||
const mock_store_values: DeepPartial<ReturnType<typeof useStores>> = { | ||
buy_sell_store: { | ||
setShowFilterPaymentMethods: jest.fn(), | ||
setShouldUseClientLimits: jest.fn(), | ||
show_filter_payment_methods: false, | ||
should_use_client_limits: false, | ||
}, | ||
my_profile_store: { | ||
payment_methods_list_items: [ | ||
{ | ||
text: 'Skrill', | ||
value: 'skrill', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const mock_props = { | ||
onChange: jest.fn(), | ||
selected_methods: ['skrill'], | ||
selected_methods_text: ['Skrill'], | ||
setHasMadeChanges: jest.fn(), | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store_values), | ||
})); | ||
|
||
jest.mock('../filter-modal-result', () => jest.fn(() => <div>FilterModalResult</div>)); | ||
jest.mock('../filter-modal-search', () => jest.fn(() => <div>FilterModalSearch</div>)); | ||
|
||
describe('<FilterModalBody />', () => { | ||
it('should render the modal content', () => { | ||
render(<FilterModalBody {...mock_props} />); | ||
expect(screen.getByText('Payment methods')).toBeInTheDocument(); | ||
expect(screen.getByText('Matching ads')).toBeInTheDocument(); | ||
}); | ||
it('should handle onclick for payment methods section', () => { | ||
render(<FilterModalBody {...mock_props} />); | ||
userEvent.click(screen.getByText('Payment methods')); | ||
expect(mock_store_values.buy_sell_store.setShowFilterPaymentMethods).toHaveBeenCalledWith(true); | ||
}); | ||
it('should handle toggle button click', () => { | ||
render(<FilterModalBody {...mock_props} />); | ||
userEvent.click(screen.getByRole('checkbox', { name: 'matching_ads_toggler' })); | ||
expect(mock_store_values.buy_sell_store.setShouldUseClientLimits).toHaveBeenCalledWith(true); | ||
expect(mock_props.setHasMadeChanges).toHaveBeenCalledWith(true); | ||
}); | ||
it('should show the result section and search section when payment method section was already clicked', () => { | ||
mock_store_values.buy_sell_store.show_filter_payment_methods = true; | ||
render(<FilterModalBody {...mock_props} />); | ||
expect(screen.getByText('FilterModalResult')).toBeInTheDocument(); | ||
expect(screen.getByText('FilterModalSearch')).toBeInTheDocument(); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
...p/src/components/modal-manager/modals/filter-modal/__tests__/filter-modal-footer.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,62 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { useStores } from 'Stores'; | ||
import FilterModalFooter from '../filter-modal-footer'; | ||
|
||
const mock_store_values: DeepPartial<ReturnType<typeof useStores>> = { | ||
buy_sell_store: { | ||
show_filter_payment_methods: false, | ||
}, | ||
}; | ||
|
||
const mock_props = { | ||
class_name: '', | ||
has_made_changes: false, | ||
has_selected_payment_methods: false, | ||
onClickApply: jest.fn(), | ||
onClickClearPaymentMethods: jest.fn(), | ||
onClickConfirmPaymentMethods: jest.fn(), | ||
onClickReset: jest.fn(), | ||
selected_methods: ['skrill'], | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store_values), | ||
})); | ||
|
||
describe('<FilterModalFooter />', () => { | ||
it('should render the component', () => { | ||
render(<FilterModalFooter {...mock_props} />); | ||
expect(screen.getByRole('button', { name: 'Reset' })).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Apply' })).toBeInTheDocument(); | ||
}); | ||
it('should handle reset button click', () => { | ||
render(<FilterModalFooter {...mock_props} />); | ||
userEvent.click(screen.getByRole('button', { name: 'Reset' })); | ||
expect(mock_props.onClickReset).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should handle apply button click', () => { | ||
const new_props = { ...mock_props, has_made_changes: true }; | ||
|
||
render(<FilterModalFooter {...new_props} />); | ||
userEvent.click(screen.getByRole('button', { name: 'Apply' })); | ||
expect(mock_props.onClickApply).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should handle clear button click', () => { | ||
mock_store_values.buy_sell_store.show_filter_payment_methods = true; | ||
|
||
render(<FilterModalFooter {...mock_props} />); | ||
userEvent.click(screen.getByRole('button', { name: 'Clear' })); | ||
expect(mock_props.onClickClearPaymentMethods).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should handle confirm button click', () => { | ||
mock_store_values.buy_sell_store.show_filter_payment_methods = true; | ||
const new_props = { ...mock_props, has_selected_payment_methods: true }; | ||
|
||
render(<FilterModalFooter {...new_props} />); | ||
userEvent.click(screen.getByRole('button', { name: 'Confirm' })); | ||
expect(mock_props.onClickConfirmPaymentMethods).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...p/src/components/modal-manager/modals/filter-modal/__tests__/filter-modal-header.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,37 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import FilterModalHeader from '../filter-modal-header'; | ||
|
||
const mock_store = { | ||
buy_sell_store: { | ||
show_filter_payment_methods: false, | ||
}, | ||
}; | ||
|
||
const mock_props = { | ||
pageHeaderReturnFn: jest.fn(), | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store), | ||
})); | ||
|
||
describe('<FilterModalHeader />', () => { | ||
it('should render the component', () => { | ||
render(<FilterModalHeader {...mock_props} />); | ||
expect(screen.getByText('Filter')).toBeInTheDocument(); | ||
}); | ||
it('should render the component with payment methods', () => { | ||
mock_store.buy_sell_store.show_filter_payment_methods = true; | ||
render(<FilterModalHeader {...mock_props} />); | ||
expect(screen.getByText('Payment methods')).toBeInTheDocument(); | ||
}); | ||
it('should handle clicking return', () => { | ||
render(<FilterModalHeader {...mock_props} />); | ||
const return_button = screen.getByTestId('dt_page_return_icon'); | ||
userEvent.click(return_button); | ||
expect(mock_props.pageHeaderReturnFn).toHaveBeenCalled(); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
...c/components/modal-manager/modals/filter-modal/__tests__/filter-modal-no-results.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,15 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import FilterModalNoResults from '../filter-modal-no-results'; | ||
|
||
const mock_props = { | ||
text: 'test word', | ||
}; | ||
|
||
describe('<FilterModalNoResults />', () => { | ||
it('should render the component with the passed props', () => { | ||
render(<FilterModalNoResults {...mock_props} />); | ||
expect(screen.getByText('No results for "test word".')).toBeInTheDocument(); | ||
expect(screen.getByText('Check your spelling or use a different term.')).toBeInTheDocument(); | ||
}); | ||
}); |
83 changes: 83 additions & 0 deletions
83
...p/src/components/modal-manager/modals/filter-modal/__tests__/filter-modal-result.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,83 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { useStores } from 'Stores'; | ||
import FilterModalResult from '../filter-modal-result'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const mock_store_values: DeepPartial<ReturnType<typeof useStores>> = { | ||
buy_sell_store: { | ||
is_filter_modal_loading: false, | ||
}, | ||
my_profile_store: { | ||
payment_methods_list_items: [ | ||
{ | ||
text: 'Skrill', | ||
value: 'skrill', | ||
}, | ||
{ | ||
value: 'bank', | ||
text: 'Bank', | ||
}, | ||
{ | ||
value: 'upi', | ||
text: 'UPI', | ||
}, | ||
], | ||
search_results: [], | ||
search_term: '', | ||
}, | ||
}; | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store_values), | ||
})); | ||
|
||
jest.mock('@deriv/components', () => ({ | ||
...jest.requireActual('@deriv/components'), | ||
Loading: () => <div>Loading</div>, | ||
})); | ||
|
||
const mock_props = { | ||
onChange: jest.fn(), | ||
selected_methods: ['skrill'], | ||
}; | ||
|
||
describe('<FilterModalResult />', () => { | ||
it('should render the component with the passed props', () => { | ||
render(<FilterModalResult {...mock_props} />); | ||
expect(screen.getByText('Skrill')).toBeInTheDocument(); | ||
expect(screen.getByText('Bank')).toBeInTheDocument(); | ||
}); | ||
it('should handle checkbox selection', () => { | ||
render(<FilterModalResult {...mock_props} />); | ||
const checkbox = screen.getByRole('checkbox', { name: 'Skrill' }); | ||
userEvent.click(checkbox); | ||
expect(mock_props.onChange).toHaveBeenCalledWith({ text: 'Skrill', value: 'skrill' }); | ||
}); | ||
it('should show no results if search term is present and no results are found', () => { | ||
mock_store_values.my_profile_store.search_term = 'test'; | ||
render(<FilterModalResult {...mock_props} />); | ||
expect(screen.getByText('No results for "test".')).toBeInTheDocument(); | ||
}); | ||
it('should show the search results if search term is present and results are found', () => { | ||
mock_store_values.my_profile_store.search_term = 'skrill'; | ||
mock_store_values.my_profile_store.search_results = [{ text: 'Skrill', value: 'skrill' }]; | ||
render(<FilterModalResult {...mock_props} />); | ||
expect(screen.getByText('Skrill')).toBeInTheDocument(); | ||
}); | ||
it('should handle selection of search results', () => { | ||
mock_store_values.my_profile_store.search_term = 'skrill'; | ||
mock_store_values.my_profile_store.search_results = [{ text: 'Skrill', value: 'skrill' }]; | ||
render(<FilterModalResult {...mock_props} />); | ||
expect(screen.getByText('Skrill')).toBeInTheDocument(); | ||
const checkbox = screen.getByRole('checkbox', { name: 'Skrill' }); | ||
userEvent.click(checkbox); | ||
expect(mock_props.onChange).toHaveBeenCalledWith({ text: 'Skrill', value: 'skrill' }); | ||
}); | ||
it('should show the Loading indicator when in loading state', () => { | ||
mock_store_values.buy_sell_store.is_filter_modal_loading = true; | ||
render(<FilterModalResult {...mock_props} />); | ||
expect(screen.getByText('Loading')).toBeInTheDocument(); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...p/src/components/modal-manager/modals/filter-modal/__tests__/filter-modal-search.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,49 @@ | ||
import React from 'react'; | ||
import { act, render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import FilterModalSearch from '../filter-modal-search'; | ||
|
||
const mock_store = { | ||
buy_sell_store: { | ||
setIsFilterModalLoading: jest.fn(), | ||
}, | ||
my_profile_store: { | ||
getPaymentMethodsList: jest.fn(), | ||
setSearchResults: jest.fn(), | ||
setSearchTerm: jest.fn(), | ||
}, | ||
}; | ||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store), | ||
})); | ||
|
||
describe('<FilterModalSearch />', () => { | ||
it('should render the component', () => { | ||
render(<FilterModalSearch />); | ||
expect(screen.getByPlaceholderText('Search payment method')).toBeInTheDocument(); | ||
}); | ||
it('should handle search functionality', async () => { | ||
jest.useFakeTimers(); | ||
jest.spyOn(global, 'setTimeout'); | ||
render(<FilterModalSearch />); | ||
const field = screen.getByRole('textbox'); | ||
userEvent.type(field, 'test'); | ||
act(() => { | ||
jest.advanceTimersByTime(1000); | ||
}); | ||
await waitFor(() => { | ||
expect(setTimeout).toHaveBeenCalled(); | ||
}); | ||
jest.clearAllTimers(); | ||
}); | ||
it('should handle clearing search text', () => { | ||
render(<FilterModalSearch />); | ||
const field = screen.getByRole('textbox'); | ||
userEvent.type(field, 'test'); | ||
const cross_icon = screen.getByTestId('dt_filter_modal_search_icon'); | ||
userEvent.click(cross_icon); | ||
expect(field).toHaveValue(''); | ||
expect(mock_store.my_profile_store.setSearchTerm).toHaveBeenCalledWith(''); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
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:
i changed a bit here as well and fixed the typing issue for it but i dont think it'll cause any huge conflicts when we merge quick add modal as well 🙏