mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
[ACA-2299] fix search error translation (#1030)
* fix search error translation * fix translation fallback * remove fdescribe
This commit is contained in:
parent
3f0848c1dc
commit
5aa0c6f21d
@ -13,7 +13,8 @@ import {
|
|||||||
CoreModule,
|
CoreModule,
|
||||||
AppConfigService,
|
AppConfigService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoApiServiceMock
|
AlfrescoApiServiceMock,
|
||||||
|
TranslationService
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { NavigateToFolder, SnackbarErrorAction } from '../../../store/actions';
|
import { NavigateToFolder, SnackbarErrorAction } from '../../../store/actions';
|
||||||
@ -28,6 +29,7 @@ describe('SearchComponent', () => {
|
|||||||
let store: Store<any>;
|
let store: Store<any>;
|
||||||
let queryBuilder: SearchQueryBuilderService;
|
let queryBuilder: SearchQueryBuilderService;
|
||||||
let alfrescoApi: AlfrescoApiService;
|
let alfrescoApi: AlfrescoApiService;
|
||||||
|
let translate: TranslationService;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -60,6 +62,7 @@ describe('SearchComponent', () => {
|
|||||||
store = TestBed.get(Store);
|
store = TestBed.get(Store);
|
||||||
queryBuilder = TestBed.get(SearchQueryBuilderService);
|
queryBuilder = TestBed.get(SearchQueryBuilderService);
|
||||||
alfrescoApi = TestBed.get(AlfrescoApiService);
|
alfrescoApi = TestBed.get(AlfrescoApiService);
|
||||||
|
translate = TestBed.get(TranslationService);
|
||||||
|
|
||||||
fixture = TestBed.createComponent(SearchResultsComponent);
|
fixture = TestBed.createComponent(SearchResultsComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
@ -83,7 +86,57 @@ describe('SearchComponent', () => {
|
|||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(store.dispatch).toHaveBeenCalledWith(
|
expect(store.dispatch).toHaveBeenCalledWith(
|
||||||
new SnackbarErrorAction('APP.BROWSE.SEARCH.ERRORS.500')
|
new SnackbarErrorAction('APP.BROWSE.SEARCH.ERRORS.GENERIC')
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should raise a known error if search fails', fakeAsync(() => {
|
||||||
|
spyOn(translate, 'instant').and.callFake((key: string) => {
|
||||||
|
if (key === 'APP.BROWSE.SEARCH.ERRORS.401') {
|
||||||
|
return 'Known Error';
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
});
|
||||||
|
|
||||||
|
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
|
||||||
|
Promise.reject({
|
||||||
|
message: `{ "error": { "statusCode": 401 } } `
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
|
||||||
|
spyOn(store, 'dispatch').and.stub();
|
||||||
|
|
||||||
|
queryBuilder.execute();
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(
|
||||||
|
new SnackbarErrorAction('Known Error')
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should raise a generic error if search fails', fakeAsync(() => {
|
||||||
|
spyOn(translate, 'instant').and.callFake((key: string) => {
|
||||||
|
if (key === 'APP.BROWSE.SEARCH.ERRORS.GENERIC') {
|
||||||
|
return 'Generic Error';
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
});
|
||||||
|
|
||||||
|
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
|
||||||
|
Promise.reject({
|
||||||
|
message: `{ "error": { "statusCode": 401 } } `
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
|
||||||
|
spyOn(store, 'dispatch').and.stub();
|
||||||
|
|
||||||
|
queryBuilder.execute();
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(
|
||||||
|
new SnackbarErrorAction('Generic Error')
|
||||||
);
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -37,7 +37,11 @@ import { AppStore } from '../../../store/states/app.state';
|
|||||||
import { NavigateToFolder } from '../../../store/actions';
|
import { NavigateToFolder } from '../../../store/actions';
|
||||||
import { AppExtensionService } from '../../../extensions/extension.service';
|
import { AppExtensionService } from '../../../extensions/extension.service';
|
||||||
import { ContentManagementService } from '../../../services/content-management.service';
|
import { ContentManagementService } from '../../../services/content-management.service';
|
||||||
import { AppConfigService, AlfrescoApiService } from '@alfresco/adf-core';
|
import {
|
||||||
|
AppConfigService,
|
||||||
|
AlfrescoApiService,
|
||||||
|
TranslationService
|
||||||
|
} from '@alfresco/adf-core';
|
||||||
import { Observable, Subject } from 'rxjs';
|
import { Observable, Subject } from 'rxjs';
|
||||||
import { showFacetFilter } from '../../../store/selectors/app.selectors';
|
import { showFacetFilter } from '../../../store/selectors/app.selectors';
|
||||||
import { SnackbarErrorAction } from '../../../store/actions';
|
import { SnackbarErrorAction } from '../../../store/actions';
|
||||||
@ -72,7 +76,8 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
|
|||||||
private config: AppConfigService,
|
private config: AppConfigService,
|
||||||
store: Store<AppStore>,
|
store: Store<AppStore>,
|
||||||
extensions: AppExtensionService,
|
extensions: AppExtensionService,
|
||||||
content: ContentManagementService
|
content: ContentManagementService,
|
||||||
|
private translationService: TranslationService
|
||||||
) {
|
) {
|
||||||
super(store, extensions, content);
|
super(store, extensions, content);
|
||||||
|
|
||||||
@ -124,13 +129,7 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
this.searchQueryError.subscribe(error => {
|
this.searchQueryError.subscribe(error => {
|
||||||
const { statusCode } = JSON.parse(error.message).error;
|
this.onSearchError(error);
|
||||||
|
|
||||||
this.store.dispatch(
|
|
||||||
new SnackbarErrorAction(
|
|
||||||
`APP.BROWSE.SEARCH.ERRORS.${statusCode || 'GENERIC'}`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -154,6 +153,21 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSearchError(error: { message: any }) {
|
||||||
|
const { statusCode } = JSON.parse(error.message).error;
|
||||||
|
|
||||||
|
const messageKey = `APP.BROWSE.SEARCH.ERRORS.${statusCode}`;
|
||||||
|
let translated = this.translationService.instant(messageKey);
|
||||||
|
|
||||||
|
if (translated === messageKey) {
|
||||||
|
translated = this.translationService.instant(
|
||||||
|
`APP.BROWSE.SEARCH.ERRORS.GENERIC`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.store.dispatch(new SnackbarErrorAction(translated));
|
||||||
|
}
|
||||||
|
|
||||||
private isOperator(input: string): boolean {
|
private isOperator(input: string): boolean {
|
||||||
if (input) {
|
if (input) {
|
||||||
input = input.trim().toUpperCase();
|
input = input.trim().toUpperCase();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user