Skip to content

Commit

Permalink
Add error input test flows
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Oct 25, 2023
1 parent 0c138e6 commit bf507c3
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 22 deletions.
114 changes: 93 additions & 21 deletions web-frontend/cypress/e2e/acceptance/home/send.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('E2E | Acceptance | Home', () => {
const account = mockedAccounts.at(2);

navigateToTransfercoins(2);
// cy.get('[data-testid="balance-amount"]').contains(getBalance(account));

cy.get('[data-testid="balance-amount"]').should(
'contain',
getBalance(account),
Expand Down Expand Up @@ -249,30 +249,102 @@ describe('E2E | Acceptance | Home', () => {
);
});

// it('should land on receive page when receive CTA is clicked', () => {
// const account = mockedAccounts.at(2);
it('should refuse wrong currency input', () => {
const account = mockedAccounts.at(2);
const recipientAccount = mockedAccounts.at(1);

// cy.visit('/');
const amount = 1000.12311132;
const invalidAmount = 'things';
const tooMuch = Number(account?.candidateBalance) + 1000;
const tooLow = 0;
const notEnoughForFees = Number(account?.candidateBalance);

// cy.get('[data-testid="account-2"]').click();
// cy.get('[data-testid="receive-button"]').click();
// cy.url().should('eq', `${baseUrl}/${account.nickname}/transfer-coins`);
const standardFees = '1000';
navigateToTransfercoins(2);

// cy.get('[data-testid="send-coins"]').should('not.be.visible');
// cy.get('[data-testid="receive-coins"]').should('be.visible');
// });
cy.get('[data-testid="currency-field"')
.should('exist')
.type(invalidAmount);

cy.get('[data-testid="input-field"').type(recipientAccount.address);

cy.get('[data-testid="button"]').contains('Send').click();

cy.get('[data-testid="input-field-message"]').should(
'contain.text',
'Invalid amount',
);

cy.get('[data-testid="currency-field"')
.clear()
.should('exist')
.type(tooMuch);

cy.get('[data-testid="button"]').contains('Send').click();

cy.get('[data-testid="input-field-message"]').should(
'contain.text',
'Insufficient funds',
);

cy.get('[data-testid="currency-field"')
.clear()
.should('exist')
.type(tooLow);

cy.get('[data-testid="button"]').contains('Send').click();

// it('should copy wallet address when clipboard field is clicked', () => {
// // we are adding the permission to chrome on the fly
// cy.wrap(
// Cypress.automation('remote:debugger:protocol', {
// command: 'Browser.grantPermissions',
// params: {
// permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
// origin: window.location.origin,
// },
// }),
// );
cy.get('[data-testid="input-field-message"]').should(
'contain.text',
'Amount must be greater than zero',
);

// testing amount + fees to hugh seems tricky
// amount + fees to high also triggers insufficient funds
// there mayeb we can refacto it ?
// See sendForm.tsx line 84

cy.get('[data-testid="currency-field"')
.clear()
.should('exist')
.type(notEnoughForFees);

cy.get('[data-testid="button"]').contains('Send').click();

cy.get('[data-testid="input-field-message"]').should(
'contain.text',
'Insufficient funds',
);
});

it('should refuse wrong addrress input', () => {
const account = mockedAccounts.at(2);
const wrongAddress = 'wrong address';

const amount = 1000.12311132;

navigateToTransfercoins(2);
cy.get('[data-testid="currency-field"')
.should('exist')
.type(amount)
.should('have.value', customFormatNumber(amount));

cy.get('[data-testid="input-field"').type(wrongAddress);
cy.get('[data-testid="button"]').contains('Send').click();

cy.get('[data-testid="input-field-message"]').should(
'contain.text',
'Recipient address is not a valid Massa address',
);

cy.get('[data-testid="input-field"').clear();
cy.get('[data-testid="button"]').contains('Send').click();

cy.get('[data-testid="input-field-message"]').should(
'contain.text',
'Recipient is required',
);
});

// const account = mockedAccounts.at(2);

Expand Down
2 changes: 1 addition & 1 deletion web-frontend/src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"link": "Go back to the Welcome page!"
},
"send-coins": {
"invalid-amount": "invalid amount",
"invalid-amount": "Invalid amount",
"amount-to-high": "Insufficient funds",
"amount-plus-fees-to-high": "Insufficient funds to pay fees",
"amount-to-low": "Amount must be greater than zero",
Expand Down

0 comments on commit bf507c3

Please sign in to comment.