/*! * @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 * as path from 'path'; import { BrowserActions, BrowserVisibility, TogglePage } from '@alfresco/adf-testing'; import { browser, by, element, ElementFinder } from 'protractor'; export class VersionManagePage { togglePage = new TogglePage(); showNewVersionButton = element(by.id('adf-show-version-upload-button')); uploadNewVersionInput = element(by.css('adf-upload-version-button input[data-automation-id="upload-single-file"]')); uploadNewVersionButton = element(by.css('adf-upload-version-button')); uploadNewVersionContainer = element(by.id('adf-new-version-uploader-container')); cancelButton = element(by.id('adf-new-version-cancel')); majorRadio = element(by.id('adf-new-version-major')); minorRadio = element(by.id('adf-new-version-minor')); commentText = element(by.id('adf-new-version-text-area')); readOnlySwitch = element(by.id('adf-version-manager-switch-readonly')); downloadSwitch = element(by.id('adf-version-manager-switch-download')); commentsSwitch = element(by.id('adf-version-manager-switch-comments')); async checkUploadNewVersionsButtonIsDisplayed(): Promise { await BrowserVisibility.waitUntilElementIsVisible(this.showNewVersionButton); } async checkCancelButtonIsDisplayed(): Promise { await BrowserVisibility.waitUntilElementIsVisible(this.cancelButton); } async uploadNewVersionFile(fileLocation: string): Promise { await BrowserVisibility.waitUntilElementIsPresent(this.uploadNewVersionInput); await this.uploadNewVersionInput.sendKeys(path.resolve(path.join(browser.params.testConfig.main.rootPath, fileLocation))); await BrowserVisibility.waitUntilElementIsVisible(this.showNewVersionButton); } async getFileVersionName(version: string): Promise { const fileElement = element(by.css(`[id="adf-version-list-item-name-${version}"]`)); return BrowserActions.getText(fileElement); } async checkFileVersionExist(version: string): Promise { const fileVersion = element(by.id(`adf-version-list-item-version-${version}`)); await BrowserVisibility.waitUntilElementIsVisible(fileVersion); } async checkFileVersionNotExist(version: string): Promise { const fileVersion = element(by.id(`adf-version-list-item-version-${version}`)); await BrowserVisibility.waitUntilElementIsNotVisible(fileVersion); } async getFileVersionComment(version: string): Promise { const fileComment = element(by.id(`adf-version-list-item-comment-${version}`)); return BrowserActions.getText(fileComment); } async getFileVersionDate(version: string): Promise { const fileDate = element(by.id(`adf-version-list-item-date-${version}`)); return BrowserActions.getText(fileDate); } async enterCommentText(text: string): Promise { await BrowserActions.clearSendKeys(this.commentText, text); } async clickMajorChange(): Promise { const radioMajor = element(by.id(`adf-new-version-major`)); await BrowserActions.click(radioMajor); } async clickMinorChange(): Promise { const radioMinor = element(by.id(`adf-new-version-minor`)); await BrowserActions.click(radioMinor); } /** * disables readOnly */ async disableReadOnly(): Promise { await this.togglePage.disableToggle(this.readOnlySwitch); } /** * enables readOnly */ async enableReadOnly(): Promise { await this.togglePage.enableToggle(this.readOnlySwitch); } /** * disables download */ async disableDownload(): Promise { await this.togglePage.disableToggle(this.downloadSwitch); } /** * enables download */ async enableDownload(): Promise { await this.togglePage.enableToggle(this.downloadSwitch); } /** * * disables comments */ async disableComments(): Promise { await this.togglePage.disableToggle(this.commentsSwitch); } /** * enables comments */ async enableComments(): Promise { await this.togglePage.enableToggle(this.commentsSwitch); } async clickActionButton(version: string): Promise { await BrowserActions.click(element(by.id(`adf-version-list-action-menu-button-${version}`))); await BrowserVisibility.waitUntilElementIsVisible(element(by.css('.cdk-overlay-container .mat-menu-content'))); } async clickAcceptConfirm(): Promise { await BrowserActions.click(element(by.id(`adf-confirm-accept`))); } async clickCancelConfirm(): Promise { await BrowserActions.click(element(by.id(`adf-confirm-cancel`))); } async closeActionsMenu(): Promise { await BrowserActions.closeMenuAndDialogs(); } async closeDisabledActionsMenu(): Promise { const container = element(by.css('div.cdk-overlay-backdrop.cdk-overlay-transparent-backdrop.cdk-overlay-backdrop-showing')); await BrowserActions.closeDisabledMenu(); await BrowserVisibility.waitUntilElementIsNotVisible(container); } async downloadFileVersion(version: string): Promise { await this.clickActionButton(version); const downloadButton = element(by.id(`adf-version-list-action-download-${version}`)); await BrowserActions.click(downloadButton); await BrowserVisibility.waitUntilElementIsNotVisible(downloadButton); } async deleteFileVersion(version: string): Promise { await this.clickActionButton(version); const deleteButton = element(by.id(`adf-version-list-action-delete-${version}`)); await BrowserActions.click(deleteButton); } async restoreFileVersion(version: string): Promise { await this.clickActionButton(version); const restoreButton = element(by.id(`adf-version-list-action-restore-${version}`)); await BrowserActions.click(restoreButton); } async viewFileVersion(version): Promise { await this.clickActionButton(version); const viewButton: ElementFinder = element(by.id(`adf-version-list-action-view-${version}`)); await BrowserActions.click(viewButton); } async checkActionsArePresent(version: string): Promise { await BrowserVisibility.waitUntilElementIsVisible(element(by.id(`adf-version-list-action-download-${version}`))); await BrowserVisibility.waitUntilElementIsVisible(element(by.id(`adf-version-list-action-delete-${version}`))); await BrowserVisibility.waitUntilElementIsVisible(element(by.id(`adf-version-list-action-restore-${version}`))); } async closeVersionDialog(): Promise { await BrowserActions.closeMenuAndDialogs(); await BrowserVisibility.waitUntilElementIsNotVisible(this.uploadNewVersionContainer); } }