Skip to content

Commit

Permalink
Merge pull request DSpace#2463 from hugo-escire/issue/2159
Browse files Browse the repository at this point in the history
Fix to Pagination position is retained between searches DSpace#2159
  • Loading branch information
alanorth authored Aug 28, 2023
2 parents da13913 + 0442302 commit eaeda31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/app/shared/search-form/search-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('SearchFormComponent', () => {
const searchService = new SearchServiceStub();
const paginationService = new PaginationServiceStub();
const searchConfigService = { paginationID: 'test-id' };
const firstPage = { 'spc.page': 1 };
const dspaceObjectService = {
findById: () => createSuccessfulRemoteDataObject$(undefined),
};
Expand Down Expand Up @@ -104,37 +105,37 @@ describe('SearchFormComponent', () => {
const scope = 'MCU';
let searchQuery = {};

it('should navigate to the search page even when no parameters are provided', () => {
it('should navigate to the search first page even when no parameters are provided', () => {
comp.updateSearch(searchQuery);

expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), {
queryParams: searchQuery,
queryParams: { ...searchQuery, ...firstPage },
queryParamsHandling: 'merge'
});
});

it('should navigate to the search page with parameters only query if only query is provided', () => {
it('should navigate to the search first page with parameters only query if only query is provided', () => {
searchQuery = {
query: query
};

comp.updateSearch(searchQuery);

expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), {
queryParams: searchQuery,
queryParams: { ...searchQuery, ...firstPage },
queryParamsHandling: 'merge'
});
});

it('should navigate to the search page with parameters only query if only scope is provided', () => {
it('should navigate to the search first page with parameters only query if only scope is provided', () => {
searchQuery = {
scope: scope
};

comp.updateSearch(searchQuery);

expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), {
queryParams: searchQuery,
queryParams: {...searchQuery, ...firstPage},
queryParamsHandling: 'merge'
});
});
Expand Down
9 changes: 8 additions & 1 deletion src/app/shared/search-form/search-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ export class SearchFormComponent implements OnChanges {
* @param data Updated parameters
*/
updateSearch(data: any) {
const queryParams = Object.assign({}, data);
const goToFirstPage = { 'spc.page': 1 };

const queryParams = Object.assign(
{
...goToFirstPage
},
data
);

void this.router.navigate(this.getSearchLinkParts(), {
queryParams: queryParams,
Expand Down

0 comments on commit eaeda31

Please sign in to comment.