-
-
Notifications
You must be signed in to change notification settings - Fork 696
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
Add current page parameter to the route in the listing and search block pagination #4159
Merged
Merged
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
deb5988
Fixes: #3868 - Added the current page parameter in route in Listing a…
bipoza 76da8e7
Merge branch 'master' into pagination-with-router-params
erral 7115d8f
Documentation improvements
bipoza dd88b26
Added support for multiple paginations
bipoza 386d340
Merge branch 'pagination-with-router-params' of https://github.com/pl…
bipoza fb04de8
usePagination code refactoring
bipoza 5f18384
Added unit test
bipoza 0ca3316
Added changelog
bipoza b9d518a
Merge branch 'master' into pagination-with-router-params
erral ab87619
Merge branch 'master' into pagination-with-router-params
erral e0b7b1a
Merge branch 'master' into pagination-with-router-params
bipoza 34ee368
Merge branch 'master' into pagination-with-router-params
erral 4effc3d
Merge branch 'master' into pagination-with-router-params
bipoza 7c4be39
Merge branch 'master' into pagination-with-router-params
erral b1e86d5
Merge branch 'master' into pagination-with-router-params
erral ca3c116
Merge branch 'master' into pagination-with-router-params
erral e59f19b
Merge branch 'master' into pagination-with-router-params
erral fa15daf
Merge branch 'master' into pagination-with-router-params
erral 9829c53
Merge branch 'master' into pagination-with-router-params
sneridagh 570bb04
Merge branch 'master' into pagination-with-router-params
bipoza 8fd8b74
Merge branch 'master' into pagination-with-router-params
bipoza a7b3cc9
fixed the bug when combining the search block with the pagination
bipoza bdc850d
usePagination jest tests
bipoza 3d54c67
eslist
bipoza 015572f
rename the blockId param to id and the defaultPage param to be 1 inst…
ionlizarazu cc9b1cd
fix and add tests for usePagination.js
ionlizarazu 5e20cd3
Merge branch 'master' into pagination-with-router-params
ionlizarazu 88b2ae5
changelog
ionlizarazu e04278e
Merge branch 'master' into pagination-with-router-params
erral 205457a
Merge branch 'master' into pagination-with-router-params
sneridagh 09b69ff
Merge branch 'master' into pagination-with-router-params
erral 8b264cb
Merge branch 'master' into pagination-with-router-params
erral 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { usePagination } from './usePagination'; | ||
import * as redux from 'react-redux'; | ||
import routeData from 'react-router'; | ||
|
||
const state = { | ||
content: { | ||
data: { | ||
blocks: { | ||
'1a4ebb48-8095-4182-98a5-d7ccf5761bd2': { | ||
'@type': 'title', | ||
}, | ||
'545b33de-92cf-4747-969d-68851837b317': { | ||
'@type': 'search', | ||
query: { | ||
b_size: '4', | ||
query: [ | ||
{ | ||
i: 'path', | ||
o: 'plone.app.querystring.operation.string.relativePath', | ||
v: '', | ||
}, | ||
], | ||
sort_order: 'ascending', | ||
}, | ||
showSearchInput: true, | ||
showTotalResults: true, | ||
}, | ||
'454b33de-92cf-4747-969d-68851837b317': { | ||
'@type': 'search', | ||
query: { | ||
b_size: '4', | ||
query: [ | ||
{ | ||
i: 'path', | ||
o: 'plone.app.querystring.operation.string.relativePath', | ||
v: '', | ||
}, | ||
], | ||
sort_order: 'ascending', | ||
}, | ||
showSearchInput: true, | ||
showTotalResults: true, | ||
}, | ||
'81509424-dcbc-4478-8db0-903c74b28b3d': { | ||
'@type': 'slate', | ||
plaintext: '', | ||
value: [ | ||
{ | ||
children: [ | ||
{ | ||
text: '', | ||
}, | ||
], | ||
type: 'p', | ||
}, | ||
], | ||
}, | ||
}, | ||
blocks_layout: { | ||
items: [ | ||
'545b33de-92cf-4747-969d-68851837b317', | ||
'81509424-dcbc-4478-8db0-903c74b28b3d', | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
let mockUseLocationValue = { | ||
pathname: '/testroute', | ||
search: '', | ||
}; | ||
|
||
// jest.mock('react-router-dom', () => ({ | ||
// ...jest.requireActual('react-router-dom'), | ||
// useLocation: () => ({ | ||
// pathname: 'localhost:3000/example/path', | ||
// }), | ||
// })); | ||
|
||
const setUp = (searchParam) => { | ||
mockUseLocationValue.search = searchParam; | ||
return renderHook( | ||
({ blockId, defaultPage }) => usePagination(blockId, defaultPage), | ||
{ | ||
initialProps: { | ||
blockId: '545b33de-92cf-4747-969d-68851837b317', | ||
defaultPage: 1, | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
// jest.mock('react-router-dom', () => ({ | ||
// useHistory: () => ({ replace: jest.fn() }), | ||
// useLocation: () => ({ | ||
// search: jest.fn().mockImplementation(() => { | ||
// return mockUseLocationValue; | ||
// }), | ||
// }), | ||
// })); | ||
|
||
jest.spyOn(redux, 'useSelector').mockImplementation((cb) => cb(state)); | ||
describe('Utils tests', () => { | ||
const useLocation = jest.spyOn(routeData, 'useLocation'); | ||
const useHistory = jest.spyOn(routeData, 'useHistory'); | ||
const useSelector = jest.spyOn(redux, 'useSelector'); | ||
beforeEach(() => { | ||
useLocation.mockReturnValue(mockUseLocationValue); | ||
useHistory.mockReturnValue({ replace: jest.fn() }); | ||
// useSelector.mockReturnValue((cb) => cb(state)); | ||
}); | ||
|
||
it('with blockId and defaultPage 1 - shoud be 1', () => { | ||
const { result } = setUp(); | ||
expect(result.current.currentPage).toBe(1); | ||
}); | ||
|
||
it('without params - shoud be 1', () => { | ||
const { result } = setUp(); | ||
expect(result.current.currentPage).toBe(1); | ||
}); | ||
|
||
it('with page 2 param - shoud be 2', () => { | ||
const { result } = setUp('?page=2'); | ||
expect(result.current.currentPage).toBe(2); | ||
}); | ||
|
||
it('first time with page 2 - shoud be 2', () => { | ||
const { result } = setUp('?page-545b33de-92cf-4747-969d-68851837b317=2'); | ||
expect(result.current.currentPage).toBe(2); | ||
}); | ||
}); | ||
|
||
// it('should always return previous state after each update', () => { | ||
// const { result, rerender } = setUp(); | ||
|
||
// rerender({ state: 2 }); | ||
// expect(result.current).toBe(0); | ||
|
||
// rerender({ state: 4 }); | ||
// expect(result.current).toBe(2); | ||
|
||
// rerender({ state: 6 }); | ||
// expect(result.current).toBe(4); | ||
// }); |
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.
I'd think we should stick to a generic
id
rather thenblockId
and a number for the defaultPage.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.
You mean the "blockId" naming or something else?