Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: validate asset names during e2e contract tests #1319

Merged
merged 8 commits into from
Jun 28, 2024
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 @@ -43,7 +43,7 @@ export const AssetsAmount: AssetsAmountComponent = ({
<Box.Flex css={styles.header}>
{title && (
<Text as="h3" css={styles.title}>
{title}
{title}ss
arthurgeron marked this conversation as resolved.
Show resolved Hide resolved
</Text>
)}
{hasError && (
Expand Down 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { testSetup } from '../utils';

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

useLocalCRX();

Expand Down Expand Up @@ -43,6 +48,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 @@ -14,7 +14,12 @@ import { testSetup } from '../utils';

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

useLocalCRX();

Expand Down Expand Up @@ -51,6 +56,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 @@ -16,7 +16,12 @@ import { testSetup } from '../utils';

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

useLocalCRX();

Expand Down Expand Up @@ -66,6 +71,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
16 changes: 15 additions & 1 deletion packages/e2e-contract-tests/playwright/e2e/ForwardEth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { testSetup } from '../utils';

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

useLocalCRX();

Expand Down Expand Up @@ -42,6 +47,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 @@ -14,7 +14,7 @@ import { testSetup } from '../utils';

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

useLocalCRX();

Expand Down Expand Up @@ -52,6 +52,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 @@ -14,7 +14,12 @@ import { testSetup } from '../utils';

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

useLocalCRX();

Expand Down Expand Up @@ -51,6 +56,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,7 @@ import { testSetup } from '../utils';

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

useLocalCRX();
test.describe('Forward Half Custom Asset', () => {
Expand Down Expand Up @@ -66,6 +66,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
16 changes: 15 additions & 1 deletion packages/e2e-contract-tests/playwright/e2e/MintAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { testSetup } from '../utils';

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

useLocalCRX();

Expand Down Expand Up @@ -119,6 +124,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();
}
}
}
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';
Loading