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

Rewrite migrate E2E tests #515

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<any>) {
super({
testContext,
header: /Downgrade/,
})
}

// // #region actions
// async clickBackToSavingsButton(): Promise<void> {
// await this.page.getByRole('button', { name: 'Back to Savings' }).click()
// await this.region.waitFor({
// state: 'detached',
// })
// }
// // #endregion actions
// #region actions
async clickBackToSavingsButton(): Promise<void> {
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<void> {
// 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<void> {
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<void> {
// 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<void> {
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
}
Original file line number Diff line number Diff line change
@@ -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')
})
})
Loading
Loading