diff --git a/srcEarnProtocol/pages/positionPage/index.ts b/srcEarnProtocol/pages/positionPage/index.ts index d2692a8b..57289cfb 100644 --- a/srcEarnProtocol/pages/positionPage/index.ts +++ b/srcEarnProtocol/pages/positionPage/index.ts @@ -1,13 +1,17 @@ import { Page } from '@playwright/test'; +import { VaultExposure } from './vaultExposure'; import { VaultSidebar } from '../vaultSidebar'; export class PositionPage { readonly page: Page; + readonly exposure: VaultExposure; + readonly sideBar: VaultSidebar; constructor(page: Page) { this.page = page; + this.exposure = new VaultExposure(page); this.sideBar = new VaultSidebar(page, this.page.locator('[class*="_sidebarWrapper_"]')); } } diff --git a/srcEarnProtocol/pages/positionPage/vaultExposure.ts b/srcEarnProtocol/pages/positionPage/vaultExposure.ts new file mode 100644 index 00000000..841f2bb6 --- /dev/null +++ b/srcEarnProtocol/pages/positionPage/vaultExposure.ts @@ -0,0 +1,43 @@ +import { expect, step } from '#noWalletFixtures'; +import { Locator, Page } from '@playwright/test'; + +export class VaultExposure { + readonly page: Page; + + readonly vaultExposureLocator: Locator; + + constructor(page: Page) { + this.page = page; + this.vaultExposureLocator = page.locator('button:has-text("Vault exposure")').locator('..'); + } + + @step + async viewMore() { + await this.vaultExposureLocator.getByText('View more').click(); + expect(this.vaultExposureLocator.getByText('View less')).toBeVisible(); + } + + @step + async viewLess() { + await this.vaultExposureLocator.getByText('View less').click(); + expect(this.vaultExposureLocator.getByText('View more')).toBeVisible(); + } + + @step + async getStrategiesTotalAllocation() { + const strategyAllocationLocator = this.vaultExposureLocator.locator('tr > td:nth-child(2)'); + // Wait for table to load + await expect(strategyAllocationLocator.first()).toBeVisible(); + + const viewMoreIsVisible = await this.vaultExposureLocator.getByText('View more').isVisible(); + if (viewMoreIsVisible) await this.viewMore(); + + const allocations = (await strategyAllocationLocator.allInnerTexts()).map((text) => + parseFloat(text.replace('%', '')) + ); + + const totalAllocation = allocations.reduce((a, b) => a + b, 0); + + return totalAllocation; + } +} diff --git a/srcEarnProtocol/pages/vaultSidebar/index.ts b/srcEarnProtocol/pages/vaultSidebar/index.ts index 7f57b89e..393af0cc 100644 --- a/srcEarnProtocol/pages/vaultSidebar/index.ts +++ b/srcEarnProtocol/pages/vaultSidebar/index.ts @@ -13,6 +13,22 @@ export class VaultSidebar { this.sideBarLocator = sideBarLocator; } + @step + async openBalanceTokens() { + await expect(async () => { + await this.sideBarLocator.locator('[class*="_dropdownSelected_"]').click(); + await expect( + this.sideBarLocator.locator('[class*="_dropdownOptions_"]'), + 'Tokens drop-downshould be visible' + ).toBeVisible(); + }).toPass(); + } + + @step + async selectBalanceToken(token: EarnTokens) { + await this.sideBarLocator.locator(`[class*="_dropdownOption_"]:has-text("${token}")`).click(); + } + @step async shouldHaveBalance({ balance, @@ -21,11 +37,20 @@ export class VaultSidebar { }: { balance: string; token: EarnTokens; - timeout: number; + timeout?: number; }) { const regExp = new RegExp(`${balance}.*${token}`); await expect(this.sideBarLocator.getByText('Balance').locator('..')).toContainText(regExp, { timeout: timeout ?? expectDefaultTimeout, }); } + + @step + async changeNetwork(options?: { delay: number }) { + await expect(this.sideBarLocator.getByRole('button', { name: 'Change network' })).toBeVisible(); + if (options?.delay) { + await this.page.waitForTimeout(options.delay); + } + await this.sideBarLocator.getByRole('button', { name: 'Change network' }).click(); + } } diff --git a/srcEarnProtocol/utils/logIn.ts b/srcEarnProtocol/utils/logIn.ts index ac36161a..31edef3d 100644 --- a/srcEarnProtocol/utils/logIn.ts +++ b/srcEarnProtocol/utils/logIn.ts @@ -7,16 +7,29 @@ export const logInWithWalletAddress = async ({ metamask, app, wallet, + network, // This property should be removed in the future }: { metamask: MetaMask; app: App; wallet: walletTypes; + network?: 'Arbitrum'; }) => { await app.header.logIn(); await app.modals.logIn.withWallet(); await app.modals.logIn.selectWallet(wallet); await metamask.connectToDapp(); + // TO BE REMOVED in the future + if (network) { + // Earn protocol app switches to Base by default + await metamask.approveNewNetwork(); + await metamask.approveSwitchNetwork(); + + // SKIPPED - Weird issue with Arbitrumwhen switching network in main page (/) + // // Switch back to Arbitrum + // await metamask.switchNetwork('arbitrum'); + } + // App doesn't reload when loging in at the moment await app.header.shouldHaveWalletAddress('0x1064...4743F'); await app.page.reload(); diff --git a/tests/withWallet/ajna/arbitrum/ajnaArbitrumEarn.spec.ts b/tests/withWallet/ajna/arbitrum/ajnaArbitrumEarn.spec.ts index a323025b..c6241bb1 100644 --- a/tests/withWallet/ajna/arbitrum/ajnaArbitrumEarn.spec.ts +++ b/tests/withWallet/ajna/arbitrum/ajnaArbitrumEarn.spec.ts @@ -35,7 +35,7 @@ test.describe('Ajna Arbitrum Earn - Wallet connected', async () => { await tenderly.deleteFork(forkId); }); - test('It should open an Ajna Arbitrum Earn position @regression', async ({ metamask, page }) => { + test('It should open an Ajna Arbitrum Earn position @regression', async ({ metamask }) => { test.setTimeout(extremelyLongTestTimeout); await app.position.openPage('/arbitrum/ajna/earn/USDC-WBTC#setup'); diff --git a/testsEarnProtocol/noWallet/positionPageArbitrum.spec.ts b/testsEarnProtocol/noWallet/positionPageArbitrum.spec.ts new file mode 100644 index 00000000..e930e94d --- /dev/null +++ b/testsEarnProtocol/noWallet/positionPageArbitrum.spec.ts @@ -0,0 +1,14 @@ +import { expect, test } from '#earnProtocolFixtures'; + +test.describe(`Earn page`, async () => { + test.beforeEach(async ({ app }) => { + await app.page.goto('/earn/arbitrum/position/earn-mcyieldface-usdc'); + }); + + test('It should show strategies exposure and be 100% in total', async ({ app }) => { + const totalAllocation = await app.positionPage.exposure.getStrategiesTotalAllocation(); + + expect(totalAllocation).toBeCloseTo(100); + expect(totalAllocation).toBeLessThanOrEqual(100); + }); +}); diff --git a/testsEarnProtocol/noWallet/positionPageBase.spec.ts b/testsEarnProtocol/noWallet/positionPageBase.spec.ts new file mode 100644 index 00000000..1df719b4 --- /dev/null +++ b/testsEarnProtocol/noWallet/positionPageBase.spec.ts @@ -0,0 +1,14 @@ +import { expect, test } from '#earnProtocolFixtures'; + +test.describe(`Earn page`, async () => { + test.beforeEach(async ({ app }) => { + await app.page.goto('/earn/base/position/usdc-ya-later'); + }); + + test('It should show strategies exposure and be 100% in total', async ({ app }) => { + const totalAllocation = await app.positionPage.exposure.getStrategiesTotalAllocation(); + + expect(totalAllocation).toBeCloseTo(100); + expect(totalAllocation).toBeLessThanOrEqual(100); + }); +}); diff --git a/testsEarnProtocol/withRealWallet/arbitrum/positionPage.spec.ts b/testsEarnProtocol/withRealWallet/arbitrum/positionPage.spec.ts new file mode 100644 index 00000000..89113198 --- /dev/null +++ b/testsEarnProtocol/withRealWallet/arbitrum/positionPage.spec.ts @@ -0,0 +1,51 @@ +import { testWithSynpress } from '@synthetixio/synpress'; +import { test as withWalletArbitrumFixtures } from '../../../srcEarnProtocol/fixtures/withTestWalletArbitrum'; +import { logInWithWalletAddress } from 'srcEarnProtocol/utils/logIn'; +import { expectDefaultTimeout, longTestTimeout } from 'utils/config'; + +const test = testWithSynpress(withWalletArbitrumFixtures); + +const { expect } = test; + +test.describe('With reaal wallet - Arbitrum', async () => { + test.beforeEach(async ({ app, metamask }) => { + await logInWithWalletAddress({ + metamask, + app, + wallet: 'MetaMask', + network: 'Arbitrum', + }); + }); + + test('It should show USDC balance in Arbitrum USDC position', async ({ app, metamask }) => { + await app.page.goto('/earn/arbitrum/position/earn-mcyieldface-usdc'); + + /* + Changing network in position page to avoid weird issue with Arbitrum + when switching network in main page (/) and the visiting position page + */ + await app.positionPage.sideBar.changeNetwork({ delay: 500 }); + await metamask.approveSwitchNetwork(); + await app.page.reload(); + + await app.positionPage.sideBar.shouldHaveBalance({ + balance: '1.00', + token: 'USDC', + timeout: expectDefaultTimeout * 2, + }); + }); + + // TODO - Add one or more tokens once it'sworking + // test.skip('It should show ??? balance in Arbitrum USDC position', async ({ app }) => { + // await app.page.goto('/earn/arbitrum/position/earn-mcyieldface-usdc'); + + // await app.positionPage.sideBar.openBalanceTokens(); + // await app.positionPage.sideBar.selectBalanceToken('USDBC'); + + // await app.positionPage.sideBar.shouldHaveBalance({ + // balance: '1.05', + // token: 'USDBC', + // timeout: expectDefaultTimeout * 2, + // }); + // }); +}); diff --git a/testsEarnProtocol/withRealWallet/arbitrum/withRealWalletSampleTest.spec.ts b/testsEarnProtocol/withRealWallet/arbitrum/withRealWalletSampleTest.spec.ts deleted file mode 100644 index 5388ee95..00000000 --- a/testsEarnProtocol/withRealWallet/arbitrum/withRealWalletSampleTest.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { testWithSynpress } from '@synthetixio/synpress'; -import { test as withWalletArbitrumFixtures } from '../../../../srcEarnProtocol/fixtures/withTestWalletArbitrum'; - -const test = testWithSynpress(withWalletArbitrumFixtures); - -const { expect } = test; - -test.describe('With reaal wallet - Arbitrum', async () => { - test('It should show USDC balance in Arbitrum USDC position', async ({ app }) => { - await app.page.goto('/earn/arbitrum/position/usdc-ya-later'); - - // - await app.pause(); - // - - // TODO - }); -}); diff --git a/testsEarnProtocol/withRealWallet/base/positionPage.spec.ts b/testsEarnProtocol/withRealWallet/base/positionPage.spec.ts index 7ea8dcc5..48bc8c89 100644 --- a/testsEarnProtocol/withRealWallet/base/positionPage.spec.ts +++ b/testsEarnProtocol/withRealWallet/base/positionPage.spec.ts @@ -1,5 +1,5 @@ import { testWithSynpress } from '@synthetixio/synpress'; -import { test as withRealWalletBaseFixtures } from '../../../../srcEarnProtocol/fixtures/withRealWalletBase'; +import { test as withRealWalletBaseFixtures } from '../../../srcEarnProtocol/fixtures/withRealWalletBase'; import { logInWithWalletAddress } from 'srcEarnProtocol/utils/logIn'; import { expectDefaultTimeout } from 'utils/config'; @@ -25,4 +25,17 @@ test.describe('With reaal wallet - Base', async () => { timeout: expectDefaultTimeout * 2, }); }); + + test('It should show USDBC balance in Base USDC position', async ({ app }) => { + await app.page.goto('/earn/base/position/usdc-ya-later'); + + await app.positionPage.sideBar.openBalanceTokens(); + await app.positionPage.sideBar.selectBalanceToken('USDBC'); + + await app.positionPage.sideBar.shouldHaveBalance({ + balance: '1.05', + token: 'USDBC', + timeout: expectDefaultTimeout * 2, + }); + }); });