From fd841b2aca544573bee3e1ba1f15487fd35618a1 Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Tue, 23 Jan 2024 14:53:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(metamask):=20Add=20`resetAccou?= =?UTF-8?q?nt`=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/classes/MetaMask.md | 19 +++++++++++++++++++ wallets/metamask/src/metamask.ts | 11 +++++++++++ .../src/pages/HomePage/actions/settings.ts | 9 +++++++++ wallets/metamask/src/pages/HomePage/page.ts | 4 ++++ .../src/pages/HomePage/selectors/settings.ts | 6 ++++++ .../test/e2e/metamask/resetAccount.spec.ts | 19 +++++++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 wallets/metamask/test/e2e/metamask/resetAccount.spec.ts diff --git a/docs/api/classes/MetaMask.md b/docs/api/classes/MetaMask.md index 6cd8d9590..993969147 100644 --- a/docs/api/classes/MetaMask.md +++ b/docs/api/classes/MetaMask.md @@ -27,6 +27,7 @@ This class is the heart of Synpress's MetaMask API. - [rejectSignature()](MetaMask.md#rejectsignature) - [rejectSwitchNetwork()](MetaMask.md#rejectswitchnetwork) - [rejectTransaction()](MetaMask.md#rejecttransaction) + - [resetAccount()](MetaMask.md#resetaccount) - [switchAccount()](MetaMask.md#switchaccount) - [switchNetwork()](MetaMask.md#switchnetwork) - [toggleDismissSecretRecoveryPhraseReminder()](MetaMask.md#toggledismisssecretrecoveryphrasereminder) @@ -402,6 +403,24 @@ Rejects a transaction request. *** +### resetAccount() + +```ts +resetAccount(): Promise +``` + +Resets the account. + +::: warning +This function requires the correct menu to be already opened. +::: + +#### Returns + +`Promise`\<`void`\> + +*** + ### switchAccount() ```ts diff --git a/wallets/metamask/src/metamask.ts b/wallets/metamask/src/metamask.ts index 67402410c..6121dec57 100644 --- a/wallets/metamask/src/metamask.ts +++ b/wallets/metamask/src/metamask.ts @@ -331,6 +331,17 @@ export class MetaMask { await this.homePage.toggleDismissSecretRecoveryPhraseReminder() } + /** + * Resets the account. + * + * ::: warning + * This function requires the correct menu to be already opened. + * ::: + */ + async resetAccount() { + await this.homePage.resetAccount() + } + /// ------------------------------------------- /// ---------- EXPERIMENTAL FEATURES ---------- /// ------------------------------------------- diff --git a/wallets/metamask/src/pages/HomePage/actions/settings.ts b/wallets/metamask/src/pages/HomePage/actions/settings.ts index 96f561d91..585d2c186 100644 --- a/wallets/metamask/src/pages/HomePage/actions/settings.ts +++ b/wallets/metamask/src/pages/HomePage/actions/settings.ts @@ -12,12 +12,21 @@ async function openSidebarMenu(page: Page, menu: SettingsSidebarMenus) { await page.locator(Selectors.settings.sidebarMenu(menu)).click() } +async function resetAccount(page: Page) { + const buttonSelector = `[data-testid="advanced-setting-reset-account"] button` + const confirmButtonSelector = '.modal .modal-container__footer button.btn-danger-primary' + + await page.locator(buttonSelector).click() + await page.locator(confirmButtonSelector).click() +} + async function toggleDismissSecretRecoveryPhraseReminder(page: Page) { const toggleLocator = page.locator(Selectors.settings.advanced.dismissSecretRecoveryPhraseReminderToggle) await toggle(toggleLocator) } const advanced = { + resetAccount, toggleDismissSecretRecoveryPhraseReminder } diff --git a/wallets/metamask/src/pages/HomePage/page.ts b/wallets/metamask/src/pages/HomePage/page.ts index 147d82aa4..c6729f2cc 100644 --- a/wallets/metamask/src/pages/HomePage/page.ts +++ b/wallets/metamask/src/pages/HomePage/page.ts @@ -56,6 +56,10 @@ export class HomePage { await toggleShowTestNetworks(this.page) } + async resetAccount() { + await settings.advanced.resetAccount(this.page) + } + async toggleDismissSecretRecoveryPhraseReminder() { await settings.advanced.toggleDismissSecretRecoveryPhraseReminder(this.page) } diff --git a/wallets/metamask/src/pages/HomePage/selectors/settings.ts b/wallets/metamask/src/pages/HomePage/selectors/settings.ts index 29429aa3b..03de00900 100644 --- a/wallets/metamask/src/pages/HomePage/selectors/settings.ts +++ b/wallets/metamask/src/pages/HomePage/selectors/settings.ts @@ -15,9 +15,15 @@ export enum SettingsSidebarMenus { const sidebarMenu = (menu: SettingsSidebarMenus) => `.settings-page__content__tabs .tab-bar__tab.pointer:nth-of-type(${menu})` +const resetAccount = { + button: `${createDataTestSelector('advanced-setting-reset-account')} button`, + confirmButton: '.modal .modal-container__footer button.btn-danger-primary' +} + const advanced = { // locator(showTestNetworksToggle).nth(0) -> Show conversion on test networks // locator(showTestNetworksToggle).nth(1) -> Show test networks + resetAccount, showTestNetworksToggle: `${createDataTestSelector('advanced-setting-show-testnet-conversion')} .toggle-button`, dismissSecretRecoveryPhraseReminderToggle: '.settings-page__content-row:nth-of-type(11) .toggle-button' } diff --git a/wallets/metamask/test/e2e/metamask/resetAccount.spec.ts b/wallets/metamask/test/e2e/metamask/resetAccount.spec.ts new file mode 100644 index 000000000..64d772aa3 --- /dev/null +++ b/wallets/metamask/test/e2e/metamask/resetAccount.spec.ts @@ -0,0 +1,19 @@ +import { testWithSynpress } from '@synthetixio/synpress-fixtures' +import { MetaMask, unlockForFixture } from '../../../src' + +import basicSetup from '../wallet-setup/basic.setup' + +const test = testWithSynpress(basicSetup, unlockForFixture) + +test('reset the account', async ({ context, metamaskPage }) => { + const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) + + await metamask.openSettings() + + const SidebarMenus = metamask.homePage.selectors.settings.SettingsSidebarMenus + await metamask.openSidebarMenu(SidebarMenus.Advanced) + + await metamask.resetAccount() + + await metamask.goBackToHomePage() +})