Skip to content

Commit

Permalink
Merge pull request #585 from OasisDEX/earn-protocol-24-oct
Browse files Browse the repository at this point in the history
Earn protocol - Adding more framework pages and tests
  • Loading branch information
juan-langa authored Oct 25, 2024
2 parents da769e1 + 6eb7150 commit 7f80f2b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 23 deletions.
20 changes: 14 additions & 6 deletions srcEarnProtocol/pages/landingPage/strategiesCarousel/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Page } from '@playwright/test';
import { ActiveSlide } from './activeSlide';
import { expect, step } from '#earnProtocolFixtures';
import { expectDefaultTimeout } from 'utils/config';

export class StrategiesCarousel {
readonly page: Page;
Expand All @@ -13,18 +14,25 @@ export class StrategiesCarousel {
}

@step
async moveToNextStrategy(direction: 'Right' | 'Left') {
await this.page.locator(`[class*="_button${direction}_"]`).click();
async moveToNextStrategy(direction: 'Right' | 'Left', args?: { timeout: number }) {
const arrowButtonLocator = this.page.locator(`[class*="_button${direction}_"]`);

// Wait for button to be fully visible
await expect(arrowButtonLocator.locator('img')).toBeVisible({
timeout: args?.timeout ?? expectDefaultTimeout,
});

// Click on button
await arrowButtonLocator.click();

// Button should be disabled after click
await expect(async () => {
expect(await this.page.locator(`[class*="_button${direction}_"]`).isDisabled()).toBeTruthy();
expect(await arrowButtonLocator.isDisabled()).toBeTruthy();
}).toPass();

// Button should be enabled back after a little while
await expect(async () => {
expect(
await this.page.locator(`[class*="_button${direction}_"]`).isDisabled()
).not.toBeTruthy();
expect(await arrowButtonLocator.isDisabled()).not.toBeTruthy();
}).toPass();
}
}
4 changes: 4 additions & 0 deletions srcEarnProtocol/pages/portfolio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Overview } from './overview';
import { Wallet } from './wallet';
import { RebalanceActivity } from './rebalanceActivity';
import { Rewards } from './rewards';
import { YouMightLike } from './youMightLike';

export class Portfolio {
readonly page: Page;
Expand All @@ -17,6 +18,8 @@ export class Portfolio {

readonly wallet: Wallet;

readonly youMightLike: YouMightLike;

readonly portfolioHeaderLocator: Locator;

constructor(page: Page) {
Expand All @@ -25,6 +28,7 @@ export class Portfolio {
this.rebalanceActivity = new RebalanceActivity(page);
this.rewards = new Rewards(page);
this.wallet = new Wallet(page);
this.youMightLike = new YouMightLike(page);
this.portfolioHeaderLocator = this.page.locator('[class*="PortfolioHeader_"]');
}

Expand Down
29 changes: 29 additions & 0 deletions srcEarnProtocol/pages/portfolio/youMightLike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Locator, Page } from '@playwright/test';
import { StrategyCard } from '../strategyCard';
import { step } from '#earnProtocolFixtures';

export class YouMightLike {
readonly page: Page;

readonly youMightLikeLocator: Locator;

constructor(page: Page) {
this.page = page;
this.youMightLikeLocator = page.locator('section:has-text("You might like")');
}

nthCard(nth: number) {
return new StrategyCard(
this.page,
this.youMightLikeLocator.locator('[class*="_strategyCard_"]').nth(nth)
);
}

@step
async move(direction: 'Left' | 'Right') {
await this.youMightLikeLocator
.getByRole('button')
.nth(direction === 'Left' ? 0 : 1)
.click();
}
}
9 changes: 9 additions & 0 deletions srcEarnProtocol/pages/strategyCard/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ export class Header {
const risk = await this.headerLocator.getByText(' risk').innerText();
return risk;
}

@step
async getDetails() {
const token = await this.getToken();
const network = await this.getToken();
const risk = await this.getRisk();

return { token, network, risk };
}
}
8 changes: 8 additions & 0 deletions srcEarnProtocol/pages/strategyCard/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Locator, Page } from '@playwright/test';
import { Header } from './header';
import { expect, step } from '#earnProtocolFixtures';
import { expectDefaultTimeout } from 'utils/config';

export class StrategyCard {
readonly page: Page;
Expand All @@ -10,6 +12,12 @@ export class StrategyCard {

constructor(page: Page, cardLocator: Locator) {
this.page = page;
this.cardLocator = cardLocator;
this.header = new Header(page, cardLocator);
}

@step
async shouldBeVisible(args?: { timeout: number }) {
await expect(this.cardLocator).toBeVisible({ timeout: args?.timeout ?? expectDefaultTimeout });
}
}
24 changes: 8 additions & 16 deletions tests/earnProtocol/landingPage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from '#earnProtocolFixtures';
import { expectDefaultTimeout } from 'utils/config';

test.describe('Landin page', async () => {
test('It should show strategy card', async ({ app }) => {
Expand All @@ -8,29 +9,20 @@ test.describe('Landin page', async () => {

(['Right', 'Left'] as const).forEach((direction) => {
test(`It should show strategy card to the ${direction}`, async ({ app }) => {
let originalStrategyCard = { token: '', network: '', risk: '' };
let newStrategyCard = { token: '', network: '', risk: '' };

await app.landingPage.open();

// Get strategy info for current active strategy in carousel
originalStrategyCard.token =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getToken();
originalStrategyCard.network =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getNetwork();
originalStrategyCard.risk =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getRisk();
const originalStrategyCard =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getDetails();

// Select strategy to the right
await app.landingPage.strategiesCarousel.moveToNextStrategy(direction);
await app.landingPage.strategiesCarousel.moveToNextStrategy(direction, {
timeout: expectDefaultTimeout * 2,
});

// Get strategy info for current active strategy in carousel
newStrategyCard.token =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getToken();
newStrategyCard.network =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getNetwork();
newStrategyCard.risk =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getRisk();
const newStrategyCard =
await app.landingPage.strategiesCarousel.activeSlide.strategyCard.header.getDetails();

// Logging strategies data for debugging purposes
console.log('originalStrategyCard: ', originalStrategyCard);
Expand Down
2 changes: 1 addition & 1 deletion tests/earnProtocol/portfolio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.describe('Portfolio', async () => {
});
});

test('It should show switch to all Portfolio tabs', async ({ app }) => {
test('It should show switch to all Portfolio main tabs', async ({ app }) => {
await app.portfolio.open('0xA1B008dBA9F6143c6211767cbA826296f95Fe3B3');

// Switch to 'Wallet' tab
Expand Down

0 comments on commit 7f80f2b

Please sign in to comment.