diff --git a/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts index 98640b5db..61d1f99a6 100644 --- a/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/migrate/downgrade/DowngradeDialog.PageObject.ts @@ -1,38 +1,42 @@ -// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -// import { testIds } from '@/ui/utils/testIds' -// import { Page, expect } from '@playwright/test' +import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { expect } from '@playwright/test' -// export class DowngradeDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /Downgrade/) -// } +export class DowngradeDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ + testContext, + header: /Downgrade/, + }) + } -// // #region actions -// async clickBackToSavingsButton(): Promise { -// await this.page.getByRole('button', { name: 'Back to Savings' }).click() -// await this.region.waitFor({ -// state: 'detached', -// }) -// } -// // #endregion actions + // #region actions + async clickBackToSavingsButton(): Promise { + await this.page.getByRole('button', { name: 'Back to Savings' }).click() + await this.region.waitFor({ + state: 'detached', + }) + } + // #endregion actions -// // #region assertions -// async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { -// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) -// if (transactionOverview.badgeTokens) { -// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) -// } -// await this.expectOutcomeText(transactionOverview.outcome) -// } + // #region assertions + async expectTransactionOverview(transactionOverview: TxOverviewWithRoute): Promise { + await this.expectTransactionOverviewRoute(transactionOverview.routeItems) + if (transactionOverview.badgeTokens) { + await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) + } + await this.expectOutcomeText(transactionOverview.outcome) + } -// async expectDowngradeSuccessPage({ -// token, -// amount, -// usdValue, -// }: { token: string; amount: string; usdValue: string }): Promise { -// await expect(this.region.getByText('Congrats, all done!')).toBeVisible() -// const summary = await this.region.getByTestId(testIds.dialog.success).textContent() -// await expect(summary).toMatch(`${token}${amount} ${usdValue}`) -// } -// // #endregion assertions -// } + async expectDowngradeSuccessPage({ + token, + amount, + usdValue, + }: { token: string; amount: string; usdValue: string }): Promise { + await expect(this.region.getByText('Congrats, all done!')).toBeVisible() + const summary = await this.region.getByTestId(testIds.dialog.success).textContent() + await expect(summary).toMatch(`${token}${amount} ${usdValue}`) + } + // #endregion assertions +} diff --git a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts index f0715c43a..ebe145dd2 100644 --- a/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/downgrade/e2e/UsdsToDai.test-e2e.ts @@ -1,104 +1,117 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { DowngradeDialogPageObject } from '../DowngradeDialog.PageObject' - -// test.describe('Downgrade USDS to DAI', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - -// test('downgrade to DAI is disabled when USDS balance is 0', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 0 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectDowngradeToDaiToBeDisabled() -// }) - -// test('uses downgrade action', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDowngradeUsdsToDaiOption() - -// const downgradeDialog = new DowngradeDialogPageObject(page) -// await downgradeDialog.fillAmountAction(100) - -// await downgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await downgradeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'USDS' }, -// { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, -// ]) -// }) - -// test('displays transaction overview', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickDowngradeUsdsToDaiOption() - -// const downgradeDialog = new DowngradeDialogPageObject(page) -// await downgradeDialog.fillAmountAction(100) - -// await downgradeDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '100.00 USDS', -// tokenUsdValue: '$100.00', -// }, -// { -// tokenAmount: '100.00 DAI', -// tokenUsdValue: '$100.00', -// }, -// ], -// outcome: '100.00 DAI', -// outcomeUsd: '$100.00', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') -// await savingsPage.clickDowngradeUsdsToDaiOption() - -// const downgradeDialog = new DowngradeDialogPageObject(page) -// await downgradeDialog.fillAmountAction(10_000) - -// await downgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await downgradeDialog.expectDowngradeSuccessPage({ token: 'USDS', amount: '10,000.00', usdValue: '$10,000.00' }) -// await downgradeDialog.clickBackToSavingsButton() - -// await savingsPage.expectUpgradableDaiBalance('10,000.00') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { DowngradeDialogPageObject } from '../DowngradeDialog.PageObject' + +test.describe('Downgrade USDS to DAI', () => { + test('downgrade to DAI is disabled when USDS balance is 0', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 0 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectDowngradeToDaiToBeDisabled() + }) + + test('uses downgrade action', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDowngradeUsdsToDaiOption() + + const downgradeDialog = new DowngradeDialogPageObject(testContext) + await downgradeDialog.fillAmountAction(100) + + await downgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await downgradeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'USDS' }, + { type: 'downgrade', fromToken: 'USDS', toToken: 'DAI' }, + ]) + }) + + test('displays transaction overview', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickDowngradeUsdsToDaiOption() + + const downgradeDialog = new DowngradeDialogPageObject(testContext) + await downgradeDialog.fillAmountAction(100) + + await downgradeDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '100.00 USDS', + tokenUsdValue: '$100.00', + }, + { + tokenAmount: '100.00 DAI', + tokenUsdValue: '$100.00', + }, + ], + outcome: '100.00 DAI', + outcomeUsd: '$100.00', + }) + }) + + test('executes transaction', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectStablecoinsInWalletAssetBalance('DAI', '-') + await savingsPage.clickDowngradeUsdsToDaiOption() + + const downgradeDialog = new DowngradeDialogPageObject(testContext) + await downgradeDialog.fillAmountAction(10_000) + + await downgradeDialog.actionsContainer.acceptAllActionsAction(2) + await downgradeDialog.expectDowngradeSuccessPage({ token: 'USDS', amount: '10,000.00', usdValue: '$10,000.00' }) + await downgradeDialog.clickBackToSavingsButton() + + await savingsPage.expectUpgradableDaiBalance('10,000.00') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts index 3e59932a2..a4075f18b 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/UpgradeDialog.PageObject.ts @@ -1,56 +1,60 @@ -// import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' -// import { testIds } from '@/ui/utils/testIds' -// import { Page, expect } from '@playwright/test' +import { DialogPageObject, TxOverviewWithRoute } from '@/features/dialogs/common/Dialog.PageObject' +import { TestContext } from '@/test/e2e/setup' +import { testIds } from '@/ui/utils/testIds' +import { expect } from '@playwright/test' -// export class UpgradeDialogPageObject extends DialogPageObject { -// constructor(page: Page) { -// super(page, /Upgrade/) -// } +export class UpgradeDialogPageObject extends DialogPageObject { + constructor(testContext: TestContext) { + super({ + testContext, + header: /Upgrade/, + }) + } -// // #region actions -// async clickBackToSavingsButton(): Promise { -// await this.page.getByRole('button', { name: 'Back to Savings' }).click() -// await this.region.waitFor({ -// state: 'detached', -// }) -// } -// // #endregion actions + // #region actions + async clickBackToSavingsButton(): Promise { + await this.page.getByRole('button', { name: 'Back to Savings' }).click() + await this.region.waitFor({ + state: 'detached', + }) + } + // #endregion actions -// // #region assertions -// async expectTransactionOverview(transactionOverview: UpgradeTxOverview): Promise { -// const panel = this.locatePanelByHeader('Transaction overview') -// await expect(panel).toBeVisible() -// const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview + // #region assertions + async expectTransactionOverview(transactionOverview: UpgradeTxOverview): Promise { + const panel = this.locatePanelByHeader('Transaction overview') + await expect(panel).toBeVisible() + const savingsTxOverviewTestIds = testIds.dialog.savings.transactionOverview -// if (transactionOverview.apyChange) { -// const currentApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.before) -// const updatedApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.after) -// await expect(currentApyValue).toContainText(transactionOverview.apyChange.current) -// await expect(updatedApyValue).toContainText(transactionOverview.apyChange.updated) -// } + if (transactionOverview.apyChange) { + const currentApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.before) + const updatedApyValue = panel.getByTestId(savingsTxOverviewTestIds.apyChange.after) + await expect(currentApyValue).toContainText(transactionOverview.apyChange.current) + await expect(updatedApyValue).toContainText(transactionOverview.apyChange.updated) + } -// await this.expectTransactionOverviewRoute(transactionOverview.routeItems) -// if (transactionOverview.badgeTokens) { -// await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) -// } -// await this.expectOutcomeText(transactionOverview.outcome) -// } + await this.expectTransactionOverviewRoute(transactionOverview.routeItems) + if (transactionOverview.badgeTokens) { + await this.expectSkyBadgeForTokens(transactionOverview.badgeTokens) + } + await this.expectOutcomeText(transactionOverview.outcome) + } -// async expectUpgradeSuccessPage({ -// token, -// amount, -// usdValue, -// }: { token: string; amount: string; usdValue: string }): Promise { -// await expect(this.region.getByText('Congrats, all done!')).toBeVisible() -// const summary = await this.region.getByTestId(testIds.dialog.success).textContent() -// await expect(summary).toMatch(`${token}${amount} ${usdValue}`) -// } -// // #endregion assertions -// } + async expectUpgradeSuccessPage({ + token, + amount, + usdValue, + }: { token: string; amount: string; usdValue: string }): Promise { + await expect(this.region.getByText('Congrats, all done!')).toBeVisible() + const summary = await this.region.getByTestId(testIds.dialog.success).textContent() + await expect(summary).toMatch(`${token}${amount} ${usdValue}`) + } + // #endregion assertions +} -// interface UpgradeTxOverview extends TxOverviewWithRoute { -// apyChange?: { -// current: string -// updated: string -// } -// } +interface UpgradeTxOverview extends TxOverviewWithRoute { + apyChange?: { + current: string + updated: string + } +} diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts index 5ba3183d8..dbc46b945 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/DaiToUsds.test-e2e.ts @@ -1,110 +1,123 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' - -// test.describe('Upgrade DAI to USDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - -// test('does not show upgrade button when DAI balance is 0', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { USDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// // wait to load -// await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') - -// await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() -// }) - -// test('uses upgrade action', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { DAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickUpgradeDaiToUsdsButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await upgradeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'DAI' }, -// { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, -// ]) -// }) - -// test('displays transaction overview', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { DAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) -// await savingsPage.clickUpgradeDaiToUsdsButtonAction() -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.expectTransactionOverview({ -// routeItems: [ -// { -// tokenAmount: '10,000.00 DAI', -// tokenUsdValue: '$10,000.00', -// }, -// { -// tokenAmount: '10,000.00 USDS', -// tokenUsdValue: '$10,000.00', -// }, -// ], -// outcome: '10,000.00 USDS', -// outcomeUsd: '$10,000.00', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { DAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') -// await savingsPage.clickUpgradeDaiToUsdsButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await upgradeDialog.expectSuccessPage( -// [ -// { -// asset: 'DAI', -// amount: 10_000, -// }, -// ], -// fork, -// ) -// await upgradeDialog.clickBackToSavingsButton() - -// await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' + +test.describe('Upgrade DAI to USDS', () => { + test('does not show upgrade button when DAI balance is 0', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { USDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + // wait to load + await savingsPage.expectOpportunityStablecoinsAmount('~$10,000.00') + + await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() + }) + + test('uses upgrade action', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { DAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickUpgradeDaiToUsdsButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await upgradeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'DAI' }, + { type: 'upgrade', fromToken: 'DAI', toToken: 'USDS' }, + ]) + }) + + test('displays transaction overview', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { DAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickUpgradeDaiToUsdsButtonAction() + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.expectTransactionOverview({ + routeItems: [ + { + tokenAmount: '10,000.00 DAI', + tokenUsdValue: '$10,000.00', + }, + { + tokenAmount: '10,000.00 USDS', + tokenUsdValue: '$10,000.00', + }, + ], + outcome: '10,000.00 USDS', + outcomeUsd: '$10,000.00', + }) + }) + + test('executes transaction', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { DAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '-') + await savingsPage.clickUpgradeDaiToUsdsButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.actionsContainer.acceptAllActionsAction(2) + await upgradeDialog.expectSuccessPage({ + tokenWithValue: [ + { + asset: 'DAI', + amount: '10,000.00', + usdValue: '$10,000.00', + }, + ], + }) + await upgradeDialog.clickBackToSavingsButton() + + await savingsPage.expectStablecoinsInWalletAssetBalance('USDS', '10,000') + }) +}) diff --git a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts index 397001c77..811c3518a 100644 --- a/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts +++ b/packages/app/src/features/dialogs/savings/migrate/upgrade/e2e/sDaiToSUsds.test-e2e.ts @@ -1,105 +1,118 @@ -// import { SavingsPageObject } from '@/pages/Savings.PageObject' -// import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' -// import { setupFork } from '@/test/e2e/forking/setupFork' -// import { setup } from '@/test/e2e/setup' -// import { test } from '@playwright/test' -// import { mainnet } from 'viem/chains' -// import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' - -// test.describe('Upgrade sDAI to sUSDS', () => { -// const fork = setupFork({ blockNumber: DEFAULT_BLOCK_NUMBER, chainId: mainnet.id, useTenderlyVnet: true }) - -// test('does not show upgrade banner when sDai balance is 0', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 0, sUSDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// // wait to load -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '10,000.00 sUSDS', estimatedUsdsValue: '10,000.23' }) - -// await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() -// }) - -// test('uses upgrade action', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickUpgradeSDaiButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) -// await upgradeDialog.actionsContainer.expectActions([ -// { type: 'approve', asset: 'sDAI' }, -// { type: 'upgrade', fromToken: 'sDAI', toToken: 'sUSDS' }, -// ]) -// }) - -// test('displays transaction overview', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) - -// await savingsPage.clickUpgradeSDaiButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) - -// await upgradeDialog.expectTransactionOverview({ -// apyChange: { -// current: '6.00%', -// updated: '6.25%', -// }, -// routeItems: [ -// { -// tokenAmount: '10,000.00 sDAI', -// tokenUsdValue: '$11,085.91', -// }, -// { -// tokenAmount: '11,085.65 sUSDS', -// tokenUsdValue: '$11,085.91', -// }, -// ], -// outcome: '11,085.65 sUSDS', -// outcomeUsd: '$11,085.91', -// }) -// }) - -// test('executes transaction', async ({ page }) => { -// await setup(page, fork, { -// initialPage: 'savings', -// account: { -// type: 'connected-random', -// assetBalances: { sDAI: 10_000, sUSDS: 10_000 }, -// }, -// }) - -// const savingsPage = new SavingsPageObject(page) -// await savingsPage.clickUpgradeSDaiButtonAction() - -// const upgradeDialog = new UpgradeDialogPageObject(page) -// await upgradeDialog.actionsContainer.acceptAllActionsAction(2, fork) -// await upgradeDialog.expectUpgradeSuccessPage({ token: 'sDAI', amount: '10,000.00', usdValue: '$11,085.91' }) -// await upgradeDialog.clickBackToSavingsButton() - -// await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '21,085.65 sUSDS', estimatedUsdsValue: '21,086.13' }) -// }) -// }) +import { SavingsPageObject } from '@/pages/Savings.PageObject' +import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants' +import { setup } from '@/test/e2e/setup' +import { test } from '@playwright/test' +import { mainnet } from 'viem/chains' +import { UpgradeDialogPageObject } from '../UpgradeDialog.PageObject' + +test.describe('Upgrade sDAI to sUSDS', () => { + test('does not show upgrade banner when sDai balance is 0', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 0, sUSDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + // wait to load + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '10,000.00 sUSDS', estimatedUsdsValue: '10,172.58' }) + + await savingsPage.expectUpgradeDaiToUsdsButtonToBeHidden() + }) + + test('uses upgrade action', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickUpgradeSDaiButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.actionsContainer.expectEnabledActionAtIndex(0) + await upgradeDialog.actionsContainer.expectActions([ + { type: 'approve', asset: 'sDAI' }, + { type: 'upgrade', fromToken: 'sDAI', toToken: 'sUSDS' }, + ]) + }) + + test('displays transaction overview', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + + await savingsPage.clickUpgradeSDaiButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + + await upgradeDialog.expectTransactionOverview({ + apyChange: { + current: '11.50%', + updated: '12.50%', + }, + routeItems: [ + { + tokenAmount: '10,000.00 sDAI', + tokenUsdValue: '$11,255.99', + }, + { + tokenAmount: '11,065.02 sUSDS', + tokenUsdValue: '$11,255.99', + }, + ], + outcome: '11,065.02 sUSDS', + outcomeUsd: '$11,255.99', + }) + }) + + test('executes transaction', async ({ page }) => { + const testContext = await setup(page, { + blockchain: { + chainId: mainnet.id, + blockNumber: DEFAULT_BLOCK_NUMBER, + }, + initialPage: 'savings', + account: { + type: 'connected-random', + assetBalances: { sDAI: 10_000, sUSDS: 10_000 }, + }, + }) + + const savingsPage = new SavingsPageObject(testContext) + await savingsPage.clickUpgradeSDaiButtonAction() + + const upgradeDialog = new UpgradeDialogPageObject(testContext) + await upgradeDialog.actionsContainer.acceptAllActionsAction(2) + await upgradeDialog.expectUpgradeSuccessPage({ token: 'sDAI', amount: '10,000.00', usdValue: '$11,255.99' }) + await upgradeDialog.clickBackToSavingsButton() + + await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '21,065.02 sUSDS', estimatedUsdsValue: '21,428.579836' }) + }) +})