Skip to content

Commit

Permalink
fix(25350): fix flakey token importing e2e test (MetaMask#26351)
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**
Captured in
https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/95033/workflows/faea9f93-9600-4207-bb3c-2dc17eec663b/jobs/3536505/tests.

This test is flaky from not waiting for token price to be fetched and
rendered properly. The simple fix would be
- wait until token is imported after modal is closed 
- use `findVisibleElement` and the built in `timeout` to wait for
element to be rendered properly

Attached to this PR is a report
[here](MetaMask#26351 (comment))
of running it 20 times after the fix and results in no flakiness.

<!--
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/26351?quickstart=1)

## **Related issues**

Fixes: MetaMask#26350

## **Manual testing steps**

1. Go to this page...
2.
3.

## **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
DDDDDanica authored Aug 8, 2024
1 parent 59cee4e commit 91dc6ea
Showing 1 changed file with 48 additions and 33 deletions.
81 changes: 48 additions & 33 deletions test/e2e/tests/tokens/token-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('Token List', function () {
await driver.clickElement(
'[data-testid="import-tokens-modal-import-button"]',
);
await driver.findElement({ text: 'Token imported', tag: 'h6' });
};

it('should not shows percentage increase for an ERC20 token without prices available', async function () {
Expand Down Expand Up @@ -96,7 +97,7 @@ describe('Token List', function () {
);
});

it('shows percentage increase for an ERC20 token with prices available', async function () {
it.only('shows percentage increase for an ERC20 token with prices available', async function () {
const ethConversionInUsd = 10000;

// Prices are in ETH
Expand Down Expand Up @@ -155,40 +156,54 @@ describe('Token List', function () {
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await importToken(driver);
await driver.delay(500);

// Verify native token increase
const testIdNative = `token-increase-decrease-percentage-${zeroAddress()}`;

// Verify native token increase
const testId = `token-increase-decrease-percentage-${tokenAddress}`;

const percentageNative = await (
await driver.findElement(`[data-testid="${testIdNative}"]`)
).getText();
assert.equal(percentageNative, '+0.02%');

const percentage = await (
await driver.findElement(`[data-testid="${testId}"]`)
).getText();
assert.equal(percentage, '+0.05%');

// check increase balance for native token
const increaseValue = await (
await driver.findElement(
`[data-testid="token-increase-decrease-value"]`,
)
).getText();
assert.equal(increaseValue, '+$50.00 ');

// check percentage increase balance for native token
const percentageIncreaseDecrease = await (
await driver.findElement(
`[data-testid="token-increase-decrease-percentage"]`,
)
).getText();

assert.equal(percentageIncreaseDecrease, '(+0.02%)');
const testIdBase = 'token-increase-decrease-percentage';

const isETHIncreaseDOMPresentAndVisible =
await driver.isElementPresentAndVisible({
css: `[data-testid="${testIdBase}-${zeroAddress()}"]`,
text: '+0.02%',
});
assert.equal(
isETHIncreaseDOMPresentAndVisible,
true,
'Invalid eth increase dom text content',
);

const isTokenIncreaseDecreasePercentageDOMPresent =
await driver.isElementPresentAndVisible({
css: `[data-testid="${testIdBase}-${tokenAddress}"]`,
text: '+0.05%',
});
assert.equal(
isTokenIncreaseDecreasePercentageDOMPresent,
true,
'Invalid token increase dom text content',
);

// check increase balance for native token eth
const isExpectedIncreaseDecreaseValueDOMPresentAndVisible =
await driver.isElementPresentAndVisible({
css: '[data-testid="token-increase-decrease-value"]',
text: '+$50.00',
});
assert.equal(
isExpectedIncreaseDecreaseValueDOMPresentAndVisible,
true,
'Invalid increase-decrease-value dom text content',
);

const isExpectedIncreaseDecreasePercentageDOMPresentAndVisible =
await driver.isElementPresentAndVisible({
css: '[data-testid="token-increase-decrease-percentage"]',
text: '(+0.02%)',
});
assert.equal(
isExpectedIncreaseDecreasePercentageDOMPresentAndVisible,
true,
'Invalid increase-decrease-percentage dom text content',
);
},
);
});
Expand Down

0 comments on commit 91dc6ea

Please sign in to comment.