-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1459 from bancorprotocol/fix/edit-budget
Fix distribution budget on edit
- Loading branch information
Showing
22 changed files
with
259 additions
and
23 deletions.
There are no files selected for viewing
Binary file modified
BIN
+7.42 KB
(120%)
e2e/screenshots/simulator/recurring/Recurring_limit_limit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-8.73 KB
(84%)
e2e/screenshots/simulator/recurring/Recurring_range_limit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+850 Bytes
(100%)
e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+852 Bytes
(100%)
e2e/screenshots/strategy/disposable/Disposable_buy_range/create/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
e2e/screenshots/strategy/disposable/Disposable_buy_range/create/my-strategy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.42 KB
(97%)
e2e/screenshots/strategy/disposable/Disposable_buy_range/deposit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3 Bytes
(100%)
e2e/screenshots/strategy/disposable/Disposable_sell_limit/create/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1 Byte
(100%)
e2e/screenshots/strategy/overlapping/Overlapping/deposit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-611 Bytes
(99%)
e2e/screenshots/strategy/recurring/Recurring_limit_limit/deposit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-396 Bytes
(99%)
e2e/screenshots/strategy/recurring/Recurring_limit_limit/editPrices/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.3 KB
(100%)
e2e/screenshots/strategy/recurring/Recurring_limit_range/duplicate/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-388 Bytes
(99%)
e2e/screenshots/strategy/recurring/Recurring_limit_range/editPrices/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-901 Bytes
(98%)
e2e/screenshots/strategy/recurring/Recurring_range_limit/deposit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-132 Bytes
(100%)
e2e/screenshots/strategy/recurring/Recurring_range_range/editPrices/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/libs/testing-library/drivers/EditStrategyDriver.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { | ||
Screen, | ||
waitForElementToBeRemoved, | ||
within, | ||
} from '@testing-library/dom'; | ||
|
||
export class EditStrategyDriver { | ||
constructor(private screen: Screen) {} | ||
|
||
async findForm() { | ||
return this.screen.findByTestId('edit-form'); | ||
} | ||
|
||
async findDisposableForm() { | ||
const form = await this.findForm(); | ||
return { | ||
element: form, | ||
min: () => within(form).getByTestId('input-min'), | ||
max: () => within(form).getByTestId('input-max'), | ||
price: () => within(form).getByTestId('input-price'), | ||
tabSell: () => within(form).getByTestId('tab-sell'), | ||
tabBuy: () => within(form).getByTestId('tab-buy'), | ||
limit: () => within(form).getByTestId('tab-limit'), | ||
range: () => within(form).getByTestId('tab-range'), | ||
budget: () => within(form).getByTestId('input-budget'), | ||
marketPriceIndicators: () => | ||
within(form).queryAllByTestId('market-price-indication'), | ||
approveWarnings: () => within(form).queryByTestId('approve-warnings'), | ||
submit: () => within(form).getByTestId('edit-submit'), | ||
}; | ||
} | ||
|
||
async findRecurringForm() { | ||
const form = await this.findForm(); | ||
const buySection = within(form).getByTestId('buy-section'); | ||
const sellSection = within(form).getByTestId('sell-section'); | ||
return { | ||
element: form, | ||
buy: { | ||
min: () => within(buySection).getByTestId('input-min'), | ||
max: () => within(buySection).getByTestId('input-max'), | ||
price: () => within(buySection).getByTestId('input-price'), | ||
limit: () => within(buySection).getByTestId('tab-limit'), | ||
range: () => within(buySection).getByTestId('tab-range'), | ||
budget: () => within(buySection).getByTestId('input-budget'), | ||
marketPriceIndicators: () => | ||
within(buySection).queryAllByTestId('market-price-indication'), | ||
}, | ||
sell: { | ||
min: () => within(sellSection).getByTestId('input-min'), | ||
max: () => within(sellSection).getByTestId('input-max'), | ||
price: () => within(sellSection).getByTestId('input-price'), | ||
limit: () => within(sellSection).getByTestId('tab-limit'), | ||
range: () => within(sellSection).getByTestId('tab-range'), | ||
budget: () => within(sellSection).getByTestId('input-budget'), | ||
marketPriceIndicators: () => | ||
within(sellSection).queryAllByTestId('market-price-indication'), | ||
}, | ||
approveWarnings: () => within(form).queryByTestId('approve-warnings'), | ||
submit: () => within(form).getByTestId('edit-submit'), | ||
}; | ||
} | ||
|
||
async findOverlappingForm() { | ||
const form = await this.findForm(); | ||
return { | ||
element: form, | ||
min: () => within(form).getByTestId('input-min'), | ||
max: () => within(form).getByTestId('input-max'), | ||
spread: { | ||
input: () => within(form).getByTestId('spread-input'), | ||
default: () => within(form).getByTestId('spread-0.05'), | ||
option: (value: string) => within(form).getByTestId(`spread-${value}`), | ||
}, | ||
anchorRequired: () => within(form).queryByTestId('require-anchor'), | ||
anchor: (anchor: 'buy' | 'sell') => | ||
within(form).getByTestId(`anchor-${anchor}`), | ||
budget: () => within(form).getByTestId('input-budget'), | ||
marketPriceIndicators: () => | ||
within(form).queryAllByTestId('market-price-indication'), | ||
approveWarnings: () => within(form).queryByTestId('approve-warnings'), | ||
submit: () => within(form).getByTestId('edit-submit'), | ||
}; | ||
} | ||
|
||
async findUserPriceForm() { | ||
return this.screen.findByTestId('user-price-form'); | ||
} | ||
|
||
async findEditMarketPrice() { | ||
return this.screen.findByTestId('edit-market-price'); | ||
} | ||
|
||
async findUserPriceInput() { | ||
const priceForm = await this.findUserPriceForm(); | ||
return { | ||
editPrice: () => within(priceForm).getByTestId('input-price'), | ||
approveWarning: () => | ||
within(priceForm).getByTestId('approve-price-warnings'), | ||
confirm: () => within(priceForm).getByTestId('set-overlapping-price'), | ||
}; | ||
} | ||
|
||
waitForLoading(parent: HTMLElement) { | ||
const loadings = parent.querySelectorAll('.loading-message'); | ||
const waitForAll = Array.from(loadings).map((loading) => { | ||
return waitForElementToBeRemoved(() => loading); | ||
}); | ||
return Promise.all(waitForAll); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { describe, test, expect, beforeAll, afterAll } from 'vitest'; | ||
import { | ||
MockServer, | ||
marketRateHandler, | ||
renderWithRouter, | ||
screen, | ||
tokenList, | ||
userEvent, | ||
} from 'libs/testing-library'; | ||
import { EditStrategyDriver } from 'libs/testing-library/drivers/EditStrategyDriver'; | ||
import { EditBudgetRecurringPage } from './recurring'; | ||
import { EditStrategyProvider } from 'components/strategies/edit/EditStrategyContext'; | ||
import { Strategy } from 'libs/queries'; | ||
import { SafeDecimal } from 'libs/safedecimal'; | ||
import { carbonSDK } from 'libs/sdk'; | ||
import { spyOn } from '@vitest/spy'; | ||
import { EditStrategyLayout } from 'components/strategies/edit/EditStrategyLayout'; | ||
|
||
const basePath = '/strategies/edit/$strategyId/budget/recurring'; | ||
|
||
const marketRates: Record<string, Record<string, number>> = { | ||
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': { USD: 1 }, // USDC | ||
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': { USD: 2.5 }, // ETH | ||
}; | ||
|
||
const mockServer = new MockServer([marketRateHandler(marketRates)]); | ||
|
||
beforeAll(() => mockServer.start()); | ||
afterAll(() => mockServer.close()); | ||
|
||
interface Props { | ||
strategy: Strategy; | ||
type: 'deposit' | 'withdraw'; | ||
} | ||
|
||
const WrappedRecurring = ({ strategy, type }: Props) => { | ||
return ( | ||
<EditStrategyProvider strategy={strategy}> | ||
<EditStrategyLayout editType={type}> | ||
<EditBudgetRecurringPage /> | ||
</EditStrategyLayout> | ||
</EditStrategyProvider> | ||
); | ||
}; | ||
|
||
describe('Create recurring page', () => { | ||
test('should only send to the SDK what has been changed', async () => { | ||
const baseToken = tokenList.ETH; | ||
const quoteToken = tokenList.USDC; | ||
|
||
const strategy: Strategy = { | ||
id: '1', | ||
idDisplay: '1', | ||
base: baseToken, | ||
quote: quoteToken, | ||
order0: { | ||
balance: '1', | ||
startRate: '1', | ||
endRate: '2', | ||
marginalRate: '1.5', | ||
}, | ||
order1: { | ||
balance: '1', | ||
startRate: '3', | ||
endRate: '4', | ||
marginalRate: '3.5', | ||
}, | ||
status: 'active', | ||
encoded: {} as any, | ||
roi: new SafeDecimal('1'), | ||
}; | ||
|
||
const search = { | ||
editType: 'deposit', | ||
buyBudget: '2', | ||
}; | ||
|
||
const url = `/strategies/edit/${strategy.id}/budget/recurring`; | ||
const { router } = await renderWithRouter({ | ||
component: () => <WrappedRecurring strategy={strategy} type="deposit" />, | ||
basePath, | ||
search, | ||
params: { strategyId: strategy.id }, | ||
}); | ||
const user = userEvent.setup(); | ||
|
||
// Check search params | ||
expect(router.state.location.pathname).toBe(url); | ||
expect(router.state.location.search).toStrictEqual(search); | ||
|
||
const recurringDriver = new EditStrategyDriver(screen); | ||
const form = await recurringDriver.findRecurringForm(); | ||
|
||
// Check form | ||
expect(form.buy.budget()).toHaveValue(search.buyBudget); | ||
expect(form.sell.budget()).toHaveValue(''); | ||
const spy = spyOn(carbonSDK, 'updateStrategy'); | ||
await user.click(form.submit()); | ||
expect(spy).toHaveBeenCalledWith( | ||
strategy.id, | ||
strategy.encoded, | ||
{ buyBudget: '3' }, | ||
undefined, | ||
undefined | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters