Skip to content

Commit

Permalink
Merge pull request #149 from OasisDEX/automations-setup
Browse files Browse the repository at this point in the history
Automations tests setup
  • Loading branch information
juan-langa authored Feb 1, 2024
2 parents ac00249 + c494120 commit e63cb61
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 3 deletions.
38 changes: 38 additions & 0 deletions src/pages/position/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,44 @@ export class Base {
}).toPass();
}

/**
* @param value should be between '0' and '1' both included | 0: far left | 1: far right
*/
@step
async moveSliderAutomations({ process, value }: { process?: 'setup' | 'manage'; value: number }) {
await expect(async () => {
const initialSliderValue = await this.page
.locator('input[type="range"]')
.nth(0)
.getAttribute('value');

const slider = this.page.locator('input[type="range"]').nth(0);
const sliderBoundingBox = await slider.boundingBox();

// Scroll down so that slider is fully visible and next dragTo doesn't fail
if (process) {
await this.page
.getByText(process === 'setup' ? 'Connect a wallet' : 'Adjust Risk')
.scrollIntoViewIfNeeded();
}

await slider.dragTo(slider, {
force: true,
targetPosition: {
x: sliderBoundingBox.width * value,
y: 0,
},
});

const newSliderValue = await this.page
.locator('input[type="range"]')
.nth(0)
.getAttribute('value');

expect(newSliderValue !== initialSliderValue).toBe(true);
}).toPass();
}

@step
async confirm() {
await this.page.getByRole('button', { name: 'Confirm' }).click();
Expand Down
13 changes: 11 additions & 2 deletions src/pages/position/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { expect, Page } from '@playwright/test';
import { positionTimeout } from 'utils/config';
import { step } from '#noWalletFixtures';
import { Manage } from './manage';
import { Optimization } from './optimization';
import { OrderInformation } from './orderInformation';
import { Overview } from './overview';
import { Setup } from './setup';
import { positionTimeout } from 'utils/config';
import { step } from '#noWalletFixtures';

export class Position {
readonly page: Page;

readonly manage: Manage;

readonly optimization: Optimization;

readonly orderInformation: OrderInformation;

readonly overview: Overview;
Expand All @@ -20,6 +23,7 @@ export class Position {
constructor(page: Page) {
this.page = page;
this.manage = new Manage(page);
this.optimization = new Optimization(page);
this.orderInformation = new OrderInformation(page);
this.overview = new Overview(page);
this.setup = new Setup(page);
Expand All @@ -38,4 +42,9 @@ export class Position {
timeout: positionTimeout,
});
}

@step
async openTab(tab: string) {
await this.page.getByRole('button', { name: tab }).click();
}
}
39 changes: 39 additions & 0 deletions src/pages/position/optimization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { step } from '#noWalletFixtures';
import { Page } from '@playwright/test';
import { Base } from './base';

export class Optimization {
readonly page: Page;

readonly base: Base;

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

@step
async setupAutoBuy() {
await this.page.getByRole('button', { name: 'Setup Auto-Buy' }).click();
}

@step
async adjustAutoBuyTrigger({ value }: { value: number }) {
await this.base.moveSliderAutomations({ value });
}

@step
async setNoThreshold() {
await this.page.getByText('span:has-text("Set No Threshold")').click();
}

@step
async setThreshold() {
await this.page.locator('span:has-text("Set Threshold")').click();
}

@step
async addAutoBuy() {
await this.page.getByRole('button', { name: 'Add Auto-Buy' }).click();
}
}
10 changes: 9 additions & 1 deletion src/pages/position/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ export class Setup {
await this.page.getByRole('button', { exact: true, name: 'Finished' }).click();
}

@step
async finishedShouldBeVisible() {
await expect(
this.page.getByRole('button', { exact: true, name: 'Finished' }),
'"Finished" should be visible'
).toBeVisible();
}

@step
async openBorrowPosition1Of2() {
await this.page.getByRole('button', { name: 'Open Borrow position (1/2)' }).click();
Expand All @@ -267,7 +275,7 @@ export class Setup {
async setupStopLossTransactionShouldBeVisible() {
await expect(
this.page.getByRole('button', { name: 'Set up Stop-Loss transaction' }),
'"Set up Stop-Loss transaction", should be visible'
'"Set up Stop-Loss transaction" should be visible'
).toBeVisible({ timeout: positionTimeout });
}

Expand Down
57 changes: 57 additions & 0 deletions tests/withWallet/aaveV3/base/aaveV3MultiplyBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,63 @@ test.describe('Aave v3 Multiply - Base - Wallet connected', async () => {
await app.position.manage.shouldBeVisible('Manage ');
});

test.skip('It should set Auto-Buy on an Aave v3 Multiply Base position @regression', async () => {
test.info().annotations.push({
type: 'Test case',
description: '12463',
});

test.setTimeout(extremelyLongTestTimeout);

// ==================================================
// ==================================================

await test.step('Test setup', async () => {
({ context } = await metamaskSetUp({ network: 'base' }));
let page = await context.newPage();
app = new App(page);

({ forkId, walletAddress } = await setup({ app, network: 'base' }));
});

await tenderly.changeAccountOwner({
account: '0xf5922d700883214f689efe190a978ac51c50e6b1',
newOwner: walletAddress,
forkId,
});

await app.page.goto('/base/aave/v3/17#overview');
// ==================================================
// ==================================================

await app.position.openTab('Optimization');
await app.position.optimization.setupAutoBuy();

//
await app.pause();
//
await app.position.optimization.adjustAutoBuyTrigger({ value: 0.05 });
//
// await app.pause();
//
await app.position.optimization.setNoThreshold();
//
await app.pause();
//
await app.position.optimization.addAutoBuy();

// await app.pause();

// Automation setup randomly fails - Retry until it's set.
await expect(async () => {
await app.position.setup.confirmOrRetry();
await test.step('Metamask: ConfirmPermissionToSpend', async () => {
await metamask.confirmPermissionToSpend();
});
await app.position.setup.finishedShouldBeVisible();
}).toPass({ timeout: longTestTimeout });
});

test.skip('It should list an opened Aave v3 Multiply Base position in portfolio', async () => {
test.info().annotations.push({
type: 'Test case',
Expand Down

0 comments on commit e63cb61

Please sign in to comment.