Skip to content

Commit

Permalink
fix: flaky anti-pattern getText + assert 3 (#28062)
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**
Continuing the work of removing the e2e anti-pattern of finding the
element and then asserting its text.
There are more occurrences, but this work is split in several PRs, for
an easy review and a faster ci.
Once all occurrences have been fixed, we'll be able to merge
@HowardBraham 's [PR
](#27591 adding a
lint rule which prevents introducing it again.

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

## **Related issues**

Fixes: (but doesn't yet closes)
#19870

## **Manual testing steps**

1. Check ci

## **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**

- [x] 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).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] 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
seaona authored Oct 24, 2024
1 parent 4fe3a9f commit 5983dc1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
12 changes: 5 additions & 7 deletions test/e2e/tests/settings/auto-lock.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { strict: assert } = require('assert');
const {
defaultGanacheOptions,
openMenuSafe,
Expand Down Expand Up @@ -41,12 +40,11 @@ describe('Auto-Lock Timer', function () {
'[data-testid="advanced-setting-auto-lock"] button',
);
// Verify the wallet is locked
const pageTitle = await driver.findElement(
'[data-testid="unlock-page-title"]',
);
const unlockButton = await driver.findElement('.unlock-page button');
assert.equal(await pageTitle.getText(), 'Welcome back!');
assert.equal(await unlockButton.isDisplayed(), true);
await driver.waitForSelector({
css: '[data-testid="unlock-page-title"]',
text: 'Welcome back!',
});
await driver.waitForSelector('.unlock-page button');
},
);
});
Expand Down
32 changes: 25 additions & 7 deletions test/e2e/tests/settings/localization.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
const { strict: assert } = require('assert');
const {
defaultGanacheOptions,
withFixtures,
unlockWallet,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');

async function mockPhpConversion(mockServer) {
return await mockServer
.forGet('https://min-api.cryptocompare.com/data/price')
.withQuery({ fsym: 'ETH', tsyms: 'PHP,USD' })
.thenCallback(() => {
return {
statusCode: 200,
json: {
PHP: '100000',
USD: '2500',
},
};
});
}

describe('Localization', function () {
it('can correctly display Philippine peso symbol and code', async function () {
await withFixtures(
Expand All @@ -22,18 +36,22 @@ describe('Localization', function () {
})
.build(),
ganacheOptions: defaultGanacheOptions,
testSpecificMock: mockPhpConversion,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

// After the removal of displaying secondary currency in coin-overview.tsx, we will test localization on main balance with showNativeTokenAsMainBalance = false
const primaryBalance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
const balanceText = await primaryBalance.getText();
assert.ok(balanceText.startsWith('₱'));
assert.ok(balanceText.endsWith('PHP'));
await driver.waitForSelector({
tag: 'span',
text: 'PHP',
});

await driver.waitForSelector({
tag: 'span',
text: '₱2,500,000.00',
});
},
);
});
Expand Down
15 changes: 2 additions & 13 deletions test/e2e/tests/settings/settings-general.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { strict: assert } = require('assert');
const {
defaultGanacheOptions,
openMenuSafe,
Expand Down Expand Up @@ -28,25 +27,15 @@ describe('Settings', function () {
'[data-testid="jazz_icon"] .settings-page__content-item__identicon__item__icon--active',
);

const jazziconText = await driver.findElement({
await driver.waitForSelector({
tag: 'h6',
text: 'Jazzicons',
});
assert.equal(
await jazziconText.getText(),
'Jazzicons',
'Text for icon should be Jazzicons',
);

const blockiesText = await driver.findElement({
await driver.waitForSelector({
tag: 'h6',
text: 'Blockies',
});
assert.equal(
await blockiesText.getText(),
'Blockies',
'Text for icon should be Blockies',
);
},
);
});
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/tests/settings/settings-security-reveal-srp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ describe('Reveal SRP through settings', function () {
await tapAndHoldToRevealSRP(driver);

// confirm SRP text matches expected
const displayedSRP = await driver.findVisibleElement(
'[data-testid="srp_text"]',
);
assert.equal(await displayedSRP.getText(), E2E_SRP);
await driver.waitForSelector({
css: '[data-testid="srp_text"]',
text: E2E_SRP,
});

// copy SRP text to clipboard
await driver.clickElement({
Expand Down
14 changes: 4 additions & 10 deletions test/e2e/tests/settings/show-hex-data.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { strict: assert } = require('assert');
const {
defaultGanacheOptions,
withFixtures,
Expand Down Expand Up @@ -84,15 +83,10 @@ describe('Check the toggle for hex data', function () {
await sendTransactionAndVerifyHexData(driver);

// Verify hex data in the container content
const pageContentContainer = await driver.findElement(
selectors.containerContent,
);
const pageContentContainerText = await pageContentContainer.getText();
assert.equal(
pageContentContainerText.includes(inputData.hexDataText),
true,
'Hex data is incorrect',
);
await driver.waitForSelector({
tag: 'p',
text: '0x0abc',
});
},
);
});
Expand Down

0 comments on commit 5983dc1

Please sign in to comment.