import { by , browser , until } from 'protractor' ; import { Component } from '../component' ; import { BROWSER_WAIT_TIMEOUT } from '../../configs' ; import { typeText } from '../../utilities/utils' ; import { BrowserActions , BrowserVisibility } from '@alfresco/adf-testing' ; export class CommentsTab extends Component { commentsContainer = this . byCss ( '.adf-comments-container' ) ; commentsHeader = this . byCss ( '.adf-comments-header' ) ; commentTextarea = this . byCss ( '.adf-comments-input-container textarea' ) ; addCommentButton = this . byCss ( 'button.adf-comments-input-add' ) ; commentListItem = by . css ( '.adf-comment-list-item' ) ; commentUserAvatar = by . id ( 'comment-user-icon' ) ; commentUser = by . id ( 'comment-user' ) ; commentText = by . id ( 'comment-message' ) ; commentTime = by . id ( 'comment-time' ) ; constructor ( ancestor ? ) { super ( 'adf-comments' , ancestor ) ; } async waitForCommentsContainer ( ) { await BrowserVisibility . waitUntilElementIsVisible ( this . commentsContainer ) ; } async getCommentsTabHeaderText ( ) { return this . commentsHeader . getText ( ) ; } async isCommentTextAreaDisplayed ( ) { return browser . isElementPresent ( this . commentTextarea ) ; } async isAddCommentButtonEnabled ( ) { const present = await browser . isElementPresent ( this . addCommentButton ) ; if ( present ) { return this . addCommentButton . isEnabled ( ) ; } return false ; } private async getCommentListItem ( ) { return browser . wait ( until . elementLocated ( this . commentListItem ) , BROWSER_WAIT_TIMEOUT / 2 ) ; } async getCommentById ( commentId ? ) { if ( commentId ) { return browser . wait ( until . elementLocated ( by . id ( `adf-comment-${ commentId }` ) ) , BROWSER_WAIT_TIMEOUT / 2 ) ; } return this . getCommentListItem ( ) ; } async isCommentDisplayed ( commentId ? ) { return browser . isElementPresent ( await this . getCommentById ( commentId ) ) ; } async isCommentUserAvatarDisplayed ( commentId ? ) { const commentElement = await this . getCommentById ( commentId ) ; return browser . isElementPresent ( commentElement . findElement ( this . commentUserAvatar ) ) ; } async getCommentText ( commentId ? ) { const commentElement = await this . getCommentById ( commentId ) ; const message = await commentElement . findElement ( this . commentText ) ; return message . getText ( ) ; } async getCommentUserName ( commentId ? ) { const commentElement = await this . getCommentById ( commentId ) ; const user = await commentElement . findElement ( this . commentUser ) ; return user . getText ( ) ; } async getCommentTime ( commentId ? ) { const commentElement = await this . getCommentById ( commentId ) ; const time = await commentElement . findElement ( this . commentTime ) ; return time . getText ( ) ; } async getNthCommentId ( index ) { const list = this . allByCss ( '.adf-comment-list-item' ) ; return list . get ( index - 1 ) . getAttribute ( 'id' ) ; } async typeComment ( text ) { await typeText ( this . commentTextarea , text ) ; } async clickAddButton ( ) { await BrowserActions . click ( this . addCommentButton ) ; } async getCommentTextFromTextArea ( ) { return BrowserActions . getInputValue ( this . commentTextarea ) ; } }