mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4424] Pdf Viewer - password dialog does not close when pressing Escape (#4622)
* return to previous page on close * update e2e * [ADF-4424] Improve PreviousRouteService to use it in pdfViewer * change previous Url logic * remove navigation logic * remove test * Update pdfViewer.component.spec.ts * back button logic for viewer outlet * unit tests * remove fdescribe * remove unused service * e2e * return to location * remove click filter step * remove unnecessary test steps * remove un existen export * unify preview between PS and CS in demo shell * fix dispalyname property
This commit is contained in:
committed by
Eugenio Romano
parent
72b3a75a85
commit
ccdcba8778
@@ -19,7 +19,7 @@
|
||||
<mat-dialog-actions class="adf-dialog-buttons">
|
||||
<span class="adf-fill-remaining-space"></span>
|
||||
|
||||
<button mat-button mat-dialog-close>{{ 'ADF_VIEWER.PDF_DIALOG.CLOSE' | translate }}</button>
|
||||
<button mat-button mat-dialog-close data-automation-id='adf-password-dialog-close'>{{ 'ADF_VIEWER.PDF_DIALOG.CLOSE' | translate }}</button>
|
||||
|
||||
<button mat-button
|
||||
data-automation-id='adf-password-dialog-submit'
|
||||
|
@@ -331,64 +331,104 @@ describe('Test PdfViewer component', () => {
|
||||
let fixtureUrlTestPasswordComponent: ComponentFixture<UrlTestPasswordComponent>;
|
||||
let componentUrlTestPasswordComponent: UrlTestPasswordComponent;
|
||||
|
||||
beforeEach((done) => {
|
||||
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||
describe('Open password dialog', () => {
|
||||
beforeEach((done) => {
|
||||
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||
|
||||
spyOn(dialog, 'open').and.callFake((comp, context) => {
|
||||
if (context.data.reason === pdfjsLib.PasswordResponses.NEED_PASSWORD) {
|
||||
return {
|
||||
afterClosed: () => of('wrong_password')
|
||||
};
|
||||
}
|
||||
spyOn(dialog, 'open').and.callFake((comp, context) => {
|
||||
if (context.data.reason === pdfjsLib.PasswordResponses.NEED_PASSWORD) {
|
||||
return {
|
||||
afterClosed: () => of('wrong_password')
|
||||
};
|
||||
}
|
||||
|
||||
if (context.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
|
||||
return {
|
||||
afterClosed: () => of('password')
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
fixtureUrlTestPasswordComponent.detectChanges();
|
||||
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement);
|
||||
});
|
||||
|
||||
it('should try to access protected pdf', (done) => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(dialog.open).toHaveBeenCalledTimes(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should raise dialog asking for password', (done) => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.NEED_PASSWORD
|
||||
if (context.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
|
||||
return {
|
||||
afterClosed: () => of('password')
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
fixtureUrlTestPasswordComponent.detectChanges();
|
||||
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement);
|
||||
});
|
||||
|
||||
it('should try to access protected pdf', (done) => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(dialog.open).toHaveBeenCalledTimes(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should raise dialog asking for password', (done) => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.NEED_PASSWORD
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('it should raise dialog with incorrect password', (done) => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[1].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.INCORRECT_PASSWORD
|
||||
});
|
||||
done();
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('it should raise dialog with incorrect password', (done) => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[1].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.INCORRECT_PASSWORD
|
||||
describe('Close password dialog ', () => {
|
||||
beforeEach((done) => {
|
||||
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||
|
||||
spyOn(dialog, 'open').and.callFake(() => {
|
||||
return {
|
||||
afterClosed: () => {
|
||||
done();
|
||||
return of('');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
spyOn(componentUrlTestPasswordComponent.pdfViewerComponent.close, 'emit');
|
||||
|
||||
fixtureUrlTestPasswordComponent.detectChanges();
|
||||
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement);
|
||||
});
|
||||
|
||||
it('should try to access protected pdf', (done) => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(componentUrlTestPasswordComponent.pdfViewerComponent.close.emit).toHaveBeenCalledWith();
|
||||
done();
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -79,6 +79,9 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
@Output()
|
||||
error = new EventEmitter<any>();
|
||||
|
||||
@Output()
|
||||
close = new EventEmitter<any>();
|
||||
|
||||
loadingTask: any;
|
||||
currentPdfDocument: any;
|
||||
page: number;
|
||||
@@ -188,11 +191,11 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
|
||||
this.currentPdfDocument.getPage(1).then(() => {
|
||||
this.scalePage('auto');
|
||||
}, (error) => {
|
||||
}, () => {
|
||||
this.error.emit();
|
||||
});
|
||||
|
||||
}, (error) => {
|
||||
}, () => {
|
||||
this.error.emit();
|
||||
});
|
||||
}
|
||||
@@ -461,13 +464,14 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.dialog
|
||||
.open(PdfPasswordDialogComponent, {
|
||||
width: '400px',
|
||||
disableClose: true,
|
||||
data: { reason }
|
||||
})
|
||||
.afterClosed().subscribe((password) => {
|
||||
if (password) {
|
||||
callback(password);
|
||||
}
|
||||
if (password) {
|
||||
callback(password);
|
||||
} else {
|
||||
this.close.emit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -171,7 +171,7 @@
|
||||
<div class="adf-viewer-content-container" [ngSwitch]="viewerType">
|
||||
|
||||
<ng-container *ngSwitchCase="'pdf'">
|
||||
<adf-pdf-viewer [thumbnailsTemplate]="thumbnailsTemplate" [allowThumbnails]="allowThumbnails" [blobFile]="blobFile" [urlFile]="urlFileContent" [nameFile]="displayName"></adf-pdf-viewer>
|
||||
<adf-pdf-viewer (close)="onBackButtonClick()" [thumbnailsTemplate]="thumbnailsTemplate" [allowThumbnails]="allowThumbnails" [blobFile]="blobFile" [urlFile]="urlFileContent" [nameFile]="displayName"></adf-pdf-viewer>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngSwitchCase="'image'">
|
||||
|
@@ -23,16 +23,14 @@ import { AlfrescoApiService, RenditionsService } from '../../services';
|
||||
|
||||
import { CoreModule } from '../../core.module';
|
||||
|
||||
import { throwError, Observable } from 'rxjs';
|
||||
import { throwError } from 'rxjs';
|
||||
import { EventMock } from '../../mock/event.mock';
|
||||
import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
import { ViewerComponent } from './viewer.component';
|
||||
import { setupTestBed } from '../../testing/setupTestBed';
|
||||
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
|
||||
import { NodeEntry } from '@alfresco/js-api';
|
||||
import { PreviousRouteService } from 'core/services/previous-route.service';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { Router, NavigationEnd } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer-container-toolbar',
|
||||
@@ -123,22 +121,11 @@ class ViewerWithCustomOpenWithComponent {
|
||||
class ViewerWithCustomMoreActionsComponent {
|
||||
}
|
||||
|
||||
class MockRouter {
|
||||
navigate = jasmine.createSpy('navigate');
|
||||
firstUrl = new NavigationEnd(0, '/files', '/files');
|
||||
events = new Observable((observer) => {
|
||||
observer.next(this.firstUrl);
|
||||
observer.complete();
|
||||
});
|
||||
}
|
||||
|
||||
describe('ViewerComponent', () => {
|
||||
|
||||
let component: ViewerComponent;
|
||||
let fixture: ComponentFixture<ViewerComponent>;
|
||||
let alfrescoApiService: AlfrescoApiService;
|
||||
let previousRouteService: PreviousRouteService;
|
||||
let router: Router;
|
||||
let element: HTMLElement;
|
||||
|
||||
setupTestBed({
|
||||
@@ -162,9 +149,7 @@ describe('ViewerComponent', () => {
|
||||
}
|
||||
}
|
||||
},
|
||||
{ provide: Router, useClass: MockRouter },
|
||||
RenderingQueueServices,
|
||||
PreviousRouteService,
|
||||
{ provide: Location, useClass: SpyLocation }
|
||||
]
|
||||
});
|
||||
@@ -175,8 +160,6 @@ describe('ViewerComponent', () => {
|
||||
component = fixture.componentInstance;
|
||||
|
||||
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
||||
previousRouteService = TestBed.get(PreviousRouteService);
|
||||
router = TestBed.get(Router);
|
||||
});
|
||||
|
||||
describe('Extension Type Test', () => {
|
||||
@@ -661,9 +644,9 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should go back when back button is clicked', async(() => {
|
||||
it('should emit `showViewerChange` event on close', async(() => {
|
||||
|
||||
spyOn(previousRouteService, 'getPreviousUrl').and.returnValue('home');
|
||||
spyOn(component.showViewerChange, 'emit');
|
||||
|
||||
const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-back"]') as HTMLButtonElement;
|
||||
button.click();
|
||||
@@ -671,11 +654,11 @@ describe('ViewerComponent', () => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
expect(component.showViewerChange.emit).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should render close viewer button if it is a shared link', (done) => {
|
||||
it('should not render close viewer button if it is a shared link', (done) => {
|
||||
spyOn(alfrescoApiService.getInstance().core.sharedlinksApi, 'getSharedLink')
|
||||
.and.returnValue(Promise.reject({}));
|
||||
|
||||
|
@@ -15,7 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Location } from '@angular/common';
|
||||
import {
|
||||
Component, ContentChild, EventEmitter, HostListener, ElementRef,
|
||||
Input, OnChanges, Output, SimpleChanges, TemplateRef,
|
||||
@@ -25,7 +24,6 @@ import { RenditionPaging, SharedLinkEntry, Node, RenditionEntry, NodeEntry } fro
|
||||
import { BaseEvent } from '../../events';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { PreviousRouteService } from '../../services/previous-route.service';
|
||||
import { ViewerMoreActionsComponent } from './viewer-more-actions.component';
|
||||
import { ViewerOpenWithComponent } from './viewer-open-with.component';
|
||||
import { ViewerSidebarComponent } from './viewer-sidebar.component';
|
||||
@@ -33,7 +31,6 @@ import { ViewerToolbarComponent } from './viewer-toolbar.component';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ViewUtilService } from '../services/view-util.service';
|
||||
import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extensions';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer',
|
||||
@@ -98,6 +95,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
@Input()
|
||||
displayName: string;
|
||||
|
||||
/** @deprecated 3.2.0 */
|
||||
/** Allows `back` navigation */
|
||||
@Input()
|
||||
allowGoBack = true;
|
||||
@@ -239,11 +237,8 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private viewUtils: ViewUtilService,
|
||||
private logService: LogService,
|
||||
private location: Location,
|
||||
private extensionService: AppExtensionService,
|
||||
private el: ElementRef,
|
||||
private router: Router,
|
||||
private previousRouteService: PreviousRouteService) {
|
||||
private el: ElementRef) {
|
||||
}
|
||||
|
||||
isSourceDefined(): boolean {
|
||||
@@ -477,23 +472,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onBackButtonClick() {
|
||||
if (this.overlayMode) {
|
||||
this.close();
|
||||
} else {
|
||||
const event = new BaseEvent<any>();
|
||||
this.goBack.next(event);
|
||||
|
||||
if (!event.defaultPrevented) {
|
||||
|
||||
const previousUrl = this.previousRouteService.getPreviousUrl();
|
||||
|
||||
if (previousUrl && previousUrl.includes('login') || window.history.length <= 2) {
|
||||
this.router.navigate([{outlets: {overlay: null, primary: ['home']}}]);
|
||||
} else {
|
||||
this.location.back();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
onNavigateBeforeClick() {
|
||||
@@ -719,7 +698,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
checkExtensions(extensionAllowed) {
|
||||
if (typeof extensionAllowed === 'string') {
|
||||
if (typeof extensionAllowed === 'string') {
|
||||
return this.extension.toLowerCase() === extensionAllowed.toLowerCase();
|
||||
} else if (extensionAllowed.length > 0) {
|
||||
return extensionAllowed.find((currentExtension) => {
|
||||
|
Reference in New Issue
Block a user