diff --git a/wallets/metamask/src/pages/HomePage/actions/renameAccount.ts b/wallets/metamask/src/pages/HomePage/actions/renameAccount.ts index a659caa06..8fff7b6f7 100644 --- a/wallets/metamask/src/pages/HomePage/actions/renameAccount.ts +++ b/wallets/metamask/src/pages/HomePage/actions/renameAccount.ts @@ -2,11 +2,13 @@ import type { Page } from '@playwright/test' import Selectors from '../selectors' import { z } from 'zod' +// @todo, look into validation schema that's language agnostic for Metamask reserved words (""Account 1", "Account 2", etc.) const Account = z.object({ name: z.string().refine((value) => { - return value.trim().length > 0 && !/^Account\s*\d+/.test(value); + return value.trim().length > 0 }, 'Invalid account name'), }) + export type Account = z.infer export async function renameAccount(page: Page, newAccountName: Account['name']) { @@ -18,5 +20,5 @@ export async function renameAccount(page: Page, newAccountName: Account['name']) await page.locator(Selectors.accountMenu.renameAccountMenu.listItemDetailButton).click() await page.locator(Selectors.accountMenu.renameAccountMenu.renameButton).click() await page.locator(Selectors.accountMenu.renameAccountMenu.renameInput).fill(newAccountName) - await page.keyboard.press('Enter') + await page.locator(Selectors.accountMenu.renameAccountMenu.confirmRenameButton).click() } diff --git a/wallets/metamask/src/pages/HomePage/selectors/index.ts b/wallets/metamask/src/pages/HomePage/selectors/index.ts index 0d9d78648..24147dd0a 100644 --- a/wallets/metamask/src/pages/HomePage/selectors/index.ts +++ b/wallets/metamask/src/pages/HomePage/selectors/index.ts @@ -12,6 +12,7 @@ const renameAccountMenu = { listItemButton: `${accountMenuContainer} ${createDataTestSelector('account-list-item-menu-button')}`, listItemDetailButton: `${createDataTestSelector('account-list-menu-details')}`, renameButton: `${createDataTestSelector('editable-label-button')}`, + confirmRenameButton: `div.editable-label button.mm-button-icon`, renameInput: `input`, } diff --git a/wallets/metamask/test/e2e/metamask/renameAccount.spec.ts b/wallets/metamask/test/e2e/metamask/renameAccount.spec.ts index 7cea6cd58..ceb0b6ce0 100644 --- a/wallets/metamask/test/e2e/metamask/renameAccount.spec.ts +++ b/wallets/metamask/test/e2e/metamask/renameAccount.spec.ts @@ -1,6 +1,5 @@ import { testWithSynpress } from '@synthetixio/synpress-fixtures' import { MetaMask, unlockForFixture } from '../../../src' -import { z } from 'zod' import basicSetup from '../wallet-setup/basic.setup' @@ -20,11 +19,5 @@ test('should rename current account with specified name', async ({ context, meta test('should throw Zod error if an empty account name is passed', async ({ context, metamaskPage }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) - await expect(metamask.renameAccount('')).rejects.toThrowError(z.ZodError) -}) - -test('should throw Zod error if a reserved account name is passed', async ({ context, metamaskPage }) => { - const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) - - await expect(metamask.renameAccount('Account 12')).rejects.toThrowError(z.ZodError) + await expect(metamask.renameAccount('')).rejects.toThrowError('Invalid account name') }) \ No newline at end of file