mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[MNT-24950] Preview a file from APS doesn't work in ADW (#11439)
This commit is contained in:
@@ -198,4 +198,58 @@ describe('ProcessContentService', () => {
|
|||||||
done();
|
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> {
|
getContentPreview(contentId: number): Observable<Blob> {
|
||||||
return new Observable((observer) => {
|
return new Observable((observer) => {
|
||||||
this.contentApi.getRawContent(contentId).then(
|
this.contentApi.getRawContent(contentId, 'preview').then(
|
||||||
(result) => {
|
(result) => {
|
||||||
observer.next(result);
|
observer.next(result);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
|
|||||||
Reference in New Issue
Block a user