Skip to content

Commit

Permalink
Introduce test context
Browse files Browse the repository at this point in the history
Co-authored-by: Oskar <[email protected]>
  • Loading branch information
yivlad and oskarvu committed Dec 17, 2024
1 parent 975192f commit a287b2c
Show file tree
Hide file tree
Showing 17 changed files with 945 additions and 937 deletions.
26 changes: 9 additions & 17 deletions packages/app/src/features/actions/ActionsContainer.PageObject.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { Locator, Page, expect } from '@playwright/test'
import { Locator, expect } from '@playwright/test'

import { formatPercentage } from '@/domain/common/format'
import { BasePageObject } from '@/test/e2e/BasePageObject'
import { isPage } from '@/test/e2e/utils'
import { TestContext } from '@/test/e2e/setup'
import { testIds } from '@/ui/utils/testIds'
import { Percentage } from '@marsfoundation/common-universal'
import { ActionType } from './logic/types'

export class ActionsPageObject extends BasePageObject {
constructor(pageOrLocator: Page | Locator) {
if (isPage(pageOrLocator)) {
super(pageOrLocator)
constructor(testContext: TestContext<any>, locator?: Locator) {
super(testContext, locator)
if (!locator) {
this.region = this.locatePanelByHeader('Actions')
} else {
super(pageOrLocator)
}
}

Expand All @@ -26,29 +24,23 @@ export class ActionsPageObject extends BasePageObject {
}

// #region actions
async acceptAllActionsAction(
expectedNumberOfActions: number,
updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>,
): Promise<void> {
async acceptAllActionsAction(expectedNumberOfActions: number): Promise<void> {
for (let index = 0; index < expectedNumberOfActions; index++) {
const row = this.region.getByTestId(testIds.actions.row(index))

await row.getByRole('button', { name: actionButtonRegex }).click()
await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible()
// @note: we are setting block timestamp of the next tx (especially after executing all txs)
await updateBrowserAndNextBlockTime(5)
await this.testContext.testnetController.progressSimulation(5)
}
}

async acceptActionAtIndex(
index: number,
updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>,
): Promise<void> {
async acceptActionAtIndex(index: number): Promise<void> {
const row = this.region.getByTestId(testIds.actions.row(index))
await row.getByRole('button', { name: actionButtonRegex }).click()
await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible()
// @note: we are setting block timestamp of the next tx (especially after executing all txs)
await updateBrowserAndNextBlockTime(5)
await this.testContext.testnetController.progressSimulation(5)
}

async switchPreferPermitsAction(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { Locator, Page, expect } from '@playwright/test'
// import { Locator, Page, expect } from '@playwright/test'

import { testIds } from '@/ui/utils/testIds'
// import { testIds } from '@/ui/utils/testIds'

import { DialogPageObject } from '../common/Dialog.PageObject'
// import { DialogPageObject } from '../common/Dialog.PageObject'

export class ClaimRewardsDialogPageObject extends DialogPageObject {
constructor(page: Page) {
super(page, /.*/)
this.region = this.locateDialogByHeader('Claim rewards')
}
// export class ClaimRewardsDialogPageObject extends DialogPageObject {
// constructor(page: Page) {
// super(page, /.*/)
// this.region = this.locateDialogByHeader('Claim rewards')
// }

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

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,
)
}
}
// 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
}
// 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,44 +1,44 @@
import { Page, expect } from '@playwright/test'
// import { Page, expect } from '@playwright/test'

import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject'
import { testIds } from '@/ui/utils/testIds'
// import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject'
// import { testIds } from '@/ui/utils/testIds'

import { CollateralSetting } from '../collateral/types'
import { DialogPageObject } from '../common/Dialog.PageObject'
// import { CollateralSetting } from '../collateral/types'
// import { DialogPageObject } from '../common/Dialog.PageObject'

export class CollateralDialogPageObject extends DialogPageObject {
constructor(page: Page) {
super(page, /.*/)
this.region = this.locateDialogByHeader('Collateral')
}
// export class CollateralDialogPageObject extends DialogPageObject {
// constructor(page: Page) {
// super(page, /.*/)
// this.region = this.locateDialogByHeader('Collateral')
// }

// #region actions
async setUseAsCollateralAction({
assetName,
setting,
updateBrowserAndNextBlockTime,
}: {
assetName: string
setting: CollateralSetting
updateBrowserAndNextBlockTime: () => Promise<void>
}): Promise<void> {
const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime)
// // #region actions
// async setUseAsCollateralAction({
// assetName,
// setting,
// updateBrowserAndNextBlockTime,
// }: {
// assetName: string
// setting: CollateralSetting
// updateBrowserAndNextBlockTime: () => Promise<void>
// }): Promise<void> {
// const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
// await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime)

// assertion used for waiting
if (setting === 'enabled') {
await this.expectSetUseAsCollateralSuccessPage(assetName, 'enabled')
} else {
await this.expectSetUseAsCollateralSuccessPage(assetName, 'disabled')
}
}
// #endregion actions
// // assertion used for waiting
// if (setting === 'enabled') {
// await this.expectSetUseAsCollateralSuccessPage(assetName, 'enabled')
// } else {
// await this.expectSetUseAsCollateralSuccessPage(assetName, 'disabled')
// }
// }
// // #endregion actions

// #region assertions
async expectSetUseAsCollateralSuccessPage(assetName: string, setting: CollateralSetting): Promise<void> {
await expect(this.region.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible()
await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(assetName)
await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(`Collateral ${setting}`)
}
// #endregion assertions
}
// // #region assertions
// async expectSetUseAsCollateralSuccessPage(assetName: string, setting: CollateralSetting): Promise<void> {
// await expect(this.region.getByRole('heading', { name: 'Congrats, all done!' })).toBeVisible()
// await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(assetName)
// await expect(this.region.getByTestId(testIds.dialog.success)).toContainText(`Collateral ${setting}`)
// }
// // #endregion assertions
// }
22 changes: 12 additions & 10 deletions packages/app/src/features/dialogs/common/Dialog.PageObject.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { Locator, Page, expect } from '@playwright/test'
import { Locator, expect } from '@playwright/test'

import { ActionsPageObject } from '@/features/actions/ActionsContainer.PageObject'
import { BasePageObject } from '@/test/e2e/BasePageObject'
import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions'
import { calculateAssetsWorth, isPage } from '@/test/e2e/utils'
import { TestContext } from '@/test/e2e/setup'
import { calculateAssetsWorth } from '@/test/e2e/utils'
import { testIds } from '@/ui/utils/testIds'
import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets'

export interface DialogPageObjectParams {
testContext: TestContext<any>
header: RegExp
}

export class DialogPageObject extends BasePageObject {
public readonly actionsContainer: ActionsPageObject
constructor(pageOrLocator: Page | Locator, header: RegExp) {
if (isPage(pageOrLocator)) {
super(pageOrLocator)
this.region = this.locateDialogByHeader(header)
} else {
super(pageOrLocator)
}
this.actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
constructor({ testContext, header }: DialogPageObjectParams) {
super(testContext)
this.region = this.locateDialogByHeader(header)
this.actionsContainer = new ActionsPageObject(testContext, this.locatePanelByHeader('Actions'))
}

getDialog(): Locator {
Expand Down
Loading

0 comments on commit a287b2c

Please sign in to comment.