import { Button, Input, Label, WebElement } from '@contour/fet/lib/elements'; import { ContourBasePage } from '../../base/basePage'; import { ContourFileUpload } from '../../elements/contourFileUpload'; import { P2P_MESSAGE_TYPE, P2P_SPECIAL_VALUE } from '../../enum/p2p'; import locator from './p2pMessage.locator'; export default class P2PMessage extends ContourBasePage { constructor(url?: string) { super(locator, url); } getMessageTypeDropdown() { return new WebElement(this.getLocatorAsString('messageTypeDropdown')); } getRecipientsDropdown() { return new WebElement(this.getLocatorAsString('recipientsDropdown')); } getRecipientsOption(companyName) { return new WebElement( this.getLocatorAsString('childRecipeint').replace(P2P_SPECIAL_VALUE.COMPANY_NAME, companyName) ); } getFormMessageTextArea() { return new Input(this.getLocatorAsString('formMessageTextArea')); } getSubjectTextArea() { return new Input(this.getLocatorAsString('subjectTextArea')); } getAttachButton() { return new Button(this.getLocatorAsString('attachButton')); } getSendButton() { return new Button(this.getLocatorAsString('sendButton')); } getSendPopupConfirmButton() { return new Button(this.getLocatorAsString('sendPopupConfirmButton')); } getSendPopupCancelButton() { return new Button(this.getLocatorAsString('sendPopupCancelButton')); } getAttachFileUpload() { return new ContourFileUpload(this.getLocatorAsString('attachButton')); } getCancelButton() { return new Button(this.getLocatorAsString('cancelButton')); } async selectP2PThreadType(threadType) { await this.getMessageTypeDropdown().clickElement(); switch (threadType) { case P2P_MESSAGE_TYPE.GENERAL: await this.getGeneralMessageType().clickElement(); break; case P2P_MESSAGE_TYPE.NOTICE_OF_DISCREPANCY: await this.getNoticeOfDiscrepancyType().clickElement(); break; case P2P_MESSAGE_TYPE.DC_CANCEL: await this.getRequestForCancellationType().clickElement(); break; } } async checkIsP2PCreationSectionExisting(falsecase = false) { if (falsecase) { await this.getFormMessageTextArea().checkIsExisting(falsecase); await this.getAttachButton().checkIsExisting(falsecase); await this.getSendButton().checkIsExisting(falsecase); } await this.getMessageTypeDropdown().checkIsExisting(falsecase); await this.getSubjectTextArea().checkIsExisting(falsecase); await this.getRecipientsDropdown().checkIsExisting(falsecase); } hasExactDisplayNameParties(companyNames, excludedCompanyName) { companyNames.forEach(async (companyName) => { if (companyName !== excludedCompanyName) { const companyNameLabel = new Label( this.getLocatorAsString('recipientsDropdown') + this.getLocatorAsString('childRecipeint').replace(P2P_SPECIAL_VALUE.COMPANY_NAME, companyName) ); await companyNameLabel.checkIsExisting(); } }); } hasExactAttachedFiles(attachments) { attachments.forEach(async (fileName) => { const fileNameLabel = new Label( this.getLocatorAsString('displayAttachFilesRoot') + this.getLocatorAsString('displayAttachFileChild').replace(P2P_SPECIAL_VALUE.FILE_NAME, fileName) ); await fileNameLabel.checkIsExisting(); }); } getCloseButtonAtAttachedFile(fileName) { return new Button( this.getLocatorAsString('removeButtonAtAttachFileChild').replace(P2P_SPECIAL_VALUE.FILE_NAME, fileName) ); } getNoticeOfDiscrepancyType() { return new Button(this.getLocatorAsString('noticeOfDiscrepancyType')); } getGeneralMessageType() { return new Button(this.getLocatorAsString('generalMessageType')); } getRequestForCancellationType() { return new Button(this.getLocatorAsString('requestForCancellationType')); } getAdviceOfReimbursementOrPaymentType() { return new Button(this.getLocatorAsString('adviceOfReimbursementOrPaymentType')); } getAuthorisationToPayAcceptOrNegotiateType() { return new Button(this.getLocatorAsString('authorisationToPayAcceptOrNegotiateType')); } getAdviceOfDischargeType() { return new Button(this.getLocatorAsString('adviceOfDischargeType')); } getAdviceOfRefusalType() { return new Button(this.getLocatorAsString('adviceOfRefusalType')); } }