diff --git a/commands/metamask.js b/commands/metamask.js index 15f76e749..ba858bcf6 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -380,7 +380,9 @@ const metamask = { mainPageElements.createAccount.createAccountError, ); const formErrorTxt = await formErrorEl.innerText(); - const accountExists = 'This account name already exists' === formErrorTxt; + const accountExists = + 'This account name already exists' === formErrorTxt || + 'This account name is reserved' === formErrorTxt; if (accountExists) { log(`[createAccount] ${formErrorTxt}`); @@ -397,6 +399,40 @@ const metamask = { await switchToCypressIfNotActive(); return accountExists ? formErrorTxt : true; }, + async renameAccount(newAccountName) { + await switchToMetamaskIfNotActive(); + + await playwright.waitAndClick(mainPageElements.optionsMenu.button); + await playwright.waitAndClick( + mainPageElements.optionsMenu.accountDetailsButton, + ); + + await playwright.waitAndClick(mainPageElements.renameAccount.invokeInput); + await playwright.waitClearAndType( + newAccountName, + mainPageElements.renameAccount.input, + ); + + const formErrorEl = await playwright.waitFor( + mainPageElements.renameAccount.error, + ); + const formErrorTxt = await formErrorEl.innerText(); + const accountExists = + 'This account name already exists' === formErrorTxt || + 'This account name is reserved' === formErrorTxt; + + if (accountExists) { + log(`[createAccount] ${formErrorTxt}`); + } else { + await playwright.waitAndClick( + mainPageElements.renameAccount.confirmButton, + ); + } + + await playwright.waitAndClick(mainPageElements.accountModal.closeButton); + await switchToCypressIfNotActive(); + return accountExists ? formErrorTxt : true; + }, async switchAccount(accountNameOrAccountNumber) { if (typeof accountNameOrAccountNumber === 'string') { accountNameOrAccountNumber = accountNameOrAccountNumber.toLowerCase(); diff --git a/docs/synpress-commands.md b/docs/synpress-commands.md index 9fefccda5..a21abf107 100644 --- a/docs/synpress-commands.md +++ b/docs/synpress-commands.md @@ -104,6 +104,14 @@ Create new account in metamask. createMetamaskAccount(accountName?: string): Chainable; ``` +#### `cy.renameMetamaskAccount()` + +Rename current account in metamask. + +```ts +createMetamaskAccount(newAccountName: string): Chainable; +``` + #### `cy.switchMetamaskAccount()` Switch metamask account. diff --git a/pages/metamask/main-page.js b/pages/metamask/main-page.js index c97c587c4..4c022a097 100644 --- a/pages/metamask/main-page.js +++ b/pages/metamask/main-page.js @@ -84,11 +84,19 @@ const connectedSites = { closeButton: `${connectedSitesSelector} [data-testid="popover-close"]`, }; +const accountModalSelector = '.account-modal'; const accountModal = { - walletAddressInput: '.account-modal .qr-code__address', + walletAddressInput: `${accountModalSelector} .qr-code__address`, closeButton: '.account-modal__close', }; +const renameAccount = { + invokeInput: `${accountModalSelector} [data-testid="editable-label-button"]`, + input: `${accountModalSelector} [data-testid="editable-input"]`, + confirmButton: `${accountModalSelector} .editable-label__icon-button`, + error: `${accountModalSelector} .editable-label__error`, +}; + const importAccountSelector = '.new-account'; const importAccount = { page: importAccountSelector, @@ -135,6 +143,7 @@ module.exports.mainPageElements = { optionsMenu, connectedSites, accountModal, + renameAccount, importAccount, createAccount, importToken, diff --git a/plugins/index.js b/plugins/index.js index 107c1ff8b..a5ab9e7ec 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -64,6 +64,7 @@ module.exports = (on, config) => { unlockMetamask: metamask.unlock, importMetamaskAccount: metamask.importAccount, createMetamaskAccount: metamask.createAccount, + renameMetamaskAccount: metamask.renameAccount, switchMetamaskAccount: metamask.switchAccount, addMetamaskNetwork: metamask.addNetwork, changeMetamaskNetwork: async network => { diff --git a/support/commands.js b/support/commands.js index f36285490..04860445a 100644 --- a/support/commands.js +++ b/support/commands.js @@ -53,6 +53,10 @@ Cypress.Commands.add('createMetamaskAccount', accountName => { return cy.task('createMetamaskAccount', accountName); }); +Cypress.Commands.add('renameMetamaskAccount', newAccountName => { + return cy.task('renameMetamaskAccount', newAccountName); +}); + Cypress.Commands.add('switchMetamaskAccount', accountNameOrAccountNumber => { return cy.task('switchMetamaskAccount', accountNameOrAccountNumber); }); diff --git a/support/index.d.ts b/support/index.d.ts index 531cb59d2..d694bf0ca 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -97,6 +97,12 @@ declare namespace Cypress { * cy.createMetamaskAccount('accountName') */ createMetamaskAccount(accountName?: string): Chainable; + /** + * Rename current account in metamask + * @example + * cy.renameMetamaskAccount('fancyAccountName') + */ + renameMetamaskAccount(newAccountName: string): Chainable; /** * Switch metamask account * @example diff --git a/tests/e2e/specs/metamask-spec.js b/tests/e2e/specs/metamask-spec.js index ed8953e72..65509240d 100644 --- a/tests/e2e/specs/metamask-spec.js +++ b/tests/e2e/specs/metamask-spec.js @@ -171,11 +171,21 @@ describe('Metamask', () => { expect(created).to.be.equal('This account name already exists'); }); }); + it(`renameMetamaskAccount should rename metamask account`, () => { + cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { + expect(created).to.be.true; + }); + }); it(`switchMetamaskAccount should switch to another account using order number`, () => { cy.switchMetamaskAccount(2).then(switched => { expect(switched).to.be.true; }); }); + it(`renameMetamaskAccount should not fail when account with this name already exists`, () => { + cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { + expect(created).to.be.equal('This account name already exists'); + }); + }); it(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal(