[ACA-4265]Refactor attachFileFromLocal method

* Refactor attachFileFromLocal method
This commit is contained in:
Cristina Jalba
2021-02-07 11:18:10 +02:00
committed by GitHub
parent f4976a1949
commit 60c1ea9fe6
8 changed files with 113 additions and 22 deletions

View File

@@ -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<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.dialog);
}
@@ -140,25 +151,27 @@ export class ContentNodeSelectorDialogPage {
await this.clickMoveCopyButton();
}
async attachFileFromLocal(fileName: string, fileLocation: string): Promise<void> {
async checkFileServerTabIsLoaded(): Promise<void> {
await this.checkDialogIsDisplayed();
await this.dataTable.waitForTableBody();
await this.breadcrumbDropdownPage.checkCurrentFolderIsDisplayed();
await this.breadcrumbDropdown.checkCurrentFolderIsDisplayed();
}
async attachFilesFromLocal(files: FileModel[]): Promise<void> {
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();
}

View File

@@ -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<void> {
await BrowserVisibility.waitUntilElementIsPresent(this.uploadButton);
for ( const file of files) {
await this.uploadButton.sendKeys(file.getLocation());
}
}
async isButtonNotDisplayed(): Promise<boolean> {
try {
await BrowserVisibility.waitUntilElementIsNotVisible(this.uploadButton);
return true;
} catch (e) {
return false;
}
}
}

View File

@@ -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;
}
}

View File

@@ -17,4 +17,5 @@
export * from './user.model';
export * from './application-model';
export * from './file.model';
export * from './tenant';

View File

@@ -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<void> {
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<void> {

View File

@@ -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<void> {
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<void> {
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<void> {
for (const fileName of filesName) {
await this.checkFileIsAttached(fileName);
}
}
async checkFileIsNotAttached(name): Promise<void> {
const fileAttached = this.widget.element(this.filesListLocator).element(by.cssContainingText('mat-list-item span ', name));
await BrowserVisibility.waitUntilElementIsNotVisible(fileAttached);