Skip to content

Commit

Permalink
fix: fix asset-list e2e test (#28822)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
fix e2e test for the unified list
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28822?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. run `PORTFOLIO_VIEW=1 yarn build:test`
2. Run `PORTFOLIO_VIEW=1 yarn test:e2e:single --browser=chrome
test/e2e/tests/multichain/asset-list.spec.ts --debug --leave-running`

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
salimtb authored Dec 2, 2024
1 parent 7143c96 commit 5ab288b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
16 changes: 16 additions & 0 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@ class FixtureBuilder {
});
}

withNetworkControllerOnPolygon() {
return this.withNetworkController({
networkConfigurations: {
networkConfigurationId: {
chainId: CHAIN_IDS.POLYGON,
nickname: 'Polygon Mainnet',
rpcPrefs: {},
rpcUrl: 'https://mainnet.infura.io',
ticker: 'ETH',
networkConfigurationId: 'networkConfigurationId',
id: 'networkConfigurationId',
},
},
});
}

withNetworkControllerDoubleGanache() {
const ganacheNetworks = mockNetworkStateOld({
id: '76e9cd59-d8e2-47e7-b369-9c205ccb602c',
Expand Down
27 changes: 14 additions & 13 deletions test/e2e/tests/multichain/asset-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import AssetListPage from '../../page-objects/pages/asset-list';

const NETWORK_NAME_MAINNET = 'Ethereum Mainnet';
const LINEA_NAME_MAINNET = 'Linea Mainnet';
const LOCALHOST = 'Localhost 8545';
const POLYGON_NAME_MAINNET = 'Polygon';
const BALANCE_AMOUNT = '24.9956';

function buildFixtures(title: string) {
function buildFixtures(title: string, chainId: number = 1337) {
return {
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withTokensControllerERC20()
.withNetworkControllerOnPolygon()
.withTokensControllerERC20({ chainId })
.build(),
ganacheOptions: defaultGanacheOptions,
smartContract: SMART_CONTRACTS.HST,
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('Multichain Asset List', function (this: Suite) {
const assetListPage = new AssetListPage(driver);
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetworkDialog.selectNetworkName(NETWORK_NAME_MAINNET);
await assetListPage.waitUntilAssetListHasItems(2);
await assetListPage.waitUntilAssetListHasItems(3);
await assetListPage.openNetworksFilter();
await assetListPage.clickCurrentNetworkOption();
await headerNavbar.clickSwitchNetworkDropDown();
Expand Down Expand Up @@ -79,7 +80,7 @@ describe('Multichain Asset List', function (this: Suite) {
const assetListPage = new AssetListPage(driver);
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetworkDialog.selectNetworkName(NETWORK_NAME_MAINNET);
await assetListPage.waitUntilAssetListHasItems(2);
await assetListPage.waitUntilAssetListHasItems(3);
await driver.clickElement('.multichain-token-list-item');
const coinOverviewElement = await driver.findElement(
'[data-testid="coin-overview-buy"]',
Expand All @@ -97,7 +98,7 @@ describe('Multichain Asset List', function (this: Suite) {
});
it('switches networks when clicking on send for a token on another network', async function () {
await withFixtures(
buildFixtures(this.test?.fullTitle() as string),
buildFixtures(this.test?.fullTitle() as string, 137),
async ({
driver,
ganacheServer,
Expand All @@ -112,10 +113,10 @@ describe('Multichain Asset List', function (this: Suite) {
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetworkDialog.selectNetworkName(NETWORK_NAME_MAINNET);
const sendPage = new SendTokenPage(driver);
await assetListPage.waitUntilAssetListHasItems(2);
await assetListPage.waitUntilAssetListHasItems(4);
await assetListPage.clickOnAsset('TST');
await driver.clickElement('[data-testid="eth-overview-send"]');
await sendPage.check_networkChange(LOCALHOST);
await sendPage.check_networkChange(POLYGON_NAME_MAINNET);
await sendPage.check_pageIsLoaded();
await sendPage.fillRecipient(
'0x2f318C334780961FB129D2a6c30D0763d9a5C970',
Expand All @@ -132,7 +133,7 @@ describe('Multichain Asset List', function (this: Suite) {
});
it('switches networks when clicking on swap for a token on another network', async function () {
await withFixtures(
buildFixtures(this.test?.fullTitle() as string),
buildFixtures(this.test?.fullTitle() as string, 137),
async ({
driver,
ganacheServer,
Expand All @@ -146,14 +147,14 @@ describe('Multichain Asset List', function (this: Suite) {
const assetListPage = new AssetListPage(driver);
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetworkDialog.selectNetworkName(NETWORK_NAME_MAINNET);
await assetListPage.waitUntilAssetListHasItems(2);
await assetListPage.waitUntilAssetListHasItems(4);
await assetListPage.clickOnAsset('TST');
await driver.clickElement('.mm-box > button:nth-of-type(3)');
const toastTextElement = await driver.findElement('.toast-text');
const toastText = await toastTextElement.getText();
assert.equal(
toastText,
`You're now using ${LOCALHOST}`,
`You're now using ${POLYGON_NAME_MAINNET}`,
'Toast text is correct',
);
},
Expand All @@ -175,7 +176,7 @@ describe('Multichain Asset List', function (this: Suite) {
const selectNetworkDialog = new SelectNetwork(driver);
await headerNavbar.clickSwitchNetworkDropDown();
await selectNetworkDialog.selectNetworkName(LINEA_NAME_MAINNET);
await assetListPage.waitUntilAssetListHasItems(2);
await assetListPage.waitUntilAssetListHasItems(3);

await assetListPage.clickOnAsset('Ethereum');

Expand All @@ -187,7 +188,7 @@ describe('Multichain Asset List', function (this: Suite) {
const toastText = await toastTextElement.getText();
assert.equal(
toastText,
`You're now using ${LOCALHOST}`,
`You're now using Ethereum Mainnet`,
'Toast text is correct',
);
const balanceMessageElement = await driver.findElement(
Expand Down

0 comments on commit 5ab288b

Please sign in to comment.