Skip to content

Commit

Permalink
Rewrite easy borrow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarvu committed Dec 18, 2024
1 parent d46cc1b commit 0d41bb2
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import { Page, expect } from '@playwright/test'

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

import { expect } from '@playwright/test'
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')
constructor(testContext: TestContext<any>) {
super({ testContext, header: /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)
await this.actionsContainer.acceptAllActionsAction(1)

// assertion used for waiting
if (setting === 'enabled') {
Expand Down
32 changes: 12 additions & 20 deletions packages/app/src/pages/Borrow.PageObject.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { 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 { buildUrl } from '@/test/e2e/setup'
import { TestContext, buildUrl } from '@/test/e2e/setup'
import { calculateAssetsWorth } from '@/test/e2e/utils'
import { testIds } from '@/ui/utils/testIds'
import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets'
import { expect } from '@playwright/test'

export class BorrowPageObject extends BasePageObject {
public readonly actionsContainer: ActionsPageObject

constructor(testContext: TestContext<any>) {
super(testContext)
this.actionsContainer = new ActionsPageObject(testContext, this.locatePanelByHeader('Actions'))
}

// #region actions
async fillDepositAssetAction(index: number, asset: string, amount: number): Promise<void> {
const inputGroup = this.page
Expand Down Expand Up @@ -54,38 +60,24 @@ export class BorrowPageObject extends BasePageObject {
async depositAssetsActions({
assetsToDeposit,
daiToBorrow,
updateBrowserAndNextBlockTime,
}: {
assetsToDeposit: Record<string, number>
daiToBorrow: number
updateBrowserAndNextBlockTime: () => Promise<void>
}): Promise<void> {
const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
await this.depositWithoutBorrowActions({
assetsToDeposit,
daiToBorrow,
actionsContainer,
updateBrowserAndNextBlockTime,
})
await actionsContainer.acceptActionAtIndex(
Object.entries(assetsToDeposit).length * 2,
updateBrowserAndNextBlockTime,
) // accept final borrow action
await this.actionsContainer.acceptActionAtIndex(Object.entries(assetsToDeposit).length * 2) // accept final borrow action
}

async depositWithoutBorrowActions({
assetsToDeposit,
daiToBorrow,
actionsContainer: _actionsContainer,
updateBrowserAndNextBlockTime,
}: {
assetsToDeposit: Record<string, number>
daiToBorrow?: number
actionsContainer?: ActionsPageObject
updateBrowserAndNextBlockTime: () => Promise<void>
}): Promise<void> {
const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions'))

let index = 0
for (const [asset, amount] of Object.entries(assetsToDeposit)) {
if (index !== 0) {
Expand All @@ -96,8 +88,8 @@ export class BorrowPageObject extends BasePageObject {
}
await this.fillBorrowAssetAction(daiToBorrow ?? 1) // defaulted value won't matter, if only depositing
await this.submitAction()
await actionsContainer.acceptAllActionsAction(2 * index, updateBrowserAndNextBlockTime) // omitting the borrow action
await actionsContainer.expectEnabledActionAtIndex(2 * index)
await this.actionsContainer.acceptAllActionsAction(2 * index) // omitting the borrow action
await this.actionsContainer.expectEnabledActionAtIndex(2 * index)
}

async goToEasyBorrowAction(): Promise<void> {
Expand Down
Loading

0 comments on commit 0d41bb2

Please sign in to comment.