import * as util from 'util'; import { Button, Label, WebElement } from '@contour/fet/lib/elements'; import { ContourBasePage } from '../../base/basePage'; import { P2P_SPECIAL_VALUE } from '../../enum/p2p'; import locator from './p2pMessageView.locator'; export default class P2PMessageView extends ContourBasePage { constructor(url?: string) { super(locator, url); } getMessageViewRoot() { return new WebElement(this.getLocatorAsString('viewRoot')); } getHeaderSubject() { return new WebElement(this.getLocatorAsString('viewRoot') + this.getLocatorAsString('header.subject')); } getHeaderRecipients() { return new Label(this.getLocatorAsString('viewRoot') + this.getLocatorAsString('header.recipients')); } getHeaderRecipientCount() { return new Label(this.getLocatorAsString('viewRoot') + this.getLocatorAsString('header.recipientCount')); } getHeaderRecipientIcon() { return new WebElement(this.getLocatorAsString('viewRoot') + this.getLocatorAsString('header.recipientIcon')); } getHeaderFilesTab() { return new WebElement(this.getLocatorAsString('filesTab')); } getHeaderMessageTab() { return new WebElement(this.getLocatorAsString('messageTab')); } async getAllBubbles() { return await browser.$$(this.getLocatorAsString('allMessageBubbles')); } async getAllMyBubbles() { return await browser.$$(this.getLocatorAsString('allMyBubbles')); } async getAllOtherBubbles() { return await browser.$$(this.getLocatorAsString('allOtherBubbles')); } getBubbleByIndex(index) { let selector = this.getLocatorAsString('body.root'); selector += this.getLocatorAsString('body.bubbleByIndex').replace(P2P_SPECIAL_VALUE.ORDER, index); return new WebElement(selector); } getBubbleAttachedFileDownloadButtonByMessageOnly(message: string, fileName: string) { return new WebElement( this.getLocatorAsString('downloadIconForAttachedFileAtMyMessage') .replace(P2P_SPECIAL_VALUE.MESSAGE, message) .replace(P2P_SPECIAL_VALUE.FILE_NAME, fileName) + ' | ' + this.getLocatorAsString('downloadIconForAttachedFileAtOtherMessage') .replace(P2P_SPECIAL_VALUE.MESSAGE, message) .replace(P2P_SPECIAL_VALUE.FILE_NAME, fileName) ); } getBubbleByMessageOnly(message) { const selector = this.getLocatorAsString('messageBubblesByMessage').replace(P2P_SPECIAL_VALUE.MESSAGE, message); return new WebElement(selector); } getBubbleByMessage(bubbleType, message) { let selector = this.getLocatorAsString('body.root'); if (bubbleType === P2P_SPECIAL_VALUE.MY_BUBBLE) { selector += this.getLocatorAsString('body.myBubbleByMessage').replace(P2P_SPECIAL_VALUE.MESSAGE, message); } else { selector += this.getLocatorAsString('body.otherBubbleByMessage').replace(P2P_SPECIAL_VALUE.MESSAGE, message); } return new WebElement(selector); } getBubbleMessageByIndex(index) { return new Label(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.message')); } getBubbleSenderByIndex(index) { return new Label(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.sender')); } getBubbleDatetimeFromBubble(bubble) { return new Label(bubble.selector + this.getLocatorAsString('body.child.dateTime')); } getBubbleDatetimeByIndex(index) { return new Label(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.dateTime')); } getBubbleVerifyButtonByIndex(index) { return new Button(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.verifyButton')); } getBubbleRejectButtonByIndex(index) { return new Button(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.rejectButton')); } getBubbleAlertIconByIndex(index) { return new WebElement(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.alertIcon')); } getBubbleEditButtonByIndex(index) { return new Button(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.editButton')); } getBubbleEditButtonByMessage(bubbleType, message) { return new Button( this.getBubbleByMessage(bubbleType, message).selector + this.getLocatorAsString('body.child.editButton') ); } getBubbleDiscardButtonByIndex(index) { return new Button(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.discardButton')); } getBubbleDiscardButtonByMessage(bubbleType, message) { return new Button( this.getBubbleByMessage(bubbleType, message).selector + this.getLocatorAsString('body.child.discardButton') ); } getBubbleVerifyButtonByMessage(bubbleType, message) { return new Button( this.getBubbleByMessage(bubbleType, message).selector + this.getLocatorAsString('body.child.verifyButton') ); } getBubbleApproveButtonByMessage(bubbleType, message) { return new Button( this.getBubbleByMessage(bubbleType, message).selector + this.getLocatorAsString('body.child.approveButton') ); } getBubbleApproveButtonByIndex(index) { return new Button(this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.approveButton')); } getBubbleRejectButtonByMessage(bubbleType, message) { return new Button( this.getBubbleByMessage(bubbleType, message).selector + this.getLocatorAsString('body.child.rejectButton') ); } async getBubbleAttachedFilesByIndex(index) { const filesSelector = this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.attachedFileList') + this.getLocatorAsString('body.child.attachedFile'); return await $$(filesSelector); } getBubbleRejectLabel(index) { const rejectLabel = this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.rejectLabel'); return new Label(rejectLabel); } getBububleRejectComment(index) { const rejectComment = this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.rejectComment'); return new WebElement(rejectComment); } getAttachedFileByIndex(index, fileName) { return new WebElement( this.getBubbleByIndex(index).selector + this.getLocatorAsString('body.child.attachedFileList') + this.getLocatorAsString('body.child.attachedFileName').replace(P2P_SPECIAL_VALUE.FILE_NAME, fileName) ); } getMessagePendingBar(index) { return new WebElement( this.getLocatorAsString('body.root') + this.getLocatorAsString('body.pendingBar').replace(P2P_SPECIAL_VALUE.ORDER, index) ); } async getAttachedFilesAtFilesTab() { const filesSelector = this.getLocatorAsString('fileRows'); return await browser.$$(filesSelector); } getAttachedFileAtFilesTabByIndex(index) { const fileSelector = util.format('%s[%d]', this.getLocatorAsString('fileRows'), index); return new WebElement(fileSelector); } getAttachedFileAtFilesTabByName(fileName) { return new WebElement(this.getLocatorAsString('fileRowForAFile').replace(P2P_SPECIAL_VALUE.FILE_NAME, fileName)); } getSentDateAtFilesTabByIndex(index) { const selector = this.getAttachedFileAtFilesTabByIndex(index).selector + this.getLocatorAsString('fileRowChild.sentDate'); return new WebElement(selector); } }