Skip to content

Commit

Permalink
wip: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Apr 16, 2024
1 parent c4d2a91 commit 4306e89
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 80 deletions.
168 changes: 91 additions & 77 deletions src/app/pages/receive/components/receive-tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { copyToClipboard } from '@app/common/utils/copy-to-clipboard';
import { useToast } from '@app/features/toasts/use-toast';
import { useAlexSwap } from '@app/pages/swap/hooks/use-alex-swap';
import { SwapAsset } from '@app/pages/swap/hooks/use-swap-form';
import { SwapContext, SwapProvider, useSwapContext } from '@app/pages/swap/swap.context';
import { sortSwappableAssetsBySymbol } from '@app/pages/swap/swap.utils';
import { Avatar, defaultFallbackDelay, getAvatarFallback } from '@app/ui/components/avatar/avatar';
import { Brc20AvatarIcon } from '@app/ui/components/avatar/brc20-avatar-icon';
import { BtcAvatarIcon } from '@app/ui/components/avatar/btc-avatar-icon';
import { RunesAvatarIcon } from '@app/ui/components/avatar/runes-avatar-icon';
Expand Down Expand Up @@ -51,89 +51,103 @@ export function ReceiveTokens({
[createSwapAssetFromAlexCurrency, supportedCurrencies]
);

// console.log(swappableAssetsQuote);
const swapContextValue: SwapContext = {
// fetchToAmount,
// isFetchingExchangeRate,
// isSendingMax,
// onSetIsFetchingExchangeRate,
// onSetIsSendingMax: value => setIsSendingMax(value),
// onSubmitSwapForReview,
// onSubmitSwap,
// swappableAssetsBase: migratePositiveBalancesToTop(swappableAssets),
swappableAssetsQuote: swappableAssets,
// swapSubmissionData,
};
const receivableAssets = useMemo(
() =>
swappableAssets
.filter(asset => asset.name !== 'STX')
.map(asset => ({
address: asset.principal.split('.')[0], // TODO check this is correct and clean up
fallback: getAvatarFallback(asset.balance.symbol),
icon: asset.icon,
name: asset.name,
})),
[swappableAssets]
);

// console.log('swapContextValue', swapContextValue);
return (
<SwapProvider value={swapContextValue}>
<Stack className={css(receiveTabStyle)}>
<ReceiveItem
address={btcAddressNativeSegwit}
icon={<BtcAvatarIcon />}
dataTestId={HomePageSelectors.ReceiveBtcNativeSegwitQrCodeBtn}
onCopyAddress={async () => {
await copyToClipboard(btcAddressNativeSegwit);
toast.success('Copied to clipboard!');
}}
onClickQrCode={onClickQrBtc}
title="Bitcoin"
/>
<ReceiveItem
address={stxAddress}
icon={<StxAvatarIcon />}
dataTestId={HomePageSelectors.ReceiveStxQrCodeBtn}
onCopyAddress={async () => {
await copyToClipboard(stxAddress);
toast.success('Copied to clipboard!');
}}
onClickQrCode={onClickQrStx}
title="Stacks"
/>
<ReceiveItem
address={btcAddressTaproot}
icon={<Brc20AvatarIcon />}
dataTestId={HomePageSelectors.ReceiveBtcTaprootQrCodeBtn}
onCopyAddress={async () => {
await copyToClipboard(btcAddressTaproot);
toast.success('Copied to clipboard!');
}}
onClickQrCode={onClickQrOrdinal}
title="BRC-20"
/>
<ReceiveItem
address={btcAddressNativeSegwit}
icon={<Src20AvatarIcon />}
onClickQrCode={onClickQrStamp}
onCopyAddress={async () => {
await copyToClipboard(btcAddressNativeSegwit);
toast.success('Copied to clipboard!');
}}
title="SRC-20"
/>
<Stack className={css(receiveTabStyle)}>
<ReceiveItem
address={btcAddressNativeSegwit}
icon={<BtcAvatarIcon />}
dataTestId={HomePageSelectors.ReceiveBtcNativeSegwitQrCodeBtn}
onCopyAddress={async () => {
await copyToClipboard(btcAddressNativeSegwit);
toast.success('Copied to clipboard!');
}}
onClickQrCode={onClickQrBtc}
title="Bitcoin"
/>
<ReceiveItem
address={stxAddress}
icon={<StxAvatarIcon />}
dataTestId={HomePageSelectors.ReceiveStxQrCodeBtn}
onCopyAddress={async () => {
await copyToClipboard(stxAddress);
toast.success('Copied to clipboard!');
}}
onClickQrCode={onClickQrStx}
title="Stacks"
/>
<ReceiveItem
address={btcAddressTaproot}
icon={<Brc20AvatarIcon />}
dataTestId={HomePageSelectors.ReceiveBtcTaprootQrCodeBtn}
onCopyAddress={async () => {
await copyToClipboard(btcAddressTaproot);
toast.success('Copied to clipboard!');
}}
onClickQrCode={onClickQrOrdinal}
title="BRC-20"
/>
<ReceiveItem
address={btcAddressNativeSegwit}
icon={<Src20AvatarIcon />}
onClickQrCode={onClickQrStamp}
onCopyAddress={async () => {
await copyToClipboard(btcAddressNativeSegwit);
toast.success('Copied to clipboard!');
}}
title="SRC-20"
/>

<ReceiveItem
address={btcAddressNativeSegwit}
icon={<RunesAvatarIcon />}
onClickQrCode={onClickQrStamp}
onCopyAddress={async () => {
await copyToClipboard(btcAddressNativeSegwit);
toast.success('Copied to clipboard!');
}}
title="Runes Segwit"
/>
<ReceiveItem
address={btcAddressTaproot}
icon={<RunesAvatarIcon />}
onClickQrCode={onClickQrStamp}
onCopyAddress={async () => {
await copyToClipboard(btcAddressTaproot);
toast.success('Copied to clipboard!');
}}
title="Runes Taproot"
/>
{receivableAssets.map(asset => (
<ReceiveItem
address={btcAddressNativeSegwit}
icon={<RunesAvatarIcon />}
onClickQrCode={onClickQrStamp}
onCopyAddress={async () => {
await copyToClipboard(btcAddressNativeSegwit);
toast.success('Copied to clipboard!');
}}
title="Runes Segwit"
/>
<ReceiveItem
address={btcAddressTaproot}
icon={<RunesAvatarIcon />}
onClickQrCode={onClickQrStamp}
key={asset.name}
address={asset.address}
icon={
<Avatar.Root>
<Avatar.Image alt={asset.fallback} src={asset.icon} />
<Avatar.Fallback delayMs={defaultFallbackDelay}>{asset.fallback}</Avatar.Fallback>
</Avatar.Root>
}
// onClickQrCode={() => null}
onCopyAddress={async () => {
await copyToClipboard(btcAddressTaproot);
await copyToClipboard(asset.address);
toast.success('Copied to clipboard!');
}}
title="Runes Taproot"
title={asset.name}
/>
</Stack>
</SwapProvider>
))}
</Stack>
);
}
7 changes: 4 additions & 3 deletions tests/page-object-models/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ export class HomePage {
await this.page.getByTestId(HomePageSelectors.ReceiveCryptoAssetBtn).click();
}

async goToSwapPage() {
await this.page.getByTestId(HomePageSelectors.SwapBtn).click();
}
// No tests use this
// async goToSwapPage() {
// await this.page.getByTestId(HomePageSelectors.SwapBtn).click();
// }

// Open issue with Playwright's ability to copyToClipboard from legacy tests:
// https://github.com/microsoft/playwright/issues/8114#issuecomment-1103317576
Expand Down
34 changes: 34 additions & 0 deletions tests/specs/receive/receive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 3 of 8

[chromium] › specs/receive/receive.spec.ts:17:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Native Segwit address

1) [chromium] › specs/receive/receive.spec.ts:17:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Native Segwit address Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 3 of 8

[chromium] › specs/receive/receive.spec.ts:17:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Native Segwit address

1) [chromium] › specs/receive/receive.spec.ts:17:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Native Segwit address Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 3 of 8

[chromium] › specs/receive/receive.spec.ts:17:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Native Segwit address

1) [chromium] › specs/receive/receive.spec.ts:17:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Native Segwit address Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 4 of 8

[chromium] › specs/receive/receive.spec.ts:22:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Taproot address

1) [chromium] › specs/receive/receive.spec.ts:22:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Taproot address Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 4 of 8

[chromium] › specs/receive/receive.spec.ts:22:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Taproot address

1) [chromium] › specs/receive/receive.spec.ts:22:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Taproot address Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 4 of 8

[chromium] › specs/receive/receive.spec.ts:22:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Taproot address

1) [chromium] › specs/receive/receive.spec.ts:22:5 › Receive Dialog: Address generation › Bitcoin › that the wallet generates the correct Taproot address Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 4 of 8

[chromium] › specs/receive/receive.spec.ts:29:5 › Receive Dialog: Address generation › Stacks › that restoring a wallet generates the correct stacks address

2) [chromium] › specs/receive/receive.spec.ts:29:5 › Receive Dialog: Address generation › Stacks › that restoring a wallet generates the correct stacks address Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 4 of 8

[chromium] › specs/receive/receive.spec.ts:29:5 › Receive Dialog: Address generation › Stacks › that restoring a wallet generates the correct stacks address

2) [chromium] › specs/receive/receive.spec.ts:29:5 › Receive Dialog: Address generation › Stacks › that restoring a wallet generates the correct stacks address Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.

Check failure on line 1 in tests/specs/receive/receive.spec.ts

View workflow job for this annotation

GitHub Actions / Shard 4 of 8

[chromium] › specs/receive/receive.spec.ts:29:5 › Receive Dialog: Address generation › Stacks › that restoring a wallet generates the correct stacks address

2) [chromium] › specs/receive/receive.spec.ts:29:5 › Receive Dialog: Address generation › Stacks › that restoring a wallet generates the correct stacks address Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.
TEST_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS,
TEST_ACCOUNT_1_STX_ADDRESS,
TEST_ACCOUNT_1_TAPROOT_ADDRESS,
} from '@tests/mocks/constants';

import { test } from '../../fixtures/fixtures';

test.describe('Receive Dialog: Address generation', () => {
test.beforeEach(async ({ extensionId, globalPage, onboardingPage, homePage }) => {
await globalPage.setupAndUseApiCalls(extensionId);
await onboardingPage.signInExistingUser();
await homePage.goToReceiveDialog();
});

test.describe('Bitcoin', () => {
test('that the wallet generates the correct Native Segwit address', async ({ homePage }) => {
const nativeSegwitAddress = await homePage.getReceiveNativeSegwitAddress();
test.expect(nativeSegwitAddress).toEqual(TEST_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS);
});

test('that the wallet generates the correct Taproot address', async ({ homePage }) => {
const taprootAddress = await homePage.getReceiveTaprootAddress();
test.expect(taprootAddress).toEqual(TEST_ACCOUNT_1_TAPROOT_ADDRESS);
});
});

test.describe('Stacks', () => {
test('that restoring a wallet generates the correct stacks address', async ({ homePage }) => {
const stacksAddress = await homePage.getReceiveStxAddress();
test.expect(stacksAddress).toEqual(TEST_ACCOUNT_1_STX_ADDRESS);
});
});
});

0 comments on commit 4306e89

Please sign in to comment.