From 1b01de1e0b8e1ff5159507a31578c9831ec9d267 Mon Sep 17 00:00:00 2001 From: Oskar Date: Wed, 12 Jun 2024 15:21:37 +0200 Subject: [PATCH] Add e2e tests for native max DAI withdrawal --- .../withdraw/e2e/WithdrawMaxDAI.test-e2e.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 packages/app/src/features/dialogs/savings/withdraw/e2e/WithdrawMaxDAI.test-e2e.ts diff --git a/packages/app/src/features/dialogs/savings/withdraw/e2e/WithdrawMaxDAI.test-e2e.ts b/packages/app/src/features/dialogs/savings/withdraw/e2e/WithdrawMaxDAI.test-e2e.ts new file mode 100644 index 000000000..c42c0003e --- /dev/null +++ b/packages/app/src/features/dialogs/savings/withdraw/e2e/WithdrawMaxDAI.test-e2e.ts @@ -0,0 +1,69 @@ +import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject' +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { setupFork } from '@/test/e2e/setupFork' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { SavingsDialogPageObject } from '../../common/e2e/SavingsDialog.PageObject' + +test.describe('Withdraw max DAI on Mainnet', () => { + const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id }) + let savingsPage: SavingsPageObject + let withdrawalDialog: SavingsDialogPageObject + + test.beforeEach(async ({ page }) => { + await setup(page, fork, { + initialPage: 'savings', + account: { + type: 'connected', + assetBalances: { + ETH: 1, + sDAI: 10_000, + }, + }, + }) + + savingsPage = new SavingsPageObject(page) + await savingsPage.clickWithdrawButtonAction() + + withdrawalDialog = new SavingsDialogPageObject({ page, type: 'withdraw' }) + await withdrawalDialog.clickMaxAmountAction() + }) + + test('uses native sDai withdrawal', async () => { + await withdrawalDialog.expectToUseNativeSDaiAction({ asset: 'DAI', amount: 10_715.05 }) + }) + + test('displays transaction overview', async () => { + await withdrawalDialog.expectNativeRouteTransactionOverview({ + apy: { + value: '5.00%', + description: 'Earn ~535.75 DAI per year', + }, + routeItems: [ + { + tokenAmount: '10,000.00 sDAI', + tokenUsdValue: '$10,715.05', + }, + { + tokenAmount: '10,715.05 DAI', + tokenUsdValue: '$10,715.05', + }, + ], + outcome: '10,715.05 DAI worth $10,715.05', + }) + }) + + test('executes max withdrawal', async () => { + const actionsContainer = new ActionsPageObject(withdrawalDialog.locatePanelByHeader('Actions')) + await actionsContainer.acceptAllActionsAction(1) + + await withdrawalDialog.expectSuccessPage() + await withdrawalDialog.clickBackToSavingsButton() + + await savingsPage.expectPotentialProjection('$43.06', '30-day') + await savingsPage.expectPotentialProjection('$535.75', '1-year') + await savingsPage.expectCashInWalletAssetBalance('DAI', '10,715.05') + }) +})