Skip to content

Commit

Permalink
Add undercut limit e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofilipenunes committed Jan 17, 2024
1 parent 265e937 commit 2e75458
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions e2e/tests/strategy/recurring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { createRecurringStrategy } from './create';
export { deleteStrategyTest } from './delete';
export { depositStrategyTest } from './deposit';
export { duplicateStrategyTest } from './duplicate';
export { undercutStrategyTest } from './undercut';
export { editPriceStrategyTest } from './edit';
export { pauseStrategyTest } from './pause';
export { renewStrategyTest } from './renew';
Expand Down
79 changes: 79 additions & 0 deletions e2e/tests/strategy/recurring/undercut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { expect, test } from '@playwright/test';
import { MyStrategyDriver } from './../../../utils/strategy';
import { fiatPrice, tokenPrice } from './../../../utils/operators';
import { CreateStrategyTemplate } from './../../../utils/strategy/template';
import { NotificationDriver } from './../../../utils/NotificationDriver';
import { ManageStrategyDriver } from './../../../utils/strategy/ManageStrategyDriver';
import { waitModalOpen } from '../../../utils/modal';
import { SafeDecimal } from '../../../../src/libs/safedecimal';

export const undercutStrategyTest = (testCase: CreateStrategyTemplate) => {
return test('Undercut', async ({ page }) => {
const { base, quote, buy, sell } = testCase;
const buyBudgetFiat = parseFloat(buy.budgetFiat ?? '0');
const sellBudgetFiat = parseFloat(sell.budgetFiat ?? '0');
const undercutRate = 0.001;

const manage = new ManageStrategyDriver(page);
const strategy = await manage.createStrategy(testCase);
await strategy.clickManageEntry('manage-strategy-duplicateStrategy');

const modal = await waitModalOpen(page);
await modal.getByTestId('undercut-strategy-btn').click();

await page.waitForURL('/strategies/create?strategy=*', {
timeout: 10_000,
});

await page.getByText('Create Strategy').click();
await page.waitForURL('/', { timeout: 10_000 });

const notif = new NotificationDriver(page, 'create-strategy');
await expect(notif.getTitle()).toHaveText('Success');
await expect(notif.getDescription()).toHaveText(
'New strategy was successfully created.'
);

const myStrategies = new MyStrategyDriver(page);
const strategies = await myStrategies.getAllStrategies();
await expect(strategies).toHaveCount(2);

const strategyUndercut = await myStrategies.getStrategy(2);

await expect(strategyUndercut.pair()).toHaveText(`${base}/${quote}`);
await expect(strategyUndercut.status()).toHaveText('Active');
await expect(strategyUndercut.totalBudget()).toHaveText(
fiatPrice(buyBudgetFiat + sellBudgetFiat)
);
await expect(strategyUndercut.buyBudget()).toHaveText(
tokenPrice(buy.budget, quote)
);
await expect(strategyUndercut.buyBudgetFiat()).toHaveText(
fiatPrice(buyBudgetFiat)
);
await expect(strategyUndercut.sellBudget()).toHaveText(
tokenPrice(sell.budget, base)
);
await expect(strategyUndercut.sellBudgetFiat()).toHaveText(
fiatPrice(sellBudgetFiat)
);

const buyTooltip = await strategyUndercut.priceTooltip('buy');
await expect(buyTooltip.startPrice()).toHaveText(
tokenPrice(
new SafeDecimal(buy.min).times(1 + undercutRate).toString(),
quote
)
);
await buyTooltip.waitForDetached();

const sellTooltip = await strategyUndercut.priceTooltip('sell');
await expect(sellTooltip.startPrice()).toHaveText(
tokenPrice(
new SafeDecimal(sell.min).times(1 - undercutRate).toString(),
quote
)
);
await sellTooltip.waitForDetached();
});
};
1 change: 1 addition & 0 deletions e2e/utils/strategy/MyStrategyDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class MyStrategyDriver {
minPrice: () => tooltip.getByTestId('min-price'),
maxPrice: () => tooltip.getByTestId('max-price'),
marginalPrice: () => tooltip.getByTestId('marginal-price'),
startPrice: () => tooltip.getByTestId('start-price'),
waitForDetached: async () => {
await this.page.mouse.move(0, 0);
await tooltip.waitFor({ state: 'detached' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ const OrderTooltip: FC<OrderTooltipProps> = ({ strategy, buy }) => {
<th className="p-8 text-start font-weight-400 text-white/60">
Price
</th>
<td className="p-8 text-end">
<td className="p-8 text-end" data-testid="start-price">
{startPrice} {quote.symbol}
</td>
</tr>
Expand Down

0 comments on commit 2e75458

Please sign in to comment.