1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 03:12:42 +02:00

feat(19726): fix flaky test in Dapp interactions caused by home-container rerender (#19997)

This commit is contained in:
Danica Shen 2023-07-13 13:02:06 +01:00 committed by GitHub
parent 30a77d0483
commit 2f03c0d62a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 57 deletions

View File

@ -5,13 +5,12 @@ const {
openDapp, openDapp,
DAPP_URL, DAPP_URL,
DAPP_ONE_URL, DAPP_ONE_URL,
unlockWallet,
WINDOW_TITLES,
} = require('../helpers'); } = require('../helpers');
const FixtureBuilder = require('../fixture-builder'); const FixtureBuilder = require('../fixture-builder');
describe('Dapp interactions', function () { describe('Dapp interactions', function () {
let windowHandles;
let extension;
let popup;
const ganacheOptions = { const ganacheOptions = {
accounts: [ accounts: [
{ {
@ -34,30 +33,13 @@ describe('Dapp interactions', function () {
}, },
async ({ driver }) => { async ({ driver }) => {
await driver.navigate(); await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await openDapp(driver); 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 // Trigger Notification
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
await driver.clickElement('#addEthereumChain'); await driver.clickElement('#addEthereumChain');
await driver.waitUntilXWindowHandles(3); await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle('MetaMask Notification');
'MetaMask Notification', await unlockWallet(driver);
windowHandles,
);
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
const notification = await driver.isElementPresent({ const notification = await driver.isElementPresent({
text: 'Allow this site to add a network?', text: 'Allow this site to add a network?',
tag: 'h3', tag: 'h3',
@ -81,45 +63,34 @@ describe('Dapp interactions', function () {
}, },
async ({ driver }) => { async ({ driver }) => {
await driver.navigate(); await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await openDapp(driver); // Connect to 2nd dapp => DAPP_ONE
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
await openDapp(driver, null, DAPP_ONE_URL); await openDapp(driver, null, DAPP_ONE_URL);
await driver.clickElement({ text: 'Connect', tag: 'button' }); await driver.clickElement({ text: 'Connect', tag: 'button' });
await driver.waitUntilXWindowHandles(4); await driver.waitUntilXWindowHandles(3);
windowHandles = await driver.getAllWindowHandles();
popup = await driver.switchToWindowWithTitle( await driver.switchToWindowWithTitle(WINDOW_TITLES.Notification);
'MetaMask Notification',
windowHandles,
);
await driver.switchToWindow(popup); await unlockWallet(driver);
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await driver.clickElement({ text: 'Next', tag: 'button' }); await driver.clickElement({ text: 'Next', tag: 'button' });
await driver.clickElement({ text: 'Connect', tag: 'button' }); await driver.clickElement({ text: 'Connect', tag: 'button' });
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.waitForSelector({
css: '#accounts',
text: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
});
// Assert Connection // Assert Connection
await driver.switchToWindow(extension); await driver.switchToWindowWithTitle(
await driver.fill('#password', 'correct horse battery staple'); WINDOW_TITLES.ExtensionInFullScreenView,
await driver.press('#password', driver.Key.ENTER); );
await unlockWallet(driver);
await driver.clickElement( await driver.clickElement(
'[data-testid ="account-options-menu-button"]', '[data-testid ="account-options-menu-button"]',
); );
await driver.clickElement({ text: 'Connected sites', tag: 'div' }); await driver.clickElement({ text: 'Connected sites', tag: 'div' });
const connectedDapp1 = await driver.isElementPresent({ const connectedDapp1 = await driver.isElementPresent({
text: DAPP_URL, text: DAPP_URL,
tag: 'bdi', tag: 'bdi',

View File

@ -93,14 +93,8 @@ const InteractiveReplacementTokenNotification = ({ isVisible }) => {
}; };
handleShowNotification(); handleShowNotification();
}, [ // eslint-disable-next-line react-hooks/exhaustive-deps
dispatch, }, [address, interactiveReplacementToken.oldRefreshToken, isUnlocked]);
address,
interactiveReplacementToken,
isUnlocked,
keyring,
mmiActions,
]);
return showNotification ? ( return showNotification ? (
<Box <Box

View File

@ -1,6 +1,7 @@
import React, { useContext, useState } from 'react'; import React, { useContext, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import isEqual from 'lodash/isEqual';
import PulseLoader from '../../../components/ui/pulse-loader'; import PulseLoader from '../../../components/ui/pulse-loader';
import { CUSTODY_ACCOUNT_ROUTE } from '../../../helpers/constants/routes'; import { CUSTODY_ACCOUNT_ROUTE } from '../../../helpers/constants/routes';
import { import {
@ -38,7 +39,7 @@ const ConfirmAddCustodianToken = () => {
const mmiActions = mmiActionsFactory(); const mmiActions = mmiActionsFactory();
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage); const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
const connectRequests = useSelector(getInstitutionalConnectRequests); const connectRequests = useSelector(getInstitutionalConnectRequests, isEqual);
const isComplianceActivated = useSelector(complianceActivated); const isComplianceActivated = useSelector(complianceActivated);
const [showMore, setShowMore] = useState(false); const [showMore, setShowMore] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);