/*! * @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 path = require('path'); import { BrowserActions, BrowserVisibility, TogglePage } from '@alfresco/adf-testing'; import { browser, by, element, ElementFinder } from 'protractor'; export class VersionManagePage { togglePage: TogglePage = new TogglePage(); showNewVersionButton: ElementFinder = element(by.id('adf-show-version-upload-button')); uploadNewVersionInput: ElementFinder = element(by.css('adf-upload-version-button input[data-automation-id="upload-single-file"]')); uploadNewVersionButton: ElementFinder = element(by.css('adf-upload-version-button')); uploadNewVersionContainer: ElementFinder = element(by.id('adf-new-version-uploader-container')); cancelButton: ElementFinder = element(by.id('adf-new-version-cancel')); majorRadio: ElementFinder = element(by.id('adf-new-version-major')); minorRadio: ElementFinder = element(by.id('adf-new-version-minor')); commentText: ElementFinder = element(by.id('adf-new-version-text-area')); readOnlySwitch: ElementFinder = element(by.id('adf-version-manager-switch-readonly')); downloadSwitch: ElementFinder = element(by.id('adf-version-manager-switch-download')); commentsSwitch: ElementFinder = 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): 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): Promise { const fileElement: ElementFinder = element(by.css(`[id="adf-version-list-item-name-${version}"]`)); return BrowserActions.getText(fileElement); } async checkFileVersionExist(version): Promise { const fileVersion: ElementFinder = element(by.id(`adf-version-list-item-version-${version}`)); await BrowserVisibility.waitUntilElementIsVisible(fileVersion); } async checkFileVersionNotExist(version): Promise { const fileVersion: ElementFinder = element(by.id(`adf-version-list-item-version-${version}`)); await BrowserVisibility.waitUntilElementIsNotVisible(fileVersion); } async getFileVersionComment(version): Promise { const fileComment: ElementFinder = element(by.id(`adf-version-list-item-comment-${version}`)); return BrowserActions.getText(fileComment); } async getFileVersionDate(version): Promise { const fileDate: ElementFinder = element(by.id(`adf-version-list-item-date-${version}`)); return BrowserActions.getText(fileDate); } async enterCommentText(text): Promise { await BrowserActions.clearSendKeys(this.commentText, text); } async clickMajorChange(): Promise { const radioMajor: ElementFinder = element(by.id(`adf-new-version-major`)); await BrowserActions.click(radioMajor); } async clickMinorChange(): Promise { const radioMinor: ElementFinder = 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): 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: ElementFinder = 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): Promise { await this.clickActionButton(version); const downloadButton: ElementFinder = element(by.id(`adf-version-list-action-download-${version}`)); await BrowserActions.click(downloadButton); await BrowserVisibility.waitUntilElementIsNotVisible(downloadButton); } async deleteFileVersion(version): Promise { await this.clickActionButton(version); const deleteButton: ElementFinder = element(by.id(`adf-version-list-action-delete-${version}`)); await BrowserActions.click(deleteButton); } async restoreFileVersion(version): Promise { await this.clickActionButton(version); const restoreButton: ElementFinder = element(by.id(`adf-version-list-action-restore-${version}`)); await BrowserActions.click(restoreButton); } async checkActionsArePresent(version): 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); } }