Skip to content

Commit

Permalink
added additional method on receive page
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebyt committed May 8, 2024
1 parent 9f9842d commit d8ac054
Showing 1 changed file with 145 additions and 24 deletions.
169 changes: 145 additions & 24 deletions packages/e2e-tests/pages/wallet/walletTab/receiveSubTab.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,34 @@ class GenerateURIModal extends BasePage {
locator: '//input[starts-with(@id, "amount--")]', // unfortunately, I didn't find a way to make a proper ID
method: 'xpath',
};
inputErrorMessageFieldLocator = {
locator: '//p[starts-with(@id, "amount--") and contains(@id, "-helper-text")]',
method: 'xpath',
};
// methods
/**
* Getting a receiver address from the disabled receiver input
* @returns {Promise<string>} A bech32 string format address
*/
async getReceiverAddress() {
this.logger.info(`ReceiveSubTab::GenerateURIModal::getReceiverAddress is called.`);
const address = await this.getAttribute(this.receiverAddressTextLocator, 'value');
this.logger.info(`ReceiveSubTab::GenerateURIModal::getReceiverAddress::address - "${address}"`);
return address
return address;
}
/**
* Entering amount to send
* @param {string} adaAmount Amount to send
*/
async enterReceiveAmount(adaAmount) {
this.logger.info(`ReceiveSubTab::GenerateURIModal::enterReceiveAmount is called.`);
await this.click(this.amountToSendInputLocator);
await this.input(this.amountToSendInputLocator, adaAmount);
}
/**
* Pressing the button "Generate".
* The method contains a waiter with 2 seconds timeout
*/
async generateLink() {
this.logger.info(`ReceiveSubTab::GenerateURIModal::generateLink is called.`);
const buttonIsEnabled = await this.customWaiter(
Expand All @@ -56,6 +72,31 @@ class GenerateURIModal extends BasePage {
throw new Error('The Continue button is disabled');
}
}
/**
* Getting the error message of amount input field
* @returns {Promise<string>}
*/
async getAmountErrorMessage() {
this.logger.info(`ReceiveSubTab::GenerateURIModal::getAmountErrorMessage is called.`);

const messageAppeared = await this.customWaiter(
async () => {
const displayedText = await this.getText(this.inputErrorMessageFieldLocator);
return displayedText !== '';
},
twoSeconds,
quarterSecond
);
if (messageAppeared) {
const errMsg = await this.getText(this.inputErrorMessageFieldLocator);
this.logger.info(
`ReceiveSubTab::GenerateURIModal::getAmountErrorMessage:errMsg - "${errMsg}"`
);
return errMsg;
} else {
return '';
}
}
}

class DisplayURIModal extends BasePage {
Expand All @@ -81,17 +122,25 @@ class DisplayURIModal extends BasePage {
method: 'id',
};
// methods
// * get the generated link
/**
* Getting a generated link right from the component itself
* @returns {Promise<string>}
*/
async getGeneratedLink() {
this.logger.info(`ReceiveSubTab::DisplayURIModal::getGeneratedLink is called.`);
return await this.getText(this.linkTextLocator);
}
// * click copy btn on generated link
/**
* Getting a generated link by clicking on the copy button near the text field.
* The address will be saved into clipboard.
*/
async copyGeneratedLink() {
this.logger.info(`ReceiveSubTab::DisplayURIModal::copyGeneratedLink is called.`);
await this.click(this.copyGeneratedLink);
}
// * close the modal window
/**
* Closing the modal window
*/
async closeModalWindow() {
this.logger.info(`ReceiveSubTab::DisplayURIModal::closeModalWindow is called.`);
await this.click(this.closeModalButtonLocator);
Expand Down Expand Up @@ -218,15 +267,21 @@ class ReceiveSubTab extends WalletTab {
};
};
// methods
// * click generate button
/**
* Generating a new address by clicking on the "Generate new address" button
* @param {number} amount Amount of addresses to generate
*/
async generateNewAddress(amount = 1) {
this.logger.info(`ReceiveSubTab::generateNewAddress is called. Amount: ${amount}`);
for (let addrIndex = 0; addrIndex < amount; addrIndex++) {
await this.click(this.generateNewAddressButtonLocator);
await this.sleep(200);
}
}
// * get error message text
/**
* Getting an error message from the Receive tab
* @returns {Promise<string>}
*/
async getErrorMessageText() {
this.logger.info(`ReceiveSubTab::getErrorMessageText is called.`);
return await this.getText(this.generateNewAddrErrorLocator);
Expand All @@ -241,65 +296,92 @@ class ReceiveSubTab extends WalletTab {
await this.click(subMenuItemLocator);
await this.sleep(300);
}
// * select base external addresses all
/**
* Clicking on the "External" menu item and then clicking on the "All" menu item
*/
async selectBaseExtAllAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseExtAllAddrs is called.`);
await this._selectBaseExt(this.allAddrsMenuItemLocator);
}
// * select base external addresses unused
/**
* Clicking on the "External" menu item and then clicking on the "Unused" menu item
*/
async selectBaseExtUnusedAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseExtUnusedAddrs is called.`);
await this._selectBaseExt(this.unusedAddrsMenuItemLocator);
}
// * select base external addresses used
/**
* Clicking on the "External" menu item and then clicking on the "Used" menu item
*/
async selectBaseExtUsedAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseExtUsedAddrs is called.`);
await this._selectBaseExt(this.usedAddrsMenuItemLocator);
}
// * select base external addresses has balance
/**
* Clicking on the "External" menu item and then clicking on the "Has balance" menu item
*/
async selectBaseExtHasBalanceAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseExtHasBalanceAddrs is called.`);
await this._selectBaseExt(this.hasBalanceAddrsMenuItemLocator);
}
// * select base internal addresses all
/**
* Clicking on the "Internal" menu item and then clicking on the "All" menu item
*/
async selectBaseInterAllAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseInterAllAddrs is called.`);
await this._selectBaseInter(this.allAddrsMenuItemLocator);
}
// * select base internal addresses unused
/**
* Clicking on the "Internal" menu item and then clicking on the "Unused" menu item
*/
async selectBaseInterUnusedAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseInterUnusedAddrs is called.`);
await this._selectBaseInter(this.unusedAddrsMenuItemLocator);
}
// * select base internal addresses used
/**
* Clicking on the "Internal" menu item and then clicking on the "Used" menu item
*/
async selectBaseInterUsedAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseInterUsedAddrs is called.`);
await this._selectBaseInter(this.usedAddrsMenuItemLocator);
}
// * select base internal addresses has balance
/**
* Clicking on the "Internal" menu item and then clicking on the "Has balance" menu item
*/
async selectBaseInterHasBalanceAddrs() {
this.logger.info(`ReceiveSubTab::selectBaseInterHasBalanceAddrs is called.`);
await this._selectBaseInter(this.hasBalanceAddrsMenuItemLocator);
}
// * select reward addresses
/**
* Clicking on the "Reward" menu item
*/
async selectRewardAddrs() {
this.logger.info(`ReceiveSubTab::selectRewardAddrs is called.`);
await this.click(this.rewardAddrsMenuItemLocator);
await this.sleep(300);
}
// * select addresses book
/**
* Clicking on the "Address book" menu item
*/
async selectAddressesBook() {
this.logger.info(`ReceiveSubTab::selectAddressesBook is called.`);
await this.click(this.addressBookMenuItemLocator);
await this.sleep(300);
}
// * get amount of displayed addresses
/**
* Getting an amount for displayed addresses
* @returns {Promise<number>}
*/
async getAmountOfAddresses() {
this.logger.info(`ReceiveSubTab::getAmountOfAddresses is called.`);
const allAddrs = await this.findElements(this.generalAddrRowLocator);
return allAddrs.length;
}
// * get address info by index
/**
*
* @param {number} rowIndex An index of a row in the addresses table starting from 0
* @returns {Promise<{address: string, balance: number}>}
*/
async getAddressInfo(rowIndex) {
this.logger.info(`ReceiveSubTab::getAddressInfo is called. Row index: ${rowIndex}`);
const shortAddr = await this.getText(this.addressTextInRowLocator(rowIndex));
Expand All @@ -318,9 +400,12 @@ class ReceiveSubTab extends WalletTab {
balance: addrBalance,
};
}
// * get balance of displayed addresses
/**
* Getting a sum of addresses balances
* @returns {Promise<number>}
*/
async getBalanceOfDisplayedAddrs() {
this.logger.info(`ReceiveSubTab::getBalanceOfDisplayedAddrs is called. Row index: ${rowIndex}`);
this.logger.info(`ReceiveSubTab::getBalanceOfDisplayedAddrs is called.`);
const addrsAmount = await this.getAmountOfAddresses();
let balance = 0;
for (let rowIndex = 0; rowIndex < addrsAmount; rowIndex++) {
Expand All @@ -329,12 +414,44 @@ class ReceiveSubTab extends WalletTab {
}
return balance;
}
// * generate link
async geneneratePaymentURI(rowIndex, adaAmount) {
this.logger.info(`ReceiveSubTab::clickGenerateURL is called. Row index: ${rowIndex}`);
/**
* Pressing the Generate URI button for an address
* @param {number} rowIndex An index of a row where the button Generate URI should be pressed
* @returns {Promise<GenerateURIModal>}
*/
async clickGenerateURI(rowIndex) {
this.logger.info(`ReceiveSubTab::geneneratePaymentURI is called. Row index: ${rowIndex}`);
const genURIBtnLocator = this.generateURIButtonInRowLocator(rowIndex);
await this.click(genURIBtnLocator);
const genLinkModal = new GenerateURIModal(this.driver, this.logger);
return new GenerateURIModal(this.driver, this.logger);
}
/**
* Getting an object of the modal window GenerateURIModal
* @returns {GenerateURIModal}
*/
getGenerateURIModal() {
this.logger.info(`ReceiveSubTab::getGenerateURIModal is called.`);
return new GenerateURIModal(this.driver, this.logger);
}
/**
* Getting an object of the modal window DisplayURIModal
* @returns {DisplayURIModal}
*/
getDisplayURIModal() {
this.logger.info(`ReceiveSubTab::getDisplayURIModal is called.`);
return new DisplayURIModal(this.driver, this.logger);
}
/**
*
* @param {number} rowIndex An index of a row in the addresses table starting from 0
* @param {string} adaAmount ADA amount to receive
* @returns {Promise<{address: string, amount: string, genLink: string}>}
*/
async geneneratePaymentURI(rowIndex, adaAmount) {
this.logger.info(
`ReceiveSubTab::geneneratePaymentURI is called. Row index: ${rowIndex}, amount: ${adaAmount}`
);
const genLinkModal = await this.clickGenerateURI(rowIndex);
const selectedAddress = await genLinkModal.getReceiverAddress();
await genLinkModal.enterReceiveAmount(adaAmount);
await genLinkModal.generateLink();
Expand All @@ -347,6 +464,10 @@ class ReceiveSubTab extends WalletTab {
genLink: generatedLink,
};
}
/**
* Getting the latest address which is displayed at the header panel of the Receive page
* @returns {Promise<string>}
*/
async getCurrentReceiveAddr() {
this.logger.info(`ReceiveSubTab::getCurrentReceiveAddr is called.`);
const address = await this.getText(this.currentAddressToUseTextLocator);
Expand Down

0 comments on commit d8ac054

Please sign in to comment.