Skip to content

Commit

Permalink
✅Add test to validate the input & output consistency on SDEX swap
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPoblete committed Aug 1, 2024
1 parent c67c0c0 commit 00f5d3e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
63 changes: 59 additions & 4 deletions cypress/e2e/flows.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// cypress/integration/navigation.ts

import { is } from 'cypress/types/bluebird';

//Bridge flow
describe('Bridge flow', () => {
Expand Down Expand Up @@ -91,9 +90,8 @@ describe('Select tokens & input amount', () => {
cy.wait(2500);

//Get the output amount
cy.get('[data-testid="swap__output__panel"]').within(() => {
cy.get('.token-amount-input').invoke('val').as('outputAmount');
});
cy.get('[data-testid="swap-output-input-panel"]').invoke('val').as('outputAmount');

cy.get('@outputAmount').should('not.be.empty');
cy.get('@outputAmount').should('have.length.greaterThan', 7);

Expand Down Expand Up @@ -132,6 +130,63 @@ describe('Select tokens & input amount', () => {
});
});

describe('Input & output amount validation', () => {
it('should type an input amount & wait for output amount', () => {
cy.visit('/swap');
//Select input asset
/* cy.get('[data-testid="swap__input__panel"]').within(() => {
cy.get('[data-testid="swap__token__select"]').click();
});
cy.get('[data-testid="currency__list__XLM"]').click();
*/
//Select output asset
cy.get('[data-testid="swap__output__panel"]').within(() => {
cy.get('[data-testid="swap__token__select"]').click();
});
cy.get('[data-testid="token-search-input"]').type('ngnt');
cy.get('[data-testid="currency__list__NGNT"]').click();


//Input amount
cy.get('[data-testid="swap__input__panel"]').within(() => {
cy.get('.token-amount-input').type('1');
});
//await for calcs
cy.wait(5000);
cy.screenshot()
//Get the output amount
cy.get('[data-testid="swap-output-input-panel"]').invoke('val').as('outputAmount');
//Get the input amount
cy.get('[data-testid="swap-input-input-panel"]').invoke('val').as('inputAmount');

//Validate type in
cy.get('@inputAmount').should('eq', '1');

cy.get('[data-testid="swap-output-input-panel"]').invoke('val')
.then((outputAmount: any) => {
//reselect input asset
cy.get('[data-testid="swap__input__panel"]').within(() => {
cy.get('[data-testid="swap__token__select"]').click();
});
cy.get('[data-testid="token-search-input"]').type('ngnt');
cy.get('[data-testid="currency__list__NGNT"]').click();
//Input amount
cy.get('[data-testid="swap__output__panel"]').within(() => {
cy.get('.token-amount-input').type('{backspace}');
cy.get('.token-amount-input').type('{backspace}');
cy.get('.token-amount-input').type('1');
});
cy.wait(2500);
cy.screenshot()
cy.get('[data-testid="swap-input-input-panel"]').invoke('val').then((inputAmount: any)=>{
const belowOutput = Math.floor(parseFloat(outputAmount) * 0.9);
const aboveOutput = Math.ceil(parseFloat(outputAmount) * 1.1);
expect(parseFloat(inputAmount)).within(belowOutput, aboveOutput)
})
})

})
});
// Navigation flow
describe('Navigation flow', () => {
it('should render the navbar', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export default function SwapCurrencyInputPanel({
onUserInput={onUserInput}
disabled={!chainAllowed || disabled || disableInput}
$loading={loading}
data-testid={`${id}-input-panel`}
/>
)}
</InputRow>
Expand Down

0 comments on commit 00f5d3e

Please sign in to comment.