Skip to content

Commit

Permalink
data-testid hit targets for automated tests (#1833)
Browse files Browse the repository at this point in the history
* add data-testid to three components

- chain modal button
- asset menu button
- connect wallet button

* more test ids for bridging view

* add final testids
  • Loading branch information
artursapek committed Apr 1, 2024
1 parent 5e87522 commit f232766
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 17 deletions.
2 changes: 2 additions & 0 deletions wormhole-connect/src/components/AlertBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Props = {
warning?: boolean;
error?: boolean;
margin?: string;
testId?: string;
};

function AlertBanner(props: Props) {
Expand All @@ -43,6 +44,7 @@ function AlertBanner(props: Props) {
!!props.error && classes.error,
])}
style={{ margin: props.margin || 0 }}
data-testid={props.testId}
>
<AlertIcon />
{props.content}
Expand Down
2 changes: 2 additions & 0 deletions wormhole-connect/src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Props = {
disabled?: boolean;
children: React.ReactNode;
onClick?: MouseEventHandler<HTMLDivElement>;
testId?: string;
};

function Button(props: Props) {
Expand All @@ -59,6 +60,7 @@ function Button(props: Props) {
!!props.disabled && classes.disabled,
])}
onClick={click}
data-testid={props.testId}
>
{props.children}
</div>
Expand Down
8 changes: 7 additions & 1 deletion wormhole-connect/src/components/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import WalletIcons from 'icons/WalletIcons';
import PopupState, { bindTrigger, bindPopover } from 'material-ui-popup-state';
import Popover from '@mui/material/Popover';
import config from 'config';
import { TransferSide } from 'config/types';
import { ExplorerConfig } from 'config/types';

type StyleProps = { disabled?: boolean };
Expand Down Expand Up @@ -57,6 +58,7 @@ const useStyles = makeStyles<StyleProps>()((theme: any, { disabled }) => ({
}));

type Props = {
side: TransferSide;
type: TransferWallet;
disabled?: boolean;
};
Expand Down Expand Up @@ -181,7 +183,11 @@ function ConnectWallet(props: Props) {
);
} else {
const button = (
<div className={classes.connectWallet} onClick={() => connect()}>
<div
className={classes.connectWallet}
onClick={() => connect()}
data-testid={`${props.side}-section-connect-wallet-button`}
>
<WalletIcon />
<div>{mobile ? 'Connect' : 'Connect wallet'}</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion wormhole-connect/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Props = {
text: string;
align?: Alignment;
size?: number;
testId?: string;
};

function Header(props: Props) {
Expand All @@ -30,7 +31,11 @@ function Header(props: Props) {
fontSize: props.size || 42,
};
const { classes } = useStyles(styleProps);
return <div className={classes.title}>{props.text}</div>;
return (
<div className={classes.title} data-test-id={props.testId}>
{props.text}
</div>
);
}

export default Header;
2 changes: 2 additions & 0 deletions wormhole-connect/src/components/InputTransparent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Props = {
onEnter?: React.KeyboardEventHandler;
disabled?: boolean;
value?: string | number;
testId?: string;
};

const NUMBER_FORMAT_REGEX = /^\d*\.?\d*$/;
Expand Down Expand Up @@ -76,6 +77,7 @@ function InputTransparent(props: Props) {
onKeyDown={handleKeyDown}
readOnly={props.disabled}
value={props.value}
data-testid={props.testId}
/>
);
}
Expand Down
4 changes: 3 additions & 1 deletion wormhole-connect/src/components/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type PageHeaderProps = {
description?: string;
back?: boolean;
showHamburgerMenu?: boolean;
testId?: string;
};

function PageHeader({
Expand All @@ -60,6 +61,7 @@ function PageHeader({
align = 'left',
description,
showHamburgerMenu = true,
testId,
}: PageHeaderProps) {
const { classes } = useStyles({ showHamburgerMenu, align });
const dispatch = useDispatch();
Expand All @@ -78,7 +80,7 @@ function PageHeader({
onClick={goBack}
/>
)}
<Header text={title} align={align} />
<Header text={title} align={align} testId={testId} />
</div>
{showHamburgerMenu ? <MenuFull /> : null}
</div>
Expand Down
3 changes: 3 additions & 0 deletions wormhole-connect/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export enum Route {
wstETHBridge = 'wstETHBridge',
}

// Used in bridging components
export type TransferSide = 'source' | 'destination';

export type SupportedRoutes = keyof typeof Route;

export type Network = 'mainnet' | 'testnet' | 'devnet';
Expand Down
3 changes: 3 additions & 0 deletions wormhole-connect/src/views/Bridge/Inputs/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import Input from './Input';
import config from 'config';
import Price from 'components/Price';
import { getTokenPrice, getUSDFormat } from 'utils';
import { TransferSide } from 'config/types';

type Props = {
handleAmountChange: (value: number | string) => void;
value: string;
disabled?: boolean;
label?: string;
side: TransferSide;
};
function AmountInput(props: Props) {
const amountEl = useRef(null);
Expand Down Expand Up @@ -77,6 +79,7 @@ function AmountInput(props: Props) {
onChange={handleAmountChange}
disabled={isTransactionInProgress || props.disabled}
value={props.value}
testId={props.side + '-section-amount-input'}
/>
{price && <Price>{price}</Price>}
</>
Expand Down
13 changes: 10 additions & 3 deletions wormhole-connect/src/views/Bridge/Inputs/From.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function FromInputs() {
const tokenInput = (
<Select
label="Asset"
testId="source-section-select-asset-button"
selected={selectedToken}
error={!!(showErrors && validations.token)}
onClick={() => setShowTokensModal(true)}
Expand Down Expand Up @@ -148,7 +149,11 @@ function FromInputs() {
computeReceiveAmount(amount);
}, [route, amount, computeReceiveAmount]);
const amountInput = (
<AmountInput handleAmountChange={handleAmountChange} value={amount} />
<AmountInput
handleAmountChange={handleAmountChange}
value={amount}
side="source"
/>
);

const handleExtraNetwork = (
Expand All @@ -165,7 +170,7 @@ function FromInputs() {
return (
<>
<Inputs
title="From"
side="source"
wallet={TransferWallet.SENDING}
walletValidations={[validations.sendingWallet]}
walletError={wallet.error}
Expand Down Expand Up @@ -193,7 +198,9 @@ function FromInputs() {
<ChainsModal
open={showChainsModal}
title="Sending from"
chains={config.chainsArr.filter((c) => c.key !== toChain && !c.disabledAsSource)}
chains={config.chainsArr.filter(
(c) => c.key !== toChain && !c.disabledAsSource,
)}
onSelect={selectChain}
onClose={() => setShowChainsModal(false)}
onMoreNetworkSelect={(href, chainName, target) =>
Expand Down
20 changes: 16 additions & 4 deletions wormhole-connect/src/views/Bridge/Inputs/Inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useMediaQuery from '@mui/material/useMediaQuery';
import { ChainName } from '@wormhole-foundation/wormhole-connect-sdk';

import config from 'config';
import { TransferSide } from 'config/types';
import { RootState } from 'store';
import { ValidationErr } from 'store/transferInput';
import { NO_INPUT } from 'utils/style';
Expand Down Expand Up @@ -107,7 +108,7 @@ const useStyles = makeStyles()((theme) => ({
}));

type Props = {
title: string;
side: TransferSide;
wallet: TransferWallet;
walletError: string;
walletValidations: string[];
Expand Down Expand Up @@ -145,13 +146,21 @@ function Inputs(props: Props) {
return '';
}, [props.tokenPrice, props.balance]);

const title = {
source: 'From',
destination: 'To',
}[props.side];

const chainTestId = props.side + '-section-select-network-button';

return (
<div className={classes.container}>
<div className={classes.errorContainer}>
<div className={classes.header}>
<div className={classes.headerTitle}>{props.title}</div>
<div className={classes.headerTitle}>{title}</div>
{/* connect wallet button */}
<ConnectWallet
side={props.side}
type={props.wallet}
disabled={isTransactionInProgress || !selectedChain}
/>
Expand All @@ -178,7 +187,7 @@ function Inputs(props: Props) {
<div className={classes.content}>
{/* chain tile */}
{!mobile && (
<div className={classes.chain}>
<div className={classes.chain} data-testid={chainTestId}>
<ChainTile
chain={chainConfig}
error={!!(showErrors && props.chainValidation)}
Expand Down Expand Up @@ -212,7 +221,10 @@ function Inputs(props: Props) {
<div className={classes.amount}>{props.amountInput}</div>

{/* balance */}
<div className={classes.balance}>
<div
className={classes.balance}
data-testid={`${props.side}-section-balance-text`}
>
<Input label="Balance" disabled>
<div>
{props.balance ? (
Expand Down
5 changes: 3 additions & 2 deletions wormhole-connect/src/views/Bridge/Inputs/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Selected = {

type Props = {
label: string;
testId?: string;
selected: Selected | undefined;
error?: boolean;
editable?: boolean;
Expand All @@ -54,7 +55,7 @@ function Select(props: Props) {
onClick={handleClick}
>
{selected ? (
<div className={classes.select}>
<div className={classes.select} data-testid={props.testId}>
<TokenIcon icon={selected.icon} height={24} />
{selected.text}
{selected.secondaryText && (
Expand All @@ -66,7 +67,7 @@ function Select(props: Props) {
) : props.disabled ? (
NO_INPUT
) : (
<div className={classes.select}>
<div className={classes.select} data-testid={props.testId}>
<TokenIcon height={24} />
Select
</div>
Expand Down
8 changes: 6 additions & 2 deletions wormhole-connect/src/views/Bridge/Inputs/To.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function ToInputs() {
const tokenInput = (
<Select
label="Asset"
testId="destination-section-select-asset-button"
selected={selectedToken}
error={!!(showErrors && validations.token)}
onClick={() => setShowTokensModal(true)}
Expand Down Expand Up @@ -122,6 +123,7 @@ function ToInputs() {
value={receiveAmount.data || ''}
disabled
label={label}
side="destination"
/>
);

Expand All @@ -139,7 +141,7 @@ function ToInputs() {
return (
<>
<Inputs
title="To"
side="destination"
wallet={TransferWallet.RECEIVING}
walletValidations={[validations.receivingWallet]}
walletError={receiving.error}
Expand Down Expand Up @@ -169,7 +171,9 @@ function ToInputs() {
<ChainsModal
open={showChainsModal}
title="Sending to"
chains={config.chainsArr.filter((c) => c.key !== fromChain && !c.disabledAsDestination)}
chains={config.chainsArr.filter(
(c) => c.key !== fromChain && !c.disabledAsDestination,
)}
onSelect={selectChain}
onClose={() => setShowChainsModal(false)}
onMoreNetworkSelect={(href, chainName, target) =>
Expand Down
1 change: 1 addition & 0 deletions wormhole-connect/src/views/Bridge/RouteOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ function RouteOption(props: { route: RouteData; disabled: boolean }) {
className={`${classes.route} ${
props.disabled ? classes.disabled : ''
}`}
data-testid={`route-option-${props.route.route}`}
>
<div className={classes.routeLeft}>
<div className={classes.routeTitle}>
Expand Down
2 changes: 2 additions & 0 deletions wormhole-connect/src/views/Bridge/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ function Send(props: { valid: boolean }) {
content={sendError}
error
margin="0 0 16px 0"
testId="send-error-message"
/>
{props.valid && !isConnected ? (
<Button disabled elevated>
Expand All @@ -266,6 +267,7 @@ function Send(props: { valid: boolean }) {
onClick={send}
action={props.valid}
disabled={disabled}
testId="approve-button"
elevated
>
{isTransactionInProgress ? (
Expand Down
3 changes: 3 additions & 0 deletions wormhole-connect/src/views/Redeem/AddToWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function AddToSolanaWallet({ token, address }: AddTokenProps) {
chain={'solana'}
type={'address'}
address={address}
side="destination"
/>
</Typography>
);
Expand All @@ -130,6 +131,7 @@ function AddToSuiWallet({ token, address }: AddTokenProps) {
chain={'sui'}
type={'object'}
object={address}
side="destination"
/>
</Typography>
);
Expand All @@ -150,6 +152,7 @@ function AddToAptosWallet({ token, address }: AddTokenProps) {
chain={'aptos'}
type={'address'}
address={tokenAccount}
side="destination"
/>
</Typography>
);
Expand Down
6 changes: 5 additions & 1 deletion wormhole-connect/src/views/Redeem/BridgeComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ function BridgeComplete() {
};

let containerBg: string | undefined = undefined;
let component: React.JSX.Element = <div>The bridge is now complete.</div>;
let component: React.JSX.Element = (
<div data-testid="transaction-complete-message">
The bridge is now complete.
</div>
);
if (
isPorticoTransferDestInfo(transferDestInfo) &&
transferDestInfo.destTxInfo.swapFailed
Expand Down
Loading

0 comments on commit f232766

Please sign in to comment.