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 claim rewards dialog tests #508

Merged
merged 1 commit into from
Dec 19, 2024
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,41 +1,39 @@
// import { Locator, Page, expect } from '@playwright/test'
import { TestContext } from '@/test/e2e/setup'
import { testIds } from '@/ui/utils/testIds'
import { Locator, expect } from '@playwright/test'
import { DialogPageObject } from '../common/Dialog.PageObject'

// import { testIds } from '@/ui/utils/testIds'
export class ClaimRewardsDialogPageObject extends DialogPageObject {
constructor(testContext: TestContext<any>) {
super({ testContext, header: /Claim rewards/ })
}

// import { DialogPageObject } from '../common/Dialog.PageObject'
// #region assertions
async expectRewards(rows: Reward[], locator?: Locator): Promise<void> {
if (!locator) {
locator = this.region
}

// export class ClaimRewardsDialogPageObject extends DialogPageObject {
// constructor(page: Page) {
// super(page, /.*/)
// this.region = this.locateDialogByHeader('Claim rewards')
// }
for (const [index, row] of rows.entries()) {
const rowLocator = this.page.getByTestId(testIds.dialog.claimRewards.transactionOverview.row(index)).first()
await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amount)).toHaveText(
`${row.amount} ${row.tokenSymbol}`,
)
await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amountUSD)).toHaveText(
row.amountUSD,
)
}
}

// // #region assertions
// async expectRewards(rows: Reward[], locator?: Locator): Promise<void> {
// if (!locator) {
// locator = this.region
// }
async expectClaimRewardsSuccessPage(rows: Reward[]): Promise<void> {
await expect(this.page.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible()
await this.expectRewards(rows, this.page.getByTestId(testIds.dialog.success))
}
// #endregion assertions
}

// for (const [index, row] of rows.entries()) {
// const rowLocator = this.page.getByTestId(testIds.dialog.claimRewards.transactionOverview.row(index)).first()
// await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amount)).toHaveText(
// `${row.amount} ${row.tokenSymbol}`,
// )
// await expect(rowLocator.getByTestId(testIds.dialog.claimRewards.transactionOverview.amountUSD)).toHaveText(
// row.amountUSD,
// )
// }
// }

// async expectClaimRewardsSuccessPage(rows: Reward[]): Promise<void> {
// await expect(this.page.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible()
// await this.expectRewards(rows, this.page.getByTestId(testIds.dialog.success))
// }
// // #endregion assertions
// }

// interface Reward {
// tokenSymbol: string
// amount: string
// amountUSD: string
// }
interface Reward {
tokenSymbol: string
amount: string
amountUSD: string
}
Original file line number Diff line number Diff line change
@@ -1,75 +1,72 @@
// import { test } from '@playwright/test'
// import { mainnet } from 'viem/chains'
import { TopbarPageObject } from '@/features/topbar/Topbar.PageObject'
import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject'
import { DEFAULT_BLOCK_NUMBER } from '@/test/e2e/constants'
import { TestContext, setup } from '@/test/e2e/setup'
import { test } from '@playwright/test'
import { mainnet } from 'viem/chains'
import { ClaimRewardsDialogPageObject } from './ClaimRewardsDialog.PageObject'

// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject'
// import { TopbarPageObject } from '@/features/topbar/Topbar.PageObject'
// import { MyPortfolioPageObject } from '@/pages/MyPortfolio.PageObject'
// import { setupFork } from '@/test/e2e/forking/setupFork'
// import { setup } from '@/test/e2e/setup'
// import { ClaimRewardsDialogPageObject } from './ClaimRewardsDialog.PageObject'
test.describe('Claim rewards dialog', () => {
let navbar: TopbarPageObject
let claimRewardsDialog: ClaimRewardsDialogPageObject
let testContext: TestContext<'connected-address'>

// test.describe('Claim rewards dialog', () => {
// const fork = setupFork({
// blockNumber: 20189272n, // block number where the reward program is finished
// chainId: mainnet.id,
// })
// let navbar: TopbarPageObject
// let claimRewardsDialog: ClaimRewardsDialogPageObject
// let actionsContainer: ActionsPageObject
test.beforeEach(async ({ page }) => {
testContext = await setup(page, {
blockchain: {
blockNumber: DEFAULT_BLOCK_NUMBER,
chainId: mainnet.id,
},
initialPage: 'easyBorrow',
account: {
type: 'connected-address',
address: '0xf8de75c7b95edb6f1e639751318f117663021cf0',
},
})

// test.beforeEach(async ({ page }) => {
// await setup(page, fork, {
// initialPage: 'easyBorrow',
// account: {
// type: 'connected-address',
// address: '0xf8de75c7b95edb6f1e639751318f117663021cf0',
// },
// })
navbar = new TopbarPageObject(testContext)
await navbar.openClaimRewardsDialog()

// navbar = new TopbarPageObject(page)
// await navbar.openClaimRewardsDialog()
claimRewardsDialog = new ClaimRewardsDialogPageObject(testContext)
})

// claimRewardsDialog = new ClaimRewardsDialogPageObject(page)
// actionsContainer = new ActionsPageObject(claimRewardsDialog.locatePanelByHeader('Actions'))
// })
test('displays correct transaction overview', async () => {
await claimRewardsDialog.expectRewards([
{
tokenSymbol: 'wstETH',
amount: '6.3697',
amountUSD: '$29,717.60',
},
])
})

// test('displays correct transaction overview', async () => {
// await claimRewardsDialog.expectRewards([
// {
// tokenSymbol: 'wstETH',
// amount: '6.3697',
// amountUSD: '$25,583.20',
// },
// ])
// })
test('has correct action plan', async () => {
await claimRewardsDialog.actionsContainer.expectActions([
{
type: 'claimMarketRewards',
asset: 'wstETH',
},
])
})

// test('has correct action plan', async () => {
// await actionsContainer.expectActions([
// {
// type: 'claimMarketRewards',
// asset: 'wstETH',
// },
// ])
// })
test('executes transaction', async () => {
await claimRewardsDialog.actionsContainer.acceptAllActionsAction(1)

// test('executes transaction', async ({ page }) => {
// await actionsContainer.acceptAllActionsAction(1)
await claimRewardsDialog.expectClaimRewardsSuccessPage([
{
tokenSymbol: 'wstETH',
amount: '6.3697',
amountUSD: '$29,717.60',
},
])

// await claimRewardsDialog.expectClaimRewardsSuccessPage([
// {
// tokenSymbol: 'wstETH',
// amount: '6.3697',
// amountUSD: '$25,583.20',
// },
// ])
const myPortfolioPage = new MyPortfolioPageObject(testContext)
await myPortfolioPage.goToMyPortfolioAction()

// const myPortfolioPage = new MyPortfolioPageObject(page)
// await myPortfolioPage.goToMyPortfolioAction()
await myPortfolioPage.expectBalancesInDepositTable({
wstETH: 6.3697,
})

// await myPortfolioPage.expectBalancesInDepositTable({
// wstETH: 6.3697,
// })

// await navbar.expectRewardsBadgeNotVisible()
// })
// })
await navbar.expectRewardsBadgeNotVisible()
})
})
Loading