45621: finished facet branch - changed decrease to reset

This commit is contained in:
Lotte Hofstede
2017-11-20 17:06:00 +01:00
parent a5d562fd22
commit 778c8049d0
8 changed files with 68 additions and 17 deletions

View File

@@ -21,7 +21,7 @@
<a class="float-left" *ngIf="filterValues.length > (facetCount | async)"
(click)="showMore()">{{"search.filters.filter.show-more"
| translate}}</a>
<a class="float-right" *ngIf="(currentPage | async) > 1" (click)="showLess()">{{"search.filters.filter.show-less"
<a class="float-right" *ngIf="(currentPage | async) > 1" (click)="showFirstPageOnly()">{{"search.filters.filter.show-less"
| translate}}</a>
</div>
</div>

View File

@@ -55,8 +55,10 @@ describe('SearchFacetFilterComponent', () => {
getQueryParamsWithout: (paramName: string, filterValue: string) => '',
getPage: (paramName: string) => page,
/* tslint:disable:no-empty */
increasePage: (filterName: string) => {},
decreasePage: (filterName: string) => {},
incrementPage: (filterName: string) => {
},
resetPage: (filterName: string) => {
},
/* tslint:enable:no-empty */
searchLink: '/search',
}
@@ -156,12 +158,23 @@ describe('SearchFacetFilterComponent', () => {
describe('when the showMore method is called', () => {
beforeEach(() => {
spyOn(filterService, 'increasePage');
spyOn(filterService, 'incrementPage');
comp.showMore();
});
it('should call increasePage on the filterService with the correct filter parameter name', () => {
expect(filterService.increasePage).toHaveBeenCalledWith(mockFilterConfig.name)
it('should call incrementPage on the filterService with the correct filter parameter name', () => {
expect(filterService.incrementPage).toHaveBeenCalledWith(mockFilterConfig.name)
});
});
describe('when the showFirstPageOnly method is called', () => {
beforeEach(() => {
spyOn(filterService, 'resetPage');
comp.showFirstPageOnly();
});
it('should call resetPage on the filterService with the correct filter parameter name', () => {
expect(filterService.resetPage).toHaveBeenCalledWith(mockFilterConfig.name)
});
});

View File

@@ -57,11 +57,11 @@ export class SearchFacetFilterComponent implements OnInit {
}
showMore() {
this.filterService.increasePage(this.filterConfig.name);
this.filterService.incrementPage(this.filterConfig.name);
}
showLess() {
this.filterService.decreasePage(this.filterConfig.name);
showFirstPageOnly() {
this.filterService.resetPage(this.filterConfig.name);
}
getCurrentPage(): Observable<number> {

View File

@@ -17,7 +17,8 @@ export const SearchFilterActionTypes = {
INITIAL_EXPAND: type('dspace/search-filter/INITIAL_EXPAND'),
TOGGLE: type('dspace/search-filter/TOGGLE'),
DECREMENT_PAGE: type('dspace/search-filter/DECREMENT_PAGE'),
INCREMENT_PAGE: type('dspace/search-filter/INCREMENT_PAGE')
INCREMENT_PAGE: type('dspace/search-filter/INCREMENT_PAGE'),
RESET_PAGE: type('dspace/search-filter/RESET_PAGE')
};
export class SearchFilterAction implements Action {
@@ -55,4 +56,8 @@ export class SearchFilterDecrementPageAction extends SearchFilterAction {
export class SearchFilterIncrementPageAction extends SearchFilterAction {
type = SearchFilterActionTypes.INCREMENT_PAGE;
}
export class SearchFilterResetPageAction extends SearchFilterAction {
type = SearchFilterActionTypes.RESET_PAGE;
}
/* tslint:enable:max-classes-per-file */

View File

@@ -4,7 +4,7 @@ import {
SearchFilterInitialCollapseAction,
SearchFilterInitialExpandAction,
SearchFilterToggleAction,
SearchFilterDecrementPageAction
SearchFilterDecrementPageAction, SearchFilterResetPageAction
} from './search-filter.actions';
import { filterReducer } from './search-filter.reducer';
@@ -154,4 +154,12 @@ describe('filterReducer', () => {
const newState = filterReducer(state, action);
expect(newState[filterName1].page).toEqual(1);
});
it('should reset the page to 1 for the specified filter in response to the RESET_PAGE action', () => {
const state = {};
state[filterName1] = { filterCollapsed: true, page: 20 };
const action = new SearchFilterResetPageAction(filterName1);
const newState = filterReducer(state, action);
expect(newState[filterName1].page).toEqual(1);
});
});

View File

@@ -77,6 +77,15 @@ export function filterReducer(state = initialState, action: SearchFilterAction):
}
});
}
case SearchFilterActionTypes.RESET_PAGE: {
return Object.assign({}, state, {
[action.filterName]: {
filterCollapsed: state[action.filterName].filterCollapsed,
page: 1
}
});
}
case SearchFilterActionTypes.TOGGLE: {

View File

@@ -4,7 +4,8 @@ import { Store } from '@ngrx/store';
import {
SearchFilterCollapseAction, SearchFilterDecrementPageAction, SearchFilterExpandAction,
SearchFilterIncrementPageAction,
SearchFilterInitialCollapseAction, SearchFilterInitialExpandAction, SearchFilterToggleAction
SearchFilterInitialCollapseAction, SearchFilterInitialExpandAction, SearchFilterResetPageAction,
SearchFilterToggleAction
} from './search-filter.actions';
import { SearchFiltersState } from './search-filter.reducer';
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
@@ -95,7 +96,7 @@ describe('SearchFilterService', () => {
describe('when the decreasePage method is triggered', () => {
beforeEach(() => {
service.decreasePage(mockFilterConfig.name);
service.decrementPage(mockFilterConfig.name);
});
it('SearchFilterDecrementPageAction should be dispatched to the store', () => {
@@ -106,7 +107,7 @@ describe('SearchFilterService', () => {
describe('when the increasePage method is triggered', () => {
beforeEach(() => {
service.increasePage(mockFilterConfig.name);
service.incrementPage(mockFilterConfig.name);
});
it('SearchFilterCollapseAction should be dispatched to the store', () => {
@@ -115,6 +116,17 @@ describe('SearchFilterService', () => {
});
describe('when the resetPage method is triggered', () => {
beforeEach(() => {
service.resetPage(mockFilterConfig.name);
});
it('SearchFilterDecrementPageAction should be dispatched to the store', () => {
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterResetPageAction(mockFilterConfig.name));
});
});
describe('when the expand method is triggered', () => {
beforeEach(() => {
service.expand(mockFilterConfig.name);

View File

@@ -7,7 +7,7 @@ import {
SearchFilterDecrementPageAction, SearchFilterExpandAction,
SearchFilterIncrementPageAction,
SearchFilterInitialCollapseAction,
SearchFilterInitialExpandAction,
SearchFilterInitialExpandAction, SearchFilterResetPageAction,
SearchFilterToggleAction
} from './search-filter.actions';
import { hasValue, } from '../../../shared/empty.util';
@@ -91,13 +91,17 @@ export class SearchFilterService {
this.store.dispatch(new SearchFilterInitialExpandAction(filterName));
}
public decreasePage(filterName: string): void {
public decrementPage(filterName: string): void {
this.store.dispatch(new SearchFilterDecrementPageAction(filterName));
}
public increasePage(filterName: string): void {
public incrementPage(filterName: string): void {
this.store.dispatch(new SearchFilterIncrementPageAction(filterName));
}
public resetPage(filterName: string): void {
this.store.dispatch(new SearchFilterResetPageAction(filterName));
}
}
function filterByNameSelector(name: string): MemoizedSelector<SearchFiltersState, SearchFilterState> {