From 2f03c0d62a4cd901e714bba78c5c809a52d41f68 Mon Sep 17 00:00:00 2001 From: Danica Shen Date: Thu, 13 Jul 2023 13:02:06 +0100 Subject: [PATCH] feat(19726): fix flaky test in Dapp interactions caused by home-container rerender (#19997) --- test/e2e/tests/dapp-interactions.spec.js | 67 ++++++------------- ...eractive-replacement-token-notification.js | 10 +-- .../confirm-add-custodian-token.js | 3 +- 3 files changed, 23 insertions(+), 57 deletions(-) diff --git a/test/e2e/tests/dapp-interactions.spec.js b/test/e2e/tests/dapp-interactions.spec.js index dae045ef0..4fb9a99a2 100644 --- a/test/e2e/tests/dapp-interactions.spec.js +++ b/test/e2e/tests/dapp-interactions.spec.js @@ -5,13 +5,12 @@ const { openDapp, DAPP_URL, DAPP_ONE_URL, + unlockWallet, + WINDOW_TITLES, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Dapp interactions', function () { - let windowHandles; - let extension; - let popup; const ganacheOptions = { accounts: [ { @@ -34,30 +33,13 @@ describe('Dapp interactions', function () { }, async ({ driver }) => { await driver.navigate(); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); - await openDapp(driver); - windowHandles = await driver.getAllWindowHandles(); - extension = windowHandles[0]; - - // Lock Account - await driver.switchToWindow(extension); - await driver.clickElement( - '[data-testid="account-options-menu-button"]', - ); - await driver.clickElement({ text: 'Lock', tag: 'div' }); // Trigger Notification - await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles); await driver.clickElement('#addEthereumChain'); await driver.waitUntilXWindowHandles(3); - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); + await driver.switchToWindowWithTitle('MetaMask Notification'); + await unlockWallet(driver); const notification = await driver.isElementPresent({ text: 'Allow this site to add a network?', tag: 'h3', @@ -81,45 +63,34 @@ describe('Dapp interactions', function () { }, async ({ driver }) => { await driver.navigate(); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); - await openDapp(driver); - windowHandles = await driver.getAllWindowHandles(); - extension = windowHandles[0]; - - // Lock Account - await driver.switchToWindow(extension); - await driver.clickElement( - '[data-testid="account-options-menu-button"]', - ); - await driver.clickElement({ text: 'Lock', tag: 'div' }); - - // Connect to Dapp1 + // Connect to 2nd dapp => DAPP_ONE await openDapp(driver, null, DAPP_ONE_URL); await driver.clickElement({ text: 'Connect', tag: 'button' }); - await driver.waitUntilXWindowHandles(4); - windowHandles = await driver.getAllWindowHandles(); + await driver.waitUntilXWindowHandles(3); - popup = await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Notification); - await driver.switchToWindow(popup); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); + await unlockWallet(driver); await driver.clickElement({ text: 'Next', tag: 'button' }); await driver.clickElement({ text: 'Connect', tag: 'button' }); + await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); + await driver.waitForSelector({ + css: '#accounts', + text: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', + }); // Assert Connection - await driver.switchToWindow(extension); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); + await driver.switchToWindowWithTitle( + WINDOW_TITLES.ExtensionInFullScreenView, + ); + await unlockWallet(driver); await driver.clickElement( '[data-testid ="account-options-menu-button"]', ); + await driver.clickElement({ text: 'Connected sites', tag: 'div' }); + const connectedDapp1 = await driver.isElementPresent({ text: DAPP_URL, tag: 'bdi', diff --git a/ui/components/institutional/interactive-replacement-token-notification/interactive-replacement-token-notification.js b/ui/components/institutional/interactive-replacement-token-notification/interactive-replacement-token-notification.js index 80c8bd93f..5f1aa1c56 100644 --- a/ui/components/institutional/interactive-replacement-token-notification/interactive-replacement-token-notification.js +++ b/ui/components/institutional/interactive-replacement-token-notification/interactive-replacement-token-notification.js @@ -93,14 +93,8 @@ const InteractiveReplacementTokenNotification = ({ isVisible }) => { }; handleShowNotification(); - }, [ - dispatch, - address, - interactiveReplacementToken, - isUnlocked, - keyring, - mmiActions, - ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [address, interactiveReplacementToken.oldRefreshToken, isUnlocked]); return showNotification ? ( { const mmiActions = mmiActionsFactory(); const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage); - const connectRequests = useSelector(getInstitutionalConnectRequests); + const connectRequests = useSelector(getInstitutionalConnectRequests, isEqual); const isComplianceActivated = useSelector(complianceActivated); const [showMore, setShowMore] = useState(false); const [isLoading, setIsLoading] = useState(false);