import { by , browser } from 'protractor' ; import { GenericDialog } from '../dialog/generic-dialog' ; import { isPresentAndEnabled , typeText } from '../../utilities/utils' ; import { BrowserVisibility } from '@alfresco/adf-testing' ; export class PasswordDialog extends GenericDialog { closeButton = this . childElement ( by . css ( '[data-automation-id="adf-password-dialog-close"]' ) ) ; submitButton = this . childElement ( by . css ( '[data-automation-id="adf-password-dialog-submit"]' ) ) ; passwordInput = this . childElement ( by . css ( 'input[type="Password"]' ) ) ; errorMessage = this . childElement ( by . css ( '.mat-error' ) ) ; constructor ( ) { super ( 'adf-pdf-viewer-password-dialog' ) ; } async waitForDialogToOpen ( ) { await BrowserVisibility . waitUntilElementIsClickable ( this . passwordInput ) ; } async isDialogOpen ( ) { try { await this . waitForDialogToOpen ( ) ; return true ; } catch ( error ) { return false ; } } async isCloseEnabled ( ) { return isPresentAndEnabled ( this . closeButton ) ; } async isSubmitEnabled ( ) { return isPresentAndEnabled ( this . submitButton ) ; } async isPasswordInputDisplayed ( ) { const present = await browser . isElementPresent ( this . passwordInput ) ; if ( present ) { return this . passwordInput . isDisplayed ( ) ; } else { return false ; } } async isErrorDisplayed ( ) { try { await this . waitForDialogToOpen ( ) ; return ( await this . errorMessage . isPresent ( ) ) && ( await this . errorMessage . isDisplayed ( ) ) ; } catch ( error ) { return false ; } } async getErrorMessage ( ) { if ( await this . isErrorDisplayed ( ) ) { return this . errorMessage . getText ( ) ; } return '' ; } async enterPassword ( password ) { await typeText ( this . passwordInput , password ) ; } }