Skip to content

Commit

Permalink
Merge pull request #713 from OasisDEX/earn-protocol-tests-jan-20-3
Browse files Browse the repository at this point in the history
Earn protocol - Tests
  • Loading branch information
juan-langa authored Jan 20, 2025
2 parents 3b7d31b + 85df4ac commit 1f47c34
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 2 deletions.
79 changes: 79 additions & 0 deletions srcEarnProtocol/pages/portfolio/rewards/claimAndDelegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { expect } from '#earnProtocolFixtures';
import { step } from '#noWalletFixtures';
import { Page } from '@playwright/test';

export class ClaimAndDelegate {
readonly page: Page;

constructor(page: Page) {
this.page = page;
}

@step
async shouldBeVisible() {
await expect(
this.page.getByText('Claim & Delegate'),
'"Claim & Delegate" header should be visible'
).toBeVisible();
}

@step
async shouldHaveButton(
button: 'Reject' | 'Accept & Sign' | 'Loading' | 'Continue',
args?: { hidden: boolean }
) {
if (args?.hidden) {
await expect(this.page.locator(`button:has-text("${button}")`)).not.toBeVisible();
} else {
await expect(this.page.locator(`button:has-text("${button}")`)).toBeVisible();
}
}

@step
async reject() {
await this.page.locator('button:has-text("Reject terms")').click();
}

@step
async acceptAndSign() {
await this.page.locator('button:has-text("Accept & Sign")').click();
}

@step
async continue() {
await this.page.locator('button:has-text("Continue")').click();
}

@step
async shouldHaveEarnedRewards({ sumr, usd }: { sumr: string; usd: string }) {
const sumrRegExp = new RegExp(sumr);
const usdRegExp = new RegExp(`\\$.*${usd}`);
const haveEarnedLocator = this.page.locator('p:has-text("You have earned")');

await expect(haveEarnedLocator.locator('xpath=//following-sibling::div[1]')).toContainText(
sumrRegExp
);
await expect(haveEarnedLocator.locator('xpath=//following-sibling::p[1]')).toContainText(
usdRegExp
);
}

@step
async claim() {
await this.page.locator('button:has-text("Claim")').click();
}

@step
async shouldHaveClaimedRewards({ sumr, usd }: { sumr: string; usd: string }) {
const sumrRegExp = new RegExp(sumr);
const usdRegExp = new RegExp(`\\$.*${usd}`);
const haveEarnedLocator = this.page.locator('p:has-text("You have claimed")');

await expect(haveEarnedLocator.locator('xpath=//following-sibling::div[1]')).toContainText(
sumrRegExp
);
await expect(haveEarnedLocator.locator('xpath=//following-sibling::p[1]')).toContainText(
usdRegExp
);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { expect, step } from '#earnProtocolFixtures';
import { Page } from '@playwright/test';
import { ClaimAndDelegate } from './claimAndDelegate';
import { expect, step } from '#earnProtocolFixtures';
import { expectDefaultTimeout } from 'utils/config';

export class Rewards {
readonly page: Page;

readonly claimAndDelegate: ClaimAndDelegate;

constructor(page: Page) {
this.page = page;
this.claimAndDelegate = new ClaimAndDelegate(page);
}

@step
Expand All @@ -21,4 +25,9 @@ export class Rewards {
'"$SUMR available to claim" should be visible'
).toBeVisible();
}

@step
async claim() {
await this.page.getByRole('button', { name: 'Claim' }).click();
}
}
52 changes: 52 additions & 0 deletions testsEarnProtocol/withRealWallet/portfolio/sumrRewards.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { testWithSynpress } from '@synthetixio/synpress';
import { test as withRealWalletBaseFixtures } from '../../../srcEarnProtocol/fixtures/withRealWalletBase';
import { logInWithWalletAddress } from 'srcEarnProtocol/utils/logIn';

const test = testWithSynpress(withRealWalletBaseFixtures);

test.describe('Realwallet - Portfolio - SUMR rewards', async () => {
test.beforeEach(async ({ app, metamask }, testInfo) => {
// Extending tests timeout by 25 extra seconds due to beforeEach actions
testInfo.setTimeout(testInfo.timeout + 25_000);

await logInWithWalletAddress({
metamask,
app,
wallet: 'MetaMask',
});

await app.portfolio.open('0x10649c79428d718621821Cf6299e91920284743F?tab=rewards');
});

test('It should claim rewards and reject terms', async ({ app }) => {
await app.portfolio.rewards.claim();

await app.portfolio.rewards.claimAndDelegate.shouldBeVisible();

await app.portfolio.rewards.claimAndDelegate.reject();
await app.portfolio.rewards.shouldBeVisible();
});

test('It should claim rewards (until tx))', async ({ app, metamask }) => {
await app.portfolio.rewards.claim();

await app.portfolio.rewards.claimAndDelegate.shouldBeVisible();

await app.portfolio.rewards.claimAndDelegate.acceptAndSign();
await metamask.confirmSignature();

await app.portfolio.rewards.claimAndDelegate.continue();
await app.portfolio.rewards.claimAndDelegate.shouldHaveEarnedRewards({
sumr: '[0-9].[0-9]',
usd: '[0-9].[0-9]',
});

await app.portfolio.rewards.claimAndDelegate.claim();
await app.portfolio.rewards.claimAndDelegate.continue();

await app.portfolio.rewards.claimAndDelegate.shouldHaveClaimedRewards({
sumr: '[0-9].[0-9]',
usd: '[0-9].[0-9]',
});
});
});
1 change: 0 additions & 1 deletion testsEarnProtocol/withRealWallet/sumrPage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { testWithSynpress } from '@synthetixio/synpress';
import { test as withRealWalletBaseFixtures } from '../../srcEarnProtocol/fixtures/withRealWalletBase';
import { logInWithWalletAddress } from 'srcEarnProtocol/utils/logIn';
import { expectDefaultTimeout } from 'utils/config';

const test = testWithSynpress(withRealWalletBaseFixtures);

Expand Down

0 comments on commit 1f47c34

Please sign in to comment.