mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACA] Search - show error message on error (#1003)
* show error message * remove fdescribe
This commit is contained in:
committed by
Denys Vuika
parent
6f9ba3ac37
commit
d0d7765af3
@@ -1,11 +1,22 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
async,
|
||||
ComponentFixture,
|
||||
TestBed,
|
||||
fakeAsync,
|
||||
tick
|
||||
} from '@angular/core/testing';
|
||||
|
||||
import { SearchResultsComponent } from './search-results.component';
|
||||
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||
import { AppSearchResultsModule } from '../search-results.module';
|
||||
import { CoreModule, AppConfigService } from '@alfresco/adf-core';
|
||||
import {
|
||||
CoreModule,
|
||||
AppConfigService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoApiServiceMock
|
||||
} from '@alfresco/adf-core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { NavigateToFolder } from '../../../store/actions';
|
||||
import { NavigateToFolder, SnackbarErrorAction } from '../../../store/actions';
|
||||
import { Pagination } from '@alfresco/js-api';
|
||||
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
@@ -16,11 +27,16 @@ describe('SearchComponent', () => {
|
||||
let config: AppConfigService;
|
||||
let store: Store<any>;
|
||||
let queryBuilder: SearchQueryBuilderService;
|
||||
let alfrescoApi: AlfrescoApiService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreModule.forRoot(), AppTestingModule, AppSearchResultsModule],
|
||||
providers: [
|
||||
{
|
||||
provide: AlfrescoApiService,
|
||||
useClass: AlfrescoApiServiceMock
|
||||
},
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
@@ -43,6 +59,7 @@ describe('SearchComponent', () => {
|
||||
config = TestBed.get(AppConfigService);
|
||||
store = TestBed.get(Store);
|
||||
queryBuilder = TestBed.get(SearchQueryBuilderService);
|
||||
alfrescoApi = TestBed.get(AlfrescoApiService);
|
||||
|
||||
fixture = TestBed.createComponent(SearchResultsComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -52,6 +69,24 @@ describe('SearchComponent', () => {
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should raise an error if search fails', fakeAsync(() => {
|
||||
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
|
||||
Promise.reject({
|
||||
message: `{ "error": { "statusCode": 500 } } `
|
||||
})
|
||||
);
|
||||
|
||||
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
|
||||
spyOn(store, 'dispatch').and.stub();
|
||||
|
||||
queryBuilder.execute();
|
||||
tick();
|
||||
|
||||
expect(store.dispatch).toHaveBeenCalledWith(
|
||||
new SnackbarErrorAction('APP.BROWSE.SEARCH.ERRORS.500')
|
||||
);
|
||||
}));
|
||||
|
||||
it('should decode encoded URI', () => {
|
||||
expect(queryBuilder.userQuery).toEqual(
|
||||
'(TYPE: "cm:folder" AND (=cm: name: email OR cm: name: budget))'
|
||||
|
@@ -37,9 +37,10 @@ import { AppStore } from '../../../store/states/app.state';
|
||||
import { NavigateToFolder } from '../../../store/actions';
|
||||
import { AppExtensionService } from '../../../extensions/extension.service';
|
||||
import { ContentManagementService } from '../../../services/content-management.service';
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AppConfigService, AlfrescoApiService } from '@alfresco/adf-core';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { showFacetFilter } from '../../../store/selectors/app.selectors';
|
||||
import { SnackbarErrorAction } from '../../../store/actions';
|
||||
|
||||
@Component({
|
||||
selector: 'aca-search-results',
|
||||
@@ -62,8 +63,10 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
|
||||
hasSelectedFilters = false;
|
||||
sorting = ['name', 'asc'];
|
||||
isLoading = false;
|
||||
searchQueryError: Subject<any> = new Subject();
|
||||
|
||||
constructor(
|
||||
private alfrescoApiService: AlfrescoApiService,
|
||||
private queryBuilder: SearchQueryBuilderService,
|
||||
private route: ActivatedRoute,
|
||||
private config: AppConfigService,
|
||||
@@ -84,6 +87,25 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
|
||||
ngOnInit() {
|
||||
super.ngOnInit();
|
||||
|
||||
// todo: remove once ADF-4193 is resolved
|
||||
this.queryBuilder.execute = async () => {
|
||||
const query = this.queryBuilder.buildQuery();
|
||||
if (query) {
|
||||
try {
|
||||
const response = await this.alfrescoApiService.searchApi.search(
|
||||
query
|
||||
);
|
||||
this.queryBuilder.executed.next(response);
|
||||
} catch (error) {
|
||||
this.searchQueryError.next(error);
|
||||
|
||||
this.queryBuilder.executed.next({
|
||||
list: { pagination: { totalItems: 0 }, entries: [] }
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.sorting = this.getSorting();
|
||||
|
||||
this.subscriptions.push(
|
||||
@@ -97,6 +119,16 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
|
||||
|
||||
this.onSearchResultLoaded(data);
|
||||
this.isLoading = false;
|
||||
}),
|
||||
|
||||
this.searchQueryError.subscribe(error => {
|
||||
const { statusCode } = JSON.parse(error.message).error;
|
||||
|
||||
this.store.dispatch(
|
||||
new SnackbarErrorAction(
|
||||
`APP.BROWSE.SEARCH.ERRORS.${statusCode || 'GENERIC'}`
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
|
@@ -169,7 +169,11 @@
|
||||
},
|
||||
"UNKNOWN_LOCATION": "Unknown",
|
||||
"NO_RESULTS": "Your search returned 0 results",
|
||||
"TOGGLE_SEARCH_FILTER": "Toggle search filter"
|
||||
"TOGGLE_SEARCH_FILTER": "Toggle search filter",
|
||||
"ERRORS": {
|
||||
"500": "There was an error processing the search query [500]",
|
||||
"GENERIC": "There was an error processing the search query"
|
||||
}
|
||||
},
|
||||
"SEARCH_LIBRARIES": {
|
||||
"TITLE": "Libraries found...",
|
||||
|
Reference in New Issue
Block a user