Skip to content

Commit

Permalink
feat: validate asset names during e2e contract tests (#1319)
Browse files Browse the repository at this point in the history
- Added aria labels to Recipient Sender and Asset Name on transaction
approval screen;
- Create util for checking text content on multiple aria labels;
- Validate all asset names during e2e contract tests on the transaction
approval screen, executes validation on all e2e contract test files.
  • Loading branch information
arthurgeron committed Jun 28, 2024
1 parent f25e3da commit e3bf65a
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/new-cars-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"fuels-wallet": patch
---

- Added aria labels to Recipient Sender and Asset Name on transaction approval screen;
- Validate all asset names during e2e contract tests on the transaction approval screen
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ const AssetsAmountItem = ({ assetAmount }: AssetsAmountItemProps) => {
) : (
<Avatar.Generated hash={assetId} size="xsm" />
)}
<Text as="span">{name || 'Unknown'}</Text>
<Text as="span" aria-label="Asset Name">
{name || 'Unknown'}
</Text>
</Box.Flex>
<Copyable value={assetId} css={styles.address}>
<Text fontSize="xs" css={{ mt: '$1' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ export const TxRecipientCard: TxRecipientCardComponent = ({
</Box>
)}
<Box.Flex css={styles.info}>
<Heading as="h6" css={styles.name}>
<Heading
as="h6"
css={styles.name}
aria-label={`${isReceiver ? 'Recipient' : 'Sender'} ${
isNetwork ? 'Address' : 'Name'
}`}
>
{isNetwork ? address : name}
</Heading>
{!isNetwork && (
Expand Down
10 changes: 10 additions & 0 deletions packages/e2e-contract-tests/playwright/e2e/DepositHalfEth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
checkFee,
connect,
waitSuccessTransaction,
Expand Down Expand Up @@ -59,6 +60,15 @@ test.describe('Deposit Half ETH', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');

// test forward asset name is shown
await hasText(walletNotificationPage, 'Ethereum');
// test forward asset id is shown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
checkFee,
connect,
waitSuccessTransaction,
Expand Down Expand Up @@ -66,6 +67,15 @@ test.describe('Forward and Mint Multicall', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');

// test forward asset name is shown
await hasText(walletNotificationPage, 'Ethereum');
// test forward asset id is shown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
checkFee,
connect,
waitSuccessTransaction,
Expand Down Expand Up @@ -80,6 +81,15 @@ test.describe('Forward Custom Asset', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');

// test the asset name is shown
await hasText(walletNotificationPage, 'Unknown', 0, 5000, true);

Expand Down
10 changes: 10 additions & 0 deletions packages/e2e-contract-tests/playwright/e2e/ForwardEth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
checkFee,
connect,
waitSuccessTransaction,
Expand Down Expand Up @@ -57,6 +58,15 @@ test.describe('Forward Eth', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');

// test the asset name is shown
await hasText(walletNotificationPage, 'Ethereum');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { EXTERNAL_CONTRACT_ID, MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
checkFee,
connect,
waitSuccessTransaction,
Expand Down Expand Up @@ -69,6 +70,15 @@ test.describe('Forward Half ETH and Mint External Custom Asset', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');

// test forward asset name is shown
await hasText(walletNotificationPage, 'Ethereum');
// test forward asset id is shown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
checkFee,
connect,
waitSuccessTransaction,
Expand Down Expand Up @@ -67,6 +68,15 @@ test.describe('Forward Half ETH and Mint Custom Asset', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');

// test forward asset name is shown
await hasText(walletNotificationPage, 'Ethereum');
// test forward asset id is shown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import { testSetup, transferMaxBalance } from '../utils';

import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import { checkAddresses, connect, waitSuccessTransaction } from './utils';
import {
checkAddresses,
checkAriaLabelsContainsText,
connect,
waitSuccessTransaction
} from './utils';

useLocalCRX();
test.describe('Forward Half Custom Asset', () => {
Expand Down Expand Up @@ -77,6 +82,14 @@ test.describe('Forward Half Custom Asset', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');
// test the forward asset name is shown
await hasText(walletNotificationPage, 'Unknown', 0, 5000, true);
// test forward asset id is correct
Expand Down
10 changes: 10 additions & 0 deletions packages/e2e-contract-tests/playwright/e2e/MintAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
checkFee,
connect,
waitSuccessTransaction,
Expand Down Expand Up @@ -131,6 +132,15 @@ test.describe('Mint Assets', () => {
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();

// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');

await hasText(walletNotificationPage, name);
await hasText(walletNotificationPage, shortAddress(assetId), 0, 10000);
// test mint amount is correct
Expand Down
18 changes: 18 additions & 0 deletions packages/e2e-contract-tests/playwright/e2e/utils/elements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Page } from '@playwright/test';

export async function checkAriaLabelsContainsText(
walletNotificationPage: Page,
ariaLabel: string,
text: string
) {
const locator = walletNotificationPage.locator(`[aria-label="${ariaLabel}"]`);
const count = await locator.count();

for (let i = 0; i < count; i++) {
if (text === '') {
expect(locator.nth(i).innerHTML()).not.toBe('');
} else {
expect((await locator.nth(i).innerHTML()).includes(text)).toBeTruthy();
}
}
}
1 change: 1 addition & 0 deletions packages/e2e-contract-tests/playwright/e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './transaction';
export * from './contract';
export * from './address';
export * from './elements';

0 comments on commit e3bf65a

Please sign in to comment.