import { by , browser } from 'protractor' ; import { BrowserActions , Logger } from '@alfresco/adf-testing' ; import { Component } from '../component' ; import { waitForPresence , waitForStaleness , typeText } from '../../utilities/utils' ; export class LibraryMetadata extends Component { metadataTabContent = this . byCss ( '.mat-card-content' ) ; metadataTabAction = this . byCss ( '.mat-card-actions .mat-button' ) ; fieldLabelWrapper = this . byCss ( '.mat-form-field-label-wrapper' ) ; fieldInput = this . byCss ( '.mat-input-element' ) ; visibilityDropDown = this . component . element ( by . css ( '.mat-select' ) ) ; visibilityPublic = this . byCssText ( '.mat-option .mat-option-text' , 'Public' , browser ) ; visibilityPrivate = this . byCssText ( '.mat-option .mat-option-text' , 'Private' , browser ) ; visibilityModerated = this . byCssText ( '.mat-option .mat-option-text' , 'Moderated' , browser ) ; hint = this . byCss ( '.mat-hint' ) ; error = this . byCss ( '.mat-error' ) ; constructor ( ancestor ? ) { super ( 'app-library-metadata-form' , ancestor ) ; } private getLabelWrapper ( label ) { return this . byCssText ( '.mat-form-field-label-wrapper' , label ) ; } private getFieldByName ( fieldName ) { const wrapper = this . getLabelWrapper ( fieldName ) ; return wrapper . element ( by . xpath ( '..' ) ) . element ( by . css ( '.mat-input-element' ) ) ; } private async isFieldDisplayed ( fieldName ) { return browser . isElementPresent ( this . getFieldByName ( fieldName ) ) ; } private async isInputEnabled ( fieldName ) { return this . getFieldByName ( fieldName ) . isEnabled ( ) ; } private async getValueOfField ( fieldName ) { return this . getFieldByName ( fieldName ) . getText ( ) ; } private async enterTextInInput ( fieldName , text ) { const input = this . getFieldByName ( fieldName ) ; await typeText ( input , text ) ; } private getButton ( button ) { return this . byCssText ( '.mat-card-actions .mat-button' , button ) ; } private async isButtonDisplayed ( button ) { return browser . isElementPresent ( this . getButton ( button ) ) ; } private async isButtonEnabled ( button ) { return this . getButton ( button ) . isEnabled ( ) ; } private async clickButton ( button ) { await BrowserActions . click ( this . getButton ( button ) ) ; } async waitForVisibilityDropDownToClose ( ) { await waitForStaleness ( browser . $ ( '.mat-option .mat-option-text' ) ) ; } async isMessageDisplayed ( ) { return browser . isElementPresent ( this . hint ) ; } async getMessage ( ) { return this . hint . getText ( ) ; } async isErrorDisplayed ( ) { return browser . isElementPresent ( this . error ) ; } async getError ( ) { return this . error . getText ( ) ; } async isNameDisplayed ( ) { return this . isFieldDisplayed ( 'Name' ) ; } async isNameEnabled ( ) { return this . isInputEnabled ( 'Name' ) ; } async getName ( ) { return this . getValueOfField ( 'Name' ) ; } async enterName ( name ) { await this . enterTextInInput ( 'Name' , name ) ; } async isDescriptionDisplayed ( ) { return this . isFieldDisplayed ( 'Description' ) ; } async isDescriptionEnabled ( ) { return this . isInputEnabled ( 'Description' ) ; } async getDescription ( ) { return this . getValueOfField ( 'Description' ) ; } async enterDescription ( desc ) { await this . enterTextInInput ( 'Description' , desc ) ; } async isVisibilityEnabled ( ) { const wrapper = this . getLabelWrapper ( 'Visibility' ) ; const field = wrapper . element ( by . xpath ( '..' ) ) . element ( by . css ( '.mat-select' ) ) ; return field . isEnabled ( ) ; } async isVisibilityDisplayed ( ) { return this . isFieldDisplayed ( 'Visibility' ) ; } async getVisibility ( ) { return this . getValueOfField ( 'Visibility' ) ; } async setVisibility ( visibility ) { const val = visibility . toLowerCase ( ) ; await BrowserActions . click ( this . visibilityDropDown ) ; await waitForPresence ( this . visibilityDropDown ) ; if ( val === 'public' ) { await BrowserActions . click ( this . visibilityPublic ) ; } else if ( val === 'private' ) { await BrowserActions . click ( this . visibilityPrivate ) ; } else if ( val === 'moderated' ) { await BrowserActions . click ( this . visibilityModerated ) ; } else { Logger . error ( '----- invalid visibility' , val ) ; } await this . waitForVisibilityDropDownToClose ( ) ; } async isLibraryIdDisplayed ( ) { return this . isFieldDisplayed ( 'Library ID' ) ; } async isLibraryIdEnabled ( ) { return this . isInputEnabled ( 'Library ID' ) ; } async getLibraryId ( ) { return this . getValueOfField ( 'Library ID' ) ; } async isEditLibraryPropertiesEnabled ( ) { return this . isButtonEnabled ( 'Edit' ) ; } async isEditLibraryPropertiesDisplayed ( ) { return this . isButtonDisplayed ( 'Edit' ) ; } async clickEditLibraryProperties ( ) { await this . clickButton ( 'Edit' ) ; } async isUpdateEnabled ( ) { return this . isButtonEnabled ( 'Update' ) ; } async isUpdateDisplayed ( ) { return this . isButtonDisplayed ( 'Update' ) ; } async clickUpdate ( ) { await this . clickButton ( 'Update' ) ; } async isCancelEnabled ( ) { return this . isButtonEnabled ( 'Cancel' ) ; } async isCancelDisplayed ( ) { return this . isButtonDisplayed ( 'Cancel' ) ; } async clickCancel ( ) { await this . clickButton ( 'Cancel' ) ; } }