From 764cd13b76faa9ceeccbfc71660102472d510f0d Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Wed, 17 Jan 2024 18:57:45 +0000 Subject: [PATCH] Update recurring e2e tests to add undercut with testCase input and output --- e2e/pages/strategy.spec.ts | 15 ++++++ e2e/tests/strategy/recurring/undercut.ts | 54 +++++++--------------- e2e/utils/strategy/CreateStrategyDriver.ts | 15 ++++++ 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/e2e/pages/strategy.spec.ts b/e2e/pages/strategy.spec.ts index c5a502e78..269220a4c 100644 --- a/e2e/pages/strategy.spec.ts +++ b/e2e/pages/strategy.spec.ts @@ -42,6 +42,21 @@ const testCases: CreateStrategyTestCase[] = [ fiat: '$3,334.42', }, }, + undercut: { + totalFiat: '$3,344.42', + buy: { + min: '1,501.50 DAI', + max: '1,501.50 DAI', + budget: '10.00 DAI', + fiat: '$10.00', + }, + sell: { + min: '1,698.30 DAI', + max: '1,698.30 DAI', + budget: '2.00 ETH', + fiat: '$3,334.42', + }, + }, }, }, { diff --git a/e2e/tests/strategy/recurring/undercut.ts b/e2e/tests/strategy/recurring/undercut.ts index 64db80bf0..cc1e3b679 100644 --- a/e2e/tests/strategy/recurring/undercut.ts +++ b/e2e/tests/strategy/recurring/undercut.ts @@ -1,21 +1,20 @@ import { expect, test } from '@playwright/test'; -import { MyStrategyDriver } from './../../../utils/strategy'; -import { fiatPrice, tokenPrice } from './../../../utils/operators'; -import { CreateStrategyTemplate } from './../../../utils/strategy/template'; +import { + CreateStrategyTestCase, + MyStrategyDriver, + assertRecurringTestCase, +} from './../../../utils/strategy'; 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) => { +export const undercutStrategyTest = (testCase: CreateStrategyTestCase) => { + assertRecurringTestCase(testCase); + const { base, quote } = testCase.input; + const output = testCase.output.undercut; 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); + const strategy = await manage.createStrategy(testCase.input); await strategy.clickManageEntry('manage-strategy-duplicateStrategy'); const modal = await waitModalOpen(page); @@ -39,41 +38,22 @@ export const undercutStrategyTest = (testCase: CreateStrategyTemplate) => { 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.totalBudget()).toHaveText(output.totalFiat); + await expect(strategyUndercut.buyBudget()).toHaveText(output.buy.budget); + await expect(strategyUndercut.buyBudgetFiat()).toHaveText(output.buy.fiat); + await expect(strategyUndercut.sellBudget()).toHaveText(output.sell.budget); await expect(strategyUndercut.sellBudgetFiat()).toHaveText( - fiatPrice(sellBudgetFiat) + output.sell.fiat ); const buyTooltip = await strategyUndercut.priceTooltip('buy'); - await expect(buyTooltip.startPrice()).toHaveText( - tokenPrice( - new SafeDecimal(buy.min).times(1 + undercutRate).toString(), - quote - ) - ); + await expect(buyTooltip.startPrice()).toHaveText(output.buy.min); 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 expect(sellTooltip.startPrice()).toHaveText(output.sell.min); await sellTooltip.waitForDetached(); }); }; diff --git a/e2e/utils/strategy/CreateStrategyDriver.ts b/e2e/utils/strategy/CreateStrategyDriver.ts index ed789b630..0d8ebe642 100644 --- a/e2e/utils/strategy/CreateStrategyDriver.ts +++ b/e2e/utils/strategy/CreateStrategyDriver.ts @@ -34,6 +34,21 @@ export interface RecurringStrategyOutput { fiat: string; }; }; + undercut: { + totalFiat: string; + buy: { + min: string; + max: string; + budget: string; + fiat: string; + }; + sell: { + min: string; + max: string; + budget: string; + fiat: string; + }; + }; } export type RecurringStrategyTestCase = TestCase< RecurringStrategyInput,