mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-4882] Error fixed - Tests improved
This commit is contained in:
@@ -10,5 +10,5 @@
|
||||
</ds-viewable-collection>
|
||||
</div>
|
||||
<ds-loading *ngIf="isLoading()" message="{{'loading.mydspace-results' | translate}}"></ds-loading>
|
||||
<ds-error *ngIf="showError(searchResults)" message="{{errorMessageLabel(searchResults) | translate}}"></ds-error>
|
||||
<ds-error *ngIf="showError()" message="{{errorMessageLabel() | translate}}"></ds-error>
|
||||
<h3 *ngIf="searchResults?.payload?.page.length == 0" class="text-center text-muted" ><span>{{'mydspace.results.no-results' | translate}}</span></h3>
|
||||
|
@@ -40,9 +40,19 @@ describe('MyDSpaceResultsComponent', () => {
|
||||
expect(fixture.debugElement.query(By.css('a'))).toBeNull();
|
||||
});
|
||||
|
||||
it('should display error message if error is != 400', () => {
|
||||
(comp as any).searchResults = { hasFailed: true, error: { statusCode: 500 } };
|
||||
it('should display error message if error is 500', () => {
|
||||
(comp as any).searchResults = { hasFailed: true, statusCode: 500 };
|
||||
fixture.detectChanges();
|
||||
expect(comp.showError()).toBeTrue();
|
||||
expect(comp.errorMessageLabel()).toBe('error.search-results');
|
||||
expect(fixture.debugElement.query(By.css('ds-error'))).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should display error message if error is 422', () => {
|
||||
(comp as any).searchResults = { hasFailed: true, statusCode: 422 };
|
||||
fixture.detectChanges();
|
||||
expect(comp.showError()).toBeTrue();
|
||||
expect(comp.errorMessageLabel()).toBe('error.invalid-search-query');
|
||||
expect(fixture.debugElement.query(By.css('ds-error'))).not.toBeNull();
|
||||
});
|
||||
|
||||
|
@@ -59,11 +59,11 @@ export class MyDSpaceResultsComponent {
|
||||
return !this.searchResults || isEmpty(this.searchResults) || this.searchResults.isLoading;
|
||||
}
|
||||
|
||||
showError(searchResults: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>): boolean {
|
||||
return searchResults?.hasFailed && (!searchResults?.errorMessage || searchResults?.statusCode !== 400);
|
||||
showError(): boolean {
|
||||
return this.searchResults?.hasFailed && (!this.searchResults?.errorMessage || this.searchResults?.statusCode !== 400);
|
||||
}
|
||||
|
||||
errorMessageLabel(searchResults: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>): string {
|
||||
return (searchResults?.statusCode === 422) ? 'error.invalid-search-query' : 'error.search-results';
|
||||
errorMessageLabel(): string {
|
||||
return (this.searchResults?.statusCode === 422) ? 'error.invalid-search-query' : 'error.search-results';
|
||||
}
|
||||
}
|
||||
|
@@ -169,7 +169,7 @@ export class SearchFilterComponent implements OnInit {
|
||||
return this.searchService.getFacetValuesFor(this.filter, 1, options).pipe(
|
||||
filter((RD) => !RD.isLoading),
|
||||
map((valuesRD) => {
|
||||
return valuesRD.payload.totalElements > 0;
|
||||
return valuesRD.payload?.totalElements > 0;
|
||||
}),);
|
||||
}
|
||||
));
|
||||
|
Reference in New Issue
Block a user