mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-04-23 22:30:37 +00:00
[MNT-24950] Preview a file from APS doesn't work in ADW (#11439)
This commit is contained in:
committed by
GitHub
parent
22baef7955
commit
de62fe181a
@@ -198,4 +198,58 @@ describe('ProcessContentService', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getContentPreview', () => {
|
||||
it('should return preview rendition when available', (done) => {
|
||||
const contentId = 999;
|
||||
const fakeBlob = createFakeBlob();
|
||||
spyOn(service.contentApi, 'getRawContent').and.returnValue(Promise.resolve(fakeBlob));
|
||||
|
||||
service.getContentPreview(contentId).subscribe((result) => {
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'preview');
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual(fakeBlob);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fallback to raw content when preview fails', (done) => {
|
||||
const contentId = 999;
|
||||
const fakeBlob = createFakeBlob();
|
||||
spyOn(service.contentApi, 'getRawContent').and.returnValues(
|
||||
Promise.reject(new Error('Preview not available')),
|
||||
Promise.resolve(fakeBlob)
|
||||
);
|
||||
|
||||
service.getContentPreview(contentId).subscribe((result) => {
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'preview');
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId);
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledTimes(2);
|
||||
expect(result).toEqual(fakeBlob);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when both preview and raw content fail', (done) => {
|
||||
const contentId = 999;
|
||||
const errorMessage = 'Content not found';
|
||||
spyOn(service.contentApi, 'getRawContent').and.returnValues(
|
||||
Promise.reject(new Error('Preview not available')),
|
||||
Promise.reject(new Error(errorMessage))
|
||||
);
|
||||
|
||||
service.getContentPreview(contentId).subscribe({
|
||||
next: () => {
|
||||
fail('Should have thrown an error');
|
||||
},
|
||||
error: (error) => {
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'preview');
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId);
|
||||
expect(service.contentApi.getRawContent).toHaveBeenCalledTimes(2);
|
||||
expect(error.message).toEqual(errorMessage);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ export class ProcessContentService {
|
||||
*/
|
||||
getContentPreview(contentId: number): Observable<Blob> {
|
||||
return new Observable((observer) => {
|
||||
this.contentApi.getRawContent(contentId).then(
|
||||
this.contentApi.getRawContent(contentId, 'preview').then(
|
||||
(result) => {
|
||||
observer.next(result);
|
||||
observer.complete();
|
||||
@@ -244,8 +244,8 @@ export class ProcessContentService {
|
||||
errMsg = error.message
|
||||
? error.message
|
||||
: error.status
|
||||
? `${error.status} - ${error.statusText}`
|
||||
: ProcessContentService.GENERIC_ERROR_MESSAGE;
|
||||
? `${error.status} - ${error.statusText}`
|
||||
: ProcessContentService.GENERIC_ERROR_MESSAGE;
|
||||
}
|
||||
return throwError(errMsg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user