Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Market tests adjustments #630

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/frontend/components/Borrow/Borrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function Borrow({ isEditing, basePosition }: BorrowProps) {
const allow = useBorrow((state) => state.allow);
const updateCurrencyPrice = useBorrow((state) => state.updateCurrencyPrice);
const signAndExecute = useBorrow((state) => state.signAndExecute);
const changeActiveVault = useBorrow((state) => state.changeActiveVault);

const position = basePosition ? basePosition.position : undefined;
const dynamicLtvMeta = ltvMeta(basePosition);
Expand Down Expand Up @@ -139,6 +140,17 @@ function Borrow({ isEditing, basePosition }: BorrowProps) {
updateCurrencyPrice(AssetType.Debt);
}, [updateCurrencyPrice]);

const resetData = () => {
walletChainId &&
changeAssetChain(AssetType.Collateral, walletChainId, true);
};

useEffect(() => {
return () => {
resetData();
};
}, []); // eslint-disable-line

useEffect(() => {
if (prevActionType.current !== actionType) {
changeInputValues('', '');
Expand Down
10 changes: 6 additions & 4 deletions packages/frontend/components/Borrow/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ function BorrowHeader({
<Typography variant="body2" height="40px" lineHeight="40px">
Borrow
</Typography>
<HeaderInfo
isCrossChainOperation={isCrossChainOperation}
chainName={chainName}
/>
{debt && (
<HeaderInfo
isCrossChainOperation={isCrossChainOperation}
chainName={chainName}
/>
)}
</Stack>
)}
<Divider sx={{ mt: '1rem', mb: '0.5rem' }} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function IntegratedProviders({ providers }: IntegratedProvidersProps) {
zIndex: 4 - i,
height: '24px',
}}
data-cy="provider-item"
>
{i <= 2 && (
<ProviderIcon
Expand Down
75 changes: 46 additions & 29 deletions packages/frontend/tests/e2e/specs/markets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,23 @@ describe('Markets', () => {
})
.click();
// checking rows count changes.
cy.get('[data-cy="market-row"]')
.then((value) => {
resultLength = value.length;
expect(resultLength).to.not.eq(startLength);
})
.first()
.find('[data-cy="market-row-network"]')
.first()
.then((network) => {
// checking rows filtered by network properly.
expect(network).to.have.text(chainName);
// clicking first network filter button which is ALL.
cy.get('[data-cy="market-network-filter"]').first().click();
// checking rows count is same as in default state.
cy.get('[data-cy="market-row"]').then((value) => {
expect(value.length).to.eq(startLength);
cy.get('[data-cy="market-row"]').then((value) => {
resultLength = value.length;
expect(resultLength).to.not.eq(startLength);
cy.get('[data-cy="market-row"]')
.find('[data-cy="market-row-network"]')
.first()
.then((network) => {
// checking rows filtered by network properly.
expect(network).to.include.text(chainName);
// clicking first network filter button which is ALL.
cy.get('[data-cy="market-network-filter"]').first().click();
// checking rows count is same as in default state.
cy.get('[data-cy="market-row"]').then((value) => {
expect(value.length).to.eq(startLength);
});
});
});
});
});
it('should toggle first high-level row', () => {
// finding first row.
Expand All @@ -146,11 +145,12 @@ describe('Markets', () => {
.should('not.exist');
});
it('should redirect after click with correct currency prefill', () => {
let collateralCurrency, debtCurrency;
let collateralCurrency, debtCurrency, provider;
// finding first row.
cy.get('[data-cy="market-row"]').first().as('firstRow', { type: 'static' });
cy.get('@firstRow')
.find('[data-cy="market-row-debt"]')
.first()
.invoke('text')
.then((debt) => {
// saving first row debt currency.
Expand All @@ -159,24 +159,41 @@ describe('Markets', () => {
.then(() => {
cy.get('@firstRow')
.find('[data-cy="market-row-collateral"]')
.first()
.invoke('text')
.then((collateral) => {
// saving first row collateral currency.
collateralCurrency = collateral;
})
.then(() => {
// clicking on first row.
cy.get('@firstRow').first().click();
// checking redirect to borrow page.
cy.location('pathname').should('eq', '/borrow');
// checking prefilled collateral currency.
cy.get('[data-cy="currency-select"]')
cy.get('[data-cy="provider-item"]')
.first()
.should('have.text', collateralCurrency);
// checking prefilled debt currency.
cy.get('[data-cy="currency-select"]')
.last()
.should('have.text', debtCurrency);
.find('img')
.first()
.then((image) => {
provider = image.attr('alt');

// clicking on first pair second row.
cy.get('[data-cy="market-row"]').eq(1).click();
// checking redirect to borrow page.
cy.location('pathname').should('eq', '/borrow');
// checking prefilled collateral currency.
cy.get('[data-cy="currency-select"]')
.first()
.should('have.text', collateralCurrency);
// checking prefilled debt currency.
cy.get('[data-cy="currency-select"]')
.last()
.should('have.text', debtCurrency);

cy.get('[data-cy="provider-item"]')
.first()
.find('img')
.first()
.then((image) => {
expect(provider).to.eq(image.attr('alt'));
});
});
});
});
});
Expand Down