mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-3217] reset previous search settings (#3490)
* reset previous search settings * unit test * remove fit
This commit is contained in:
committed by
Eugenio Romano
parent
1b049f468e
commit
acf73fba54
@@ -26,7 +26,7 @@ import { Subscription } from 'rxjs/Subscription';
|
|||||||
selector: 'app-search-result-component',
|
selector: 'app-search-result-component',
|
||||||
templateUrl: './search-result.component.html',
|
templateUrl: './search-result.component.html',
|
||||||
styleUrls: ['./search-result.component.scss'],
|
styleUrls: ['./search-result.component.scss'],
|
||||||
providers: [SearchService]
|
providers: [SearchService, SearchQueryBuilderService]
|
||||||
})
|
})
|
||||||
export class SearchResultComponent implements OnInit, OnDestroy {
|
export class SearchResultComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
@@ -27,6 +27,31 @@ describe('SearchQueryBuilder', () => {
|
|||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
it('should reset to defaults', () => {
|
||||||
|
const config: SearchConfiguration = {
|
||||||
|
categories: [
|
||||||
|
<any> { id: 'cat1', enabled: true },
|
||||||
|
<any> { id: 'cat2', enabled: true }
|
||||||
|
],
|
||||||
|
filterQueries: [
|
||||||
|
{ query: 'query1' },
|
||||||
|
{ query: 'query2' }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
const builder = new SearchQueryBuilderService(buildConfig(config), null);
|
||||||
|
|
||||||
|
builder.categories = [];
|
||||||
|
builder.filterQueries = [];
|
||||||
|
|
||||||
|
expect(builder.categories.length).toBe(0);
|
||||||
|
expect(builder.filterQueries.length).toBe(0);
|
||||||
|
|
||||||
|
builder.resetToDefaults();
|
||||||
|
|
||||||
|
expect(builder.categories.length).toBe(2);
|
||||||
|
expect(builder.filterQueries.length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
it('should have empty user query by default', () => {
|
it('should have empty user query by default', () => {
|
||||||
const builder = new SearchQueryBuilderService(buildConfig({}), null);
|
const builder = new SearchQueryBuilderService(buildConfig({}), null);
|
||||||
expect(builder.userQuery).toBe('');
|
expect(builder.userQuery).toBe('');
|
||||||
|
@@ -57,13 +57,24 @@ export class SearchQueryBuilderService {
|
|||||||
|
|
||||||
constructor(appConfig: AppConfigService, private alfrescoApiService: AlfrescoApiService) {
|
constructor(appConfig: AppConfigService, private alfrescoApiService: AlfrescoApiService) {
|
||||||
this.config = appConfig.get<SearchConfiguration>('search');
|
this.config = appConfig.get<SearchConfiguration>('search');
|
||||||
|
this.resetToDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
resetToDefaults() {
|
||||||
if (this.config) {
|
if (this.config) {
|
||||||
this.categories = (this.config.categories || []).filter(category => category.enabled);
|
this.categories =
|
||||||
this.filterQueries = this.config.filterQueries || [];
|
(this.config.categories || [])
|
||||||
|
.filter(category => category.enabled)
|
||||||
|
.map(category => { return { ...category }; });
|
||||||
|
|
||||||
|
this.filterQueries =
|
||||||
|
(this.config.filterQueries || [])
|
||||||
|
.map(query => { return {...query}; });
|
||||||
|
|
||||||
if (this.config.sorting) {
|
if (this.config.sorting) {
|
||||||
this.sorting = this.config.sorting.defaults || [];
|
this.sorting =
|
||||||
|
(this.config.sorting.defaults || [])
|
||||||
|
.map(sorting => { return { ...sorting }; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user