From ccdcba87788d1bfb1ee17c041178d6a9b520346d Mon Sep 17 00:00:00 2001
From: Cilibiu Bogdan
Date: Thu, 11 Jul 2019 19:33:15 +0300
Subject: [PATCH] [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
---
demo-shell/src/app/app.routes.ts | 2 +-
.../blob-preview/blob-preview.component.ts | 38 -----
.../blob-preview/blob-preview.module.ts | 49 ------
.../blob-preview/bob-preview.component.html | 5 -
.../file-view/file-view.component.html | 14 +-
.../file-view/file-view.component.ts | 16 +-
.../viewer-content-services-component.e2e.ts | 7 +
e2e/pages/adf/viewerPage.ts | 6 +
.../task-attachmentList-actionMenu.e2e.ts | 7 -
.../services/previous-route.service.spec.ts | 61 --------
lib/core/services/previous-route.service.ts | 42 ------
lib/core/services/public-api.ts | 1 -
.../components/pdfViewer-password-dialog.html | 2 +-
.../components/pdfViewer.component.spec.ts | 142 +++++++++++-------
.../viewer/components/pdfViewer.component.ts | 16 +-
.../viewer/components/viewer.component.html | 2 +-
.../components/viewer.component.spec.ts | 27 +---
.../viewer/components/viewer.component.ts | 29 +---
18 files changed, 149 insertions(+), 317 deletions(-)
delete mode 100644 demo-shell/src/app/components/blob-preview/blob-preview.component.ts
delete mode 100644 demo-shell/src/app/components/blob-preview/blob-preview.module.ts
delete mode 100644 demo-shell/src/app/components/blob-preview/bob-preview.component.html
delete mode 100644 lib/core/services/previous-route.service.spec.ts
delete mode 100644 lib/core/services/previous-route.service.ts
diff --git a/demo-shell/src/app/app.routes.ts b/demo-shell/src/app/app.routes.ts
index d6005ad0eb..49381be768 100644
--- a/demo-shell/src/app/app.routes.ts
+++ b/demo-shell/src/app/app.routes.ts
@@ -93,7 +93,7 @@ export const appRoutes: Routes = [
children: [
{
path: '',
- loadChildren: 'app/components/blob-preview/blob-preview.module#BlobPreviewModule'
+ loadChildren: 'app/components/file-view/file-view.module#FileViewModule'
}
]
},
diff --git a/demo-shell/src/app/components/blob-preview/blob-preview.component.ts b/demo-shell/src/app/components/blob-preview/blob-preview.component.ts
deleted file mode 100644
index 15641cd71d..0000000000
--- a/demo-shell/src/app/components/blob-preview/blob-preview.component.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-/*!
- * @license
- * Copyright 2019 Alfresco Software, Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { Component } from '@angular/core';
-import { PreviewService } from '../../services/preview.service';
-import { Router } from '@angular/router';
-
-@Component({
- templateUrl: 'bob-preview.component.html'
-})
-export class BlobPreviewComponent {
- content: Blob;
- name: string;
-
- constructor(preview: PreviewService, router: Router) {
- if (preview.content === null || preview.name === null) {
- router.navigate([{ outlets: { overlay: null } }]);
- return;
- }
-
- this.content = preview.content;
- this.name = preview.name;
- }
-}
diff --git a/demo-shell/src/app/components/blob-preview/blob-preview.module.ts b/demo-shell/src/app/components/blob-preview/blob-preview.module.ts
deleted file mode 100644
index 9e056eac9c..0000000000
--- a/demo-shell/src/app/components/blob-preview/blob-preview.module.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-/*!
- * @license
- * Copyright 2019 Alfresco Software, Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { NgModule } from '@angular/core';
-import { Routes, RouterModule } from '@angular/router';
-import { CommonModule } from '@angular/common';
-import { CoreModule, InfoDrawerModule } from '@alfresco/adf-core';
-import { ContentDirectiveModule, ContentMetadataModule, VersionManagerModule } from '@alfresco/adf-content-services';
-import { BlobPreviewComponent } from './blob-preview.component';
-
-const routes: Routes = [
- {
- path: '',
- component: BlobPreviewComponent
- }
-];
-
-@NgModule({
- imports: [
- CommonModule,
- RouterModule.forChild(routes),
- CoreModule.forChild(),
- InfoDrawerModule,
- ContentDirectiveModule,
- ContentMetadataModule,
- VersionManagerModule
- ],
- declarations: [
- BlobPreviewComponent
- ],
- exports: [
- BlobPreviewComponent
- ]
-})
-export class BlobPreviewModule {}
diff --git a/demo-shell/src/app/components/blob-preview/bob-preview.component.html b/demo-shell/src/app/components/blob-preview/bob-preview.component.html
deleted file mode 100644
index 50d2a1515f..0000000000
--- a/demo-shell/src/app/components/blob-preview/bob-preview.component.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
\ No newline at end of file
diff --git a/demo-shell/src/app/components/file-view/file-view.component.html b/demo-shell/src/app/components/file-view/file-view.component.html
index e6274e0b69..553ea01d97 100644
--- a/demo-shell/src/app/components/file-view/file-view.component.html
+++ b/demo-shell/src/app/components/file-view/file-view.component.html
@@ -1,4 +1,4 @@
-
+
@@ -284,14 +284,16 @@
-
-
@@ -314,6 +316,7 @@
diff --git a/demo-shell/src/app/components/file-view/file-view.component.ts b/demo-shell/src/app/components/file-view/file-view.component.ts
index e5b4187f87..f5e46304e4 100644
--- a/demo-shell/src/app/components/file-view/file-view.component.ts
+++ b/demo-shell/src/app/components/file-view/file-view.component.ts
@@ -16,9 +16,10 @@
*/
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
-import { ActivatedRoute, Router } from '@angular/router';
+import { ActivatedRoute, Router, PRIMARY_OUTLET } from '@angular/router';
import { ContentService, AllowableOperationsEnum, PermissionsEnum, NodesApiService } from '@alfresco/adf-core';
import { MatSnackBar } from '@angular/material';
+import { PreviewService } from '../../services/preview.service';
@Component({
selector: 'app-file-view',
@@ -57,12 +58,15 @@ export class FileViewComponent implements OnInit {
showTabWithIconAndLabel = false;
desiredAspect: string = null;
showAspect: string = null;
+ content: Blob;
+ name: string;
constructor(private router: Router,
private route: ActivatedRoute,
private snackBar: MatSnackBar,
private nodeApiService: NodesApiService,
- private contentServices: ContentService) {
+ private contentServices: ContentService,
+ private preview: PreviewService) {
}
ngOnInit() {
@@ -81,10 +85,18 @@ export class FileViewComponent implements OnInit {
},
() => this.router.navigate(['/files', id])
);
+ } else if (this.preview.content) {
+ this.content = this.preview.content;
+ this.displayName = this.preview.name;
}
});
}
+ onViewerVisibilityChanged() {
+ const primaryUrl = this.router.parseUrl(this.router.url).root.children[PRIMARY_OUTLET].toString();
+ this.router.navigateByUrl(primaryUrl);
+ }
+
onUploadError(errorMessage: string) {
this.snackBar.open(errorMessage, '', { duration: 4000 });
}
diff --git a/e2e/core/viewer/viewer-content-services-component.e2e.ts b/e2e/core/viewer/viewer-content-services-component.e2e.ts
index ba4234cdc7..0dbfd9d8a4 100644
--- a/e2e/core/viewer/viewer-content-services-component.e2e.ts
+++ b/e2e/core/viewer/viewer-content-services-component.e2e.ts
@@ -401,4 +401,11 @@ describe('Content Services Viewer', () => {
viewerPage.clickCloseButton();
});
+
+ it('[C307985] Should close the viewer when password dialog is cancelled', () => {
+ viewerPage.viewFile(protectedFile.name);
+ viewerPage.checkPasswordDialogIsDisplayed();
+ viewerPage.clickClosePasswordDialog();
+ contentServicesPage.checkContentIsDisplayed(protectedFile.name);
+ });
});
diff --git a/e2e/pages/adf/viewerPage.ts b/e2e/pages/adf/viewerPage.ts
index 0604d3bea2..6666141db4 100644
--- a/e2e/pages/adf/viewerPage.ts
+++ b/e2e/pages/adf/viewerPage.ts
@@ -50,6 +50,7 @@ export class ViewerPage {
lastThumbnailDisplayed = element.all(by.css('adf-pdf-thumb')).last();
passwordDialog = element(by.css('adf-pdf-viewer-password-dialog'));
passwordSubmit = element(by.css('button[data-automation-id="adf-password-dialog-submit"]'));
+ passwordDialogClose = element(by.css('button[data-automation-id="adf-password-dialog-close"]'));
passwordSubmitDisabled = element(by.css('button[data-automation-id="adf-password-dialog-submit"][disabled]'));
passwordInput = element(by.css('input[data-automation-id="adf-password-dialog-input"]'));
passwordError = element(by.css('mat-error[data-automation-id="adf-password-dialog-error"]'));
@@ -149,6 +150,11 @@ export class ViewerPage {
BrowserVisibility.waitUntilElementIsVisible(this.pdfPageLoaded, 30000, `not loaded ${fileName}`);
}
+ clickClosePasswordDialog() {
+ BrowserVisibility.waitUntilElementIsVisible(this.passwordDialogClose);
+ this.passwordDialogClose.click();
+ }
+
checkImgViewerIsDisplayed() {
BrowserVisibility.waitUntilElementIsOnPage(this.imgViewer);
}
diff --git a/e2e/process-services/task-attachmentList-actionMenu.e2e.ts b/e2e/process-services/task-attachmentList-actionMenu.e2e.ts
index f497d81c57..7ffde50b45 100644
--- a/e2e/process-services/task-attachmentList-actionMenu.e2e.ts
+++ b/e2e/process-services/task-attachmentList-actionMenu.e2e.ts
@@ -101,15 +101,11 @@ describe('Attachment list action menu for tasks', () => {
viewerPage.checkFileNameIsDisplayed(pngFile.name);
viewerPage.clickCloseButton();
- taskPage.filtersPage().goToFilter(CONSTANTS.TASK_FILTERS.MY_TASKS);
-
attachmentListPage.doubleClickFile(pngFile.name);
viewerPage.checkFileNameIsDisplayed(pngFile.name);
viewerPage.clickCloseButton();
- taskPage.filtersPage().goToFilter(CONSTANTS.TASK_FILTERS.MY_TASKS);
-
attachmentListPage.downloadFile(pngFile.name);
browser.driver.sleep(1000);
@@ -139,9 +135,6 @@ describe('Attachment list action menu for tasks', () => {
viewerPage.checkFileNameIsDisplayed(pngFile.name);
viewerPage.clickCloseButton();
- taskPage.filtersPage().goToFilter(CONSTANTS.TASK_FILTERS.COMPLETED_TASKS);
- taskPage.tasksListPage().selectRow(taskName.completed);
-
attachmentListPage.downloadFile(pngFile.name);
browser.driver.sleep(1000);
diff --git a/lib/core/services/previous-route.service.spec.ts b/lib/core/services/previous-route.service.spec.ts
deleted file mode 100644
index 5972b95d1e..0000000000
--- a/lib/core/services/previous-route.service.spec.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-/*!
- * @license
- * Copyright 2019 Alfresco Software, Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { TestBed } from '@angular/core/testing';
-import { setupTestBed } from '../testing/setupTestBed';
-import { PreviousRouteService } from './previous-route.service';
-import { Router, NavigationEnd } from '@angular/router';
-import { Observable } from 'rxjs';
-import { CoreTestingModule } from 'core/testing/core.testing.module';
-
-class MockRouter {
- firstUrl = new NavigationEnd(0, '/files', '/files');
- secondUrl = new NavigationEnd(0, '/home', '/home');
- events = new Observable((observer) => {
- observer.next(this.firstUrl);
- observer.next(this.secondUrl);
- observer.complete();
- });
-}
-
-describe('Previous route service ', () => {
-
- let previousRouteService: PreviousRouteService;
-
- setupTestBed({
- imports: [
- CoreTestingModule
- ],
- providers: [
- { provide: Router, useClass: MockRouter },
- PreviousRouteService
- ]
- });
-
- beforeEach(() => {
- previousRouteService = TestBed.get(PreviousRouteService);
- });
-
- it('should be able to create the service', () => {
- expect(previousRouteService).not.toBeNull();
- expect(previousRouteService).toBeDefined();
- });
-
- it('should set curent url when new page loads', () => {
- expect(previousRouteService.getPreviousUrl()).toBe('/files');
- });
-});
diff --git a/lib/core/services/previous-route.service.ts b/lib/core/services/previous-route.service.ts
deleted file mode 100644
index d545943723..0000000000
--- a/lib/core/services/previous-route.service.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-/*!
- * @license
- * Copyright 2019 Alfresco Software, Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { Injectable } from '@angular/core';
-import { Router, NavigationEnd } from '@angular/router';
-
-@Injectable({
- providedIn: 'root'
-})
-export class PreviousRouteService {
-
- private previousUrl: string;
- private currentUrl: string;
-
- constructor(private router: Router) {
- this.currentUrl = this.router.url;
- this.router.events.subscribe((event) => {
- if (event instanceof NavigationEnd) {
- this.previousUrl = this.currentUrl;
- this.currentUrl = event.url;
- }
- });
- }
-
- public getPreviousUrl(): string {
- return this.previousUrl;
- }
-}
diff --git a/lib/core/services/public-api.ts b/lib/core/services/public-api.ts
index 462642fb8f..60dae7989d 100644
--- a/lib/core/services/public-api.ts
+++ b/lib/core/services/public-api.ts
@@ -55,5 +55,4 @@ export * from './jwt-helper.service';
export * from './download-zip.service';
export * from './lock.service';
export * from './automation.service';
-export * from './previous-route.service';
export * from './automation.service';
diff --git a/lib/core/viewer/components/pdfViewer-password-dialog.html b/lib/core/viewer/components/pdfViewer-password-dialog.html
index dbb92bcbc0..a6c488cfc3 100644
--- a/lib/core/viewer/components/pdfViewer-password-dialog.html
+++ b/lib/core/viewer/components/pdfViewer-password-dialog.html
@@ -19,7 +19,7 @@
-
+