Skip to content

Commit

Permalink
test(e2e): makes commands reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodressel authored and mmpetarpeshev committed Jun 25, 2024
1 parent adb1338 commit 2083a04
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 69 deletions.
39 changes: 25 additions & 14 deletions tests/e2e/specs/pool.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,38 @@ describe('Pool', () => {
});

it('Provide Liquidity', () => {
cy.login().get('[data-cy=pool]').filter(':visible').click();
cy.login();
cy.get('[data-cy=pool]').filter(':visible').click();
cy.get('.title').should('contain', 'Pool');
cy.get('.pool-view').should('be.visible');

cy.get('[data-cy=add-liquidity]').click();
cy.get('.add-liquidity').should('be.visible');
cy.get('.input-token input')
.eq(0)
.type('1')
.get('.input-token input')
.eq(1)
.type('1')
.get('.provide-liquidity-modal button.primary')
.click()
.get('.confirm-transaction-modal')
.should('be.visible')
.get('.confirm-transaction-modal button.primary')
.click();
cy.selectToken(0);
cy.selectToken(1, 'ct_b7FZHQzBcAW4r43ECWpV3qQJMQJp5BxkZUGNKrqqLyjVRN3SC');
cy.get('.input-token input').eq(0).type('0.1');

// intercept the approval transaction
cy.intercept({
method: 'POST',
url: 'https://testnet.aeternity.io/v3/transactions*',
times: 1,
}).as('postTx');

cy.contains('Approve').click();
cy.wait('@walletSignTx', { timeout: 10000 });
cy.wait('@postTx', { timeout: 10000 });

// wait for notification to appear
cy.get('.notification-transaction-status').should('be.visible', { timeout: 10000 });

cy.interceptTxPost();
cy.contains('Supply').click();
cy.wait('@walletSignTx', { timeout: 10000 });
cy.wait('@postTx', { timeout: 10000 });
});

it('Remove Liquidity', () => {
it.skip('Remove Liquidity', () => {
cy.login()
.get('[data-cy=pool]')
.filter(':visible')
Expand Down
52 changes: 11 additions & 41 deletions tests/e2e/specs/swap.cy.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,16 @@
describe('Swap', () => {
it('Swap Token', () => {
cy.login()
// get first .input-token
.get('.input-token button')
.first()
.click()
// token pop up should open
.get('.select-token-modal')
.should('be.visible')
// select first token
.get('.select-token-modal .token')
.click()
// expect ae to be selected
.get('.input-token')
.first()
.should('contain', 'AE')
// select second token
// get first .input-token
.get('.input-token button')
.eq(1)
.click()
// token pop up should open
.get('.select-token-modal')
.should('be.visible')
// select first token
.get('.select-token-modal .search-bar')
.type('ct_b7FZHQzBcAW4r43ECWpV3qQJMQJp5BxkZUGNKrqqLyjVRN3SC')
//
.get('.select-token-modal .import-button')
.click()
// warning should be shown
.get('.select-token-modal')
.should('contain', 'Make sure this is the token that you want to trade.')
// confirm import
.get('.select-token-modal .import-button')
.click()
// expect ae to be selected
.get('.input-token')
.eq(1)
.should('contain', 'TAEX9-A')
// input amount
.get('.input-token input')
cy.interceptTxPost();
cy.login();
cy.selectToken(0);
cy.selectToken(1, 'ct_b7FZHQzBcAW4r43ECWpV3qQJMQJp5BxkZUGNKrqqLyjVRN3SC');

cy.get('.input-token').first().should('contain', 'AE');

// expect ae to be selected
cy.get('.input-token').eq(1).should('contain', 'TAEX9-A');
// input amount
cy.get('.input-token input')
.eq(0)
.type('1')
// expect second input to have a number
Expand Down
37 changes: 34 additions & 3 deletions tests/e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,38 @@ Cypress.Commands.add('login', () => {
.should('contain', 'Testnet');
});

Cypress.Commands.add('logout', () => {
cy.get('[data-cy=wallet-address]').click().get('[data-cy=wallet-disconnect]').click();
// TODO: check if we gonna disconnect from wallet.superhero.com too
Cypress.Commands.add('selectToken', (slot, token) => {
// get first .input-token
cy.get('.input-token button')
.eq(slot)
.click()
// token pop up should open
.get('.select-token-modal')
.should('be.visible');
// select first token
if (token) {
cy.get('.select-token-modal .search-bar')
.type(token)
.get('.select-token-modal .import-button')
.click()
// warning should be shown
.get('.select-token-modal')
.should('contain', 'Make sure this is the token that you want to trade.')
// confirm import
.get('.select-token-modal .import-button')
.click();
} else {
cy.get('.select-token-modal .token').click();
}
});

Cypress.Commands.add('interceptTxPost', () => {
cy.intercept(
{
method: 'POST',
url: 'https://testnet.aeternity.io/v3/transactions*',
times: 1,
},
{ tx_hash: 'th_8zREhgdJmg8LxG5hnJ2Eq63n7ZTbJMeZfi8EETDjtdnmv4Ksk' },
).as('postTx');
});
13 changes: 2 additions & 11 deletions tests/e2e/support/networkStubs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import aeSdk from './testAeSdk';

before(() => {
beforeEach(() => {
cy.intercept('GET', 'https://wallet.superhero.com/sign-transaction*', (req) => {
// extract transaction from query
const transaction = new URL(req.url).searchParams.get('transaction');
Expand All @@ -21,15 +21,6 @@ before(() => {
);
});
}).as('walletAddress');

cy.intercept(
{
method: 'POST',
url: 'https://testnet.aeternity.io/v3/transactions*',
},
{ tx_hash: 'th_8zREhgdJmg8LxG5hnJ2Eq63n7ZTbJMeZfi8EETDjtdnmv4Ksk' },
).as('postTx');
});

// Alternatively you can use CommonJS syntax:
// require('./commands')
export {};

0 comments on commit 2083a04

Please sign in to comment.