From 60c1ea9fe614d5bcbc85785b2df0fa4df304bf54 Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Sun, 7 Feb 2021 11:18:10 +0200 Subject: [PATCH] [ACA-4265]Refactor attachFileFromLocal method * Refactor attachFileFromLocal method --- .../start-task-form-cloud.e2e.ts | 2 +- .../components/document-list.component.ts | 2 +- .../content-node-selector-dialog.page.ts | 33 ++++++++++----- .../pages/upload-button.page.ts | 41 +++++++++++++++++++ lib/testing/src/lib/core/models/file.model.ts | 36 ++++++++++++++++ lib/testing/src/lib/core/models/public-api.ts | 1 + .../lib/core/pages/form/widgets/tab.page.ts | 6 ++- .../widget/attach-file-widget-cloud.page.ts | 14 +++---- 8 files changed, 113 insertions(+), 22 deletions(-) create mode 100644 lib/testing/src/lib/content-services/pages/upload-button.page.ts create mode 100644 lib/testing/src/lib/core/models/file.model.ts diff --git a/e2e/process-services-cloud/start-task-form-cloud.e2e.ts b/e2e/process-services-cloud/start-task-form-cloud.e2e.ts index 2a303c33f7..1ffc62e376 100644 --- a/e2e/process-services-cloud/start-task-form-cloud.e2e.ts +++ b/e2e/process-services-cloud/start-task-form-cloud.e2e.ts @@ -316,7 +316,7 @@ describe('Start Task Form', () => { const localFileWidget = await widget.attachFileWidgetCloud('Attachlocalfile'); await localFileWidget.clickAttachContentFile('Attachlocalfile'); - await contentNodeSelectorDialogPage.attachFileFromLocal(pdfFile.name, pdfFile.location); + await contentNodeSelectorDialogPage.attachFilesFromLocal([pdfFile]); await localFileWidget.checkFileIsAttached(pdfFile.name); await localFileWidget.removeFile(pdfFile.name); await localFileWidget.checkFileIsNotAttached(pdfFile.name); diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.ts b/lib/content-services/src/lib/document-list/components/document-list.component.ts index c3081cb7c8..d7485d51e7 100644 --- a/lib/content-services/src/lib/document-list/components/document-list.component.ts +++ b/lib/content-services/src/lib/document-list/components/document-list.component.ts @@ -924,7 +924,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte } onPreselectNodes() { - if (this.data.hasPreselectedRows()) { + if (this.data?.hasPreselectedRows()) { const preselectedNodes = [...this.isSingleSelectionMode() ? [this.data.getPreselectedRows()[0]] : this.data.getPreselectedRows()]; const selectedNodes = [...this.selection, ...preselectedNodes]; diff --git a/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts b/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts index 50b5837739..6016dd16a9 100644 --- a/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts +++ b/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { by, element, browser } from 'protractor'; +import { by, element } from 'protractor'; import { DocumentListPage } from '../pages/document-list.page'; import { BrowserVisibility } from '../../core/utils/browser-visibility'; import { BrowserActions } from '../../core/utils/browser-actions'; @@ -23,6 +23,8 @@ import { DropdownPage } from '../../core/pages/material/dropdown.page'; import { BreadcrumbDropdownPage } from '../pages/breadcrumb/breadcrumb-dropdown.page'; import { Logger } from '../../core/utils/logger'; import { TabPage } from '../../core/pages/form/widgets/tab.page'; +import { UploadButtonPage } from '../pages/upload-button.page'; +import { FileModel } from '../../core/models/file.model'; export class ContentNodeSelectorDialogPage { dialog = element(by.css(`adf-content-node-selector`)); @@ -36,12 +38,21 @@ export class ContentNodeSelectorDialogPage { contentList = new DocumentListPage(this.dialog); dataTable = this.contentList.dataTablePage(); siteListDropdown = new DropdownPage(this.dialog.element(by.css(`mat-select[data-automation-id='site-my-files-option']`))); - breadcrumbDropdownPage = new BreadcrumbDropdownPage(); + breadcrumbDropdown = new BreadcrumbDropdownPage(); tabPage: TabPage = new TabPage(); + uploadButtonComponent = new UploadButtonPage(); uploadFromLocalTabName = 'Upload from your device'; repositoryTabName = 'Repository'; + breadcrumbDropdownPage(): BreadcrumbDropdownPage { + return this.breadcrumbDropdown; + } + + uploadButtonPage(): UploadButtonPage { + return this.uploadButtonComponent; + } + async checkDialogIsDisplayed(): Promise { await BrowserVisibility.waitUntilElementIsVisible(this.dialog); } @@ -140,25 +151,27 @@ export class ContentNodeSelectorDialogPage { await this.clickMoveCopyButton(); } - async attachFileFromLocal(fileName: string, fileLocation: string): Promise { + async checkFileServerTabIsLoaded(): Promise { await this.checkDialogIsDisplayed(); await this.dataTable.waitForTableBody(); - await this.breadcrumbDropdownPage.checkCurrentFolderIsDisplayed(); + await this.breadcrumbDropdown.checkCurrentFolderIsDisplayed(); + } + + async attachFilesFromLocal(files: FileModel[]): Promise { + await this.checkFileServerTabIsLoaded(); await this.tabPage.clickTabByLabel(this.uploadFromLocalTabName); - const uploadButton = element(by.css('adf-upload-button input')); - await BrowserVisibility.waitUntilElementIsPresent(uploadButton); - await browser.sleep(500); - await uploadButton.sendKeys(fileLocation); + await this.uploadButtonComponent.attachFiles(files); await this.tabPage.clickTabByLabel(this.repositoryTabName); await this.dataTable.waitForTableBody(); await this.dataTable.waitTillContentLoaded(); - await this.dataTable.checkRowContentIsDisplayed(fileName); + for ( const file of files) { + await this.dataTable.checkRowContentIsDisplayed(file.getName()); + } - await this.clickContentNodeSelectorResult(fileName); await this.checkCopyMoveButtonIsEnabled(); await this.clickMoveCopyButton(); } diff --git a/lib/testing/src/lib/content-services/pages/upload-button.page.ts b/lib/testing/src/lib/content-services/pages/upload-button.page.ts new file mode 100644 index 0000000000..b5c0d892bb --- /dev/null +++ b/lib/testing/src/lib/content-services/pages/upload-button.page.ts @@ -0,0 +1,41 @@ +/*! + * @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 { element, by } from 'protractor'; +import { BrowserVisibility } from '../../core/utils/browser-visibility'; +import { FileModel } from '../../core/models/file.model'; + +export class UploadButtonPage { + + uploadButton = element(by.css('adf-upload-button input')); + + async attachFiles(files: FileModel[]): Promise { + await BrowserVisibility.waitUntilElementIsPresent(this.uploadButton); + for ( const file of files) { + await this.uploadButton.sendKeys(file.getLocation()); + } + } + + async isButtonNotDisplayed(): Promise { + try { + await BrowserVisibility.waitUntilElementIsNotVisible(this.uploadButton); + return true; + } catch (e) { + return false; + } + } +} diff --git a/lib/testing/src/lib/core/models/file.model.ts b/lib/testing/src/lib/core/models/file.model.ts new file mode 100644 index 0000000000..ba11041475 --- /dev/null +++ b/lib/testing/src/lib/core/models/file.model.ts @@ -0,0 +1,36 @@ +/*! + * @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 { StringUtil } from '../utils/string.util'; + +export class FileModel { + + name = StringUtil.generateRandomString(); + location = StringUtil.generateRandomString(); + + constructor(details?: any) { + Object.assign(this, details); + } + + getName() { + return this.name; + } + + getLocation() { + return this.location; + } +} diff --git a/lib/testing/src/lib/core/models/public-api.ts b/lib/testing/src/lib/core/models/public-api.ts index 738cb4ae36..1441e09364 100644 --- a/lib/testing/src/lib/core/models/public-api.ts +++ b/lib/testing/src/lib/core/models/public-api.ts @@ -17,4 +17,5 @@ export * from './user.model'; export * from './application-model'; +export * from './file.model'; export * from './tenant'; diff --git a/lib/testing/src/lib/core/pages/form/widgets/tab.page.ts b/lib/testing/src/lib/core/pages/form/widgets/tab.page.ts index 05fceaf22c..63f13ead50 100644 --- a/lib/testing/src/lib/core/pages/form/widgets/tab.page.ts +++ b/lib/testing/src/lib/core/pages/form/widgets/tab.page.ts @@ -15,15 +15,17 @@ * limitations under the License. */ -import { by, element, browser } from 'protractor'; +import { by, element } from 'protractor'; import { BrowserActions, BrowserVisibility } from '../../../utils/public-api'; export class TabPage { + changeTabAnimation = element(by.css('div[class="mat-ripple-element"]')); + async clickTabByLabel(tabLabel): Promise { const user = element(by.cssContainingText('.mat-tab-label-content', tabLabel)); await BrowserActions.click(user); - await browser.sleep(300); + await BrowserVisibility.waitUntilElementIsNotVisible(this.changeTabAnimation); } async checkTabIsDisplayedByLabel(tabLabel): Promise { diff --git a/lib/testing/src/lib/process-services-cloud/pages/form/widget/attach-file-widget-cloud.page.ts b/lib/testing/src/lib/process-services-cloud/pages/form/widget/attach-file-widget-cloud.page.ts index c63949989d..74e33e6349 100644 --- a/lib/testing/src/lib/process-services-cloud/pages/form/widget/attach-file-widget-cloud.page.ts +++ b/lib/testing/src/lib/process-services-cloud/pages/form/widget/attach-file-widget-cloud.page.ts @@ -32,14 +32,6 @@ export class AttachFileWidgetCloudPage { this.widget = element(by.css(`adf-form-field div[id='field-${fieldId}-container']`)); } - async attachLocalFile(fileLocation: string): Promise { - const uploadButton = element(by.css('adf-upload-button input')); - await BrowserVisibility.waitUntilElementIsPresent(uploadButton); - await uploadButton.sendKeys(fileLocation); - await BrowserActions.click(uploadButton); - await BrowserVisibility.waitUntilElementIsPresent(uploadButton); - } - async clickAttachContentFile(fileId: string): Promise { const uploadButton = this.widget.element(by.css(`button[id=${fileId}]`)); await BrowserActions.click(uploadButton); @@ -60,6 +52,12 @@ export class AttachFileWidgetCloudPage { await BrowserVisibility.waitUntilElementIsVisible(fileAttached); } + async checkFilesAreAttached(filesName: string[]): Promise { + for (const fileName of filesName) { + await this.checkFileIsAttached(fileName); + } + } + async checkFileIsNotAttached(name): Promise { const fileAttached = this.widget.element(this.filesListLocator).element(by.cssContainingText('mat-list-item span ', name)); await BrowserVisibility.waitUntilElementIsNotVisible(fileAttached);