Skip to content

Commit

Permalink
Code refactoring and new test scripts automated
Browse files Browse the repository at this point in the history
  • Loading branch information
taimuraamer committed Jun 27, 2023
1 parent b81f7f6 commit 844c9f0
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 27 deletions.
33 changes: 23 additions & 10 deletions e2e/cypress/fixtures/selectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"connectToMetamask": "div[class='sc-iqHYmW jsRmqq']",
"connectWallet":"button[class='sc-fubCzh exdHlk']",
"connected": ".sc-ibxdXY UfbkG css-8visvh",
"gasToken": "div[class='sc-jmdVzn kYCKo css-8visvh']",
"walletAddress": "p[class='sc-kLjoBy hBytEM']",
"nativeToken": "div[class='sc-gdKWnS sc-fkaoMN djcPdi ixgCNr']",
"gasToken": "div[class='sc-cXGEIS gVAxCC css-8visvh']",
"walletAddress": "p[class='sc-bvJpEl eEfCOq']",
"nativeToken": "div[class='sc-NGuuG sc-jmdVzn jGHUkW dFKmPi']",
"nativeTokenDeatils": "div[class='sc-iqHYmW fznvqs']",
"nativeTokenLogo": "img[class='sc-ezredP iPgjFG']",
"nativeTokenLogo": "[class='sc-kEjbQP sc-VhHcL iqcNnm eeNTYy'] img[class='sc-ezredP iPgjFG']",
"nativeTokenBalance": "div[class='sc-iqHYmW buqNus']",
"detailsMenuClose": "svg[class='sc-kOtXPA cEoheH']",
"changeBtn": "button[class='sc-fubCzh fBmMeN sc-jtazFa sc-iYXQCk sc-eSBXJh bKlgKv gZFcTV imQxVR']",
"changeBtn": "button[class='sc-fubCzh fBmMeN sc-dHhxQd sc-hHdtSz sc-kiEqrO gqwtAw repgZ jPLMyI']",
"walletConnected": "div[class='sc-gYhhMS kUMVn']",
"accountMenuClose": "svg[class='sc-kOtXPA cEoheH']",
"totalAmount": "div[class='sc-iqHYmW iPElRN']",
Expand Down Expand Up @@ -116,8 +116,8 @@
"clearAll":"button[class='sc-gJnOmN dDjmVt']",
"transactionAppear":"div[class='sc-fIUAFO henkdw css-gp5dfh']",
"accountMenuCloseSwap":"div[class='sc-kEjbQP sc-iMyPae iqcNnm ekaUlm']",
"notification":"[class='sc-fIUAFO itZXRL css-1a92al5']",
"notificationViewOnExplorer":"a[class='sc-hiAVnf jKUipH']",
"notification":"[class='sc-iYXQCk NcoRw css-1a92al5']",
"notificationViewOnExplorer":"a[class='sc-fUiULZ cEFGA']",
"transactionRejected":"div[class='sc-iqHYmW flqkxK']",
"selectTokenBtn":"span[class='sc-jJEKmz jysvvD token-symbol-container']",
"priceField":"input[class='sc-dQoVA cBTceE sc-eLgNKc jWrmCf']",
Expand Down Expand Up @@ -211,7 +211,8 @@
"stakeSideMenuSelect": "div[class='sc-gqPbQI ikudoI'] a"
},
"pools":{
"poolsSideMenu": "div[class='sc-gqPbQI ikudoI']",
"poolsSideMenu": "[id='pool']",
"standardSideMenu":"[id='standard']",
"poolsSideMenuSelect": "div[class='sc-gqPbQI ikudoI'] a",
"searchFieldPool": "#token-search-input",
"cardTitleSuper": "div[class='sc-jSMfEi jPrZZL']",
Expand Down Expand Up @@ -263,7 +264,19 @@
"importPoolTitle": "div[class='sc-jSMfEi cKdnJn']",
"importConnectWalletBtn": "div[class='sc-jSMfEi RXmdt']",
"importSelectTokens": "div[class='sc-jSMfEi bNwKAa']",
"importDropdownTokens": "div[class='sc-bdxVC hZpdoX']"
}
"importDropdownTokens": "div[class='sc-bdxVC hZpdoX']",
"createPair": "div[class='sc-iqHYmW iCNRDR']",
"createPairToken1": "div[class='sc-iqHYmW fnmIdP']",
"createPairToken2": "div[class='sc-iqHYmW dusRLR']",
"createAddBtn": "button[class='sc-eZuRTN gZWUcp']",
"createAddTitle": "div[class='sc-iqHYmW bFmqvA']",
"createAddTokenValues": "div[class='sc-iqHYmW iNMdSu']",
"createAddConfirmBtn": "button[class='sc-fubCzh jZKmXf']",
"createAddMaxBtn": "button[class='sc-BXpxD iUCTxs']",
"createAddAmountField": "input[class='sc-dQoVA hYbnKV']",
"createAddSupplyBtn": "button[class='sc-fubCzh gsRRav']",
"createAddTokenNamesValues": "div[class='sc-iqHYmW kfPvZs']",
"createAddOutputMsg": "div[class='sc-iqHYmW sc-gUUBao gtjCqr fFynoI']"
}

}
48 changes: 48 additions & 0 deletions e2e/cypress/src/pool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import selectors from '../fixtures/selectors.json'
let { tokenSearch, selectTokens, toEstimated, amountInTokensSwap, confirmSwap, toTokenChain, swappingMsg } = selectors.swap
let { createPairToken1, createPairToken2, createAddTokenValues, createAddConfirmBtn, createAddMaxBtn, createAddOutputMsg, createAddBtn, createAddAmountField, createAddSupplyBtn, createAddTokenNamesValues } = selectors.pools
function selectTokensPoolftn(token1, token2, pairBtn ) {
cy.get(createPairToken1).eq(0).click()
cy.get(tokenSearch).eq(0).should('have.attr', 'placeholder', 'Search').type(token1);
cy.get(selectTokens).contains(token1).click()
cy.get(createPairToken2).contains("Select a Token").click()
cy.get(tokenSearch).eq(1).should('have.attr', 'placeholder', 'Search').type(token2);
cy.get(selectTokens).contains(token2).click()
cy.get(createAddBtn, { timeout: 30000 }).should('contain', pairBtn).click()

}

function pairDetailsCardftn() {
for (var i = 0; i <= 1; i++) {
cy.get(toEstimated).eq(i).should('be.visible');
cy.get(createAddTokenValues).eq(i).invoke('text').should('match', /^\d+(\.\d+)?$/);
cy.get(amountInTokensSwap).eq(i).invoke('text').should('match', /^(-|0%$)/);
cy.get(createAddConfirmBtn).contains("Enter an amount").should('be.visible')
cy.get(createAddMaxBtn).eq(0).should('be.visible').click()
cy.get(amountInTokensSwap).eq(i).invoke('text').should('match', /\d+/);
cy.get(createAddAmountField).eq(i).invoke('val').should('match', /\d+/);
}
}

function createEnterValuesftn(cardName, supplyBtn, token1, token2) {
for (var i = 0; i <= 1; i++) {
// Entering values
cy.get(createAddAmountField).eq(i).type("99999");
cy.get(createAddConfirmBtn).contains(/Insufficient \w+ balance/i).should('be.visible');
cy.get(createAddAmountField).eq(i).clear();
cy.get(createAddAmountField).eq(i).type("0.001");
}

cy.get(createAddSupplyBtn).eq(0).should('contain', 'Supply').click();

// You will receive card
cy.get(confirmSwap).contains(cardName).should('be.visible');
cy.get(createAddTokenNamesValues).eq(0).contains(new RegExp(`^\\d+\\.\\d+ ${token1}$`)).should('be.visible');
cy.get(createAddTokenNamesValues).eq(1).contains(new RegExp(`^\\d+\\.\\d+ ${token2}$`)).should('be.visible');
cy.get(toTokenChain).contains("PGL").should('be.visible');
cy.get(toTokenChain).contains("Share of Pool").should('be.visible');
cy.get(createAddOutputMsg).contains("Output is estimated. If the price changes by more than 0.5% your transaction will revert.").should('be.visible');
cy.get(createAddSupplyBtn).eq(1).should('contain', supplyBtn).click();
cy.get(swappingMsg).contains(new RegExp(`^Supplying \\d+\\.\\d+ ${token1} and \\d+\\.\\d+ ${token2}$`)).should('be.visible');
}
export{selectTokensPoolftn, pairDetailsCardftn, createEnterValuesftn}
2 changes: 1 addition & 1 deletion e2e/cypress/src/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function connectWallet1 (fromSelector, toSelector, connectWalletBtnSel) {

function notificationftn(msg) {
const regexPattern = new RegExp(`.*${msg}.*`);
cy.get(notification).contains(regexPattern).should('be.visible')
cy.get(notification, { timeout: 30000 }).contains(regexPattern).should('be.visible')
cy.get(notificationViewOnExplorer).each(page => {
cy.request(page.prop('href')).as('link');
});
Expand Down
1 change: 0 additions & 1 deletion e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions e2e/tests/e2e/specs/dashboard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { connectWalletftn } from '../../../cypress/src/dashboard'

let { connectWallet,connectToMetamask,connectToWallet, connected, gasToken, walletAddress, networkName, networks, testnetBtn} = selectors.dashboard
let { networkNameArr, gasTokenArr, testnetNetworkNameArr} = data.dashboard

//To run each file
//npx env-cmd -f .env npx synpress run --spec 'tests/e2e/specs/dashboard.spec.js' -cf synpress.json
describe('Dashboard', () => {
it('Connect to Metamask', () => {
cy.visit('/dashboard')
Expand Down
112 changes: 112 additions & 0 deletions e2e/tests/e2e/specs/pool.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import selectors from '../../../cypress/fixtures/selectors.json'
import { connectWalletftn } from '../../../cypress/src/dashboard'
import { nativeDetails } from '../../../cypress/src/dashboard'
import { notificationftn } from '../../../cypress/src/swap'
import { selectTokensPoolftn } from '../../../cypress/src/pool'
import { pairDetailsCardftn } from '../../../cypress/src/pool'
import { createEnterValuesftn } from '../../../cypress/src/pool'

let { connectToWallet, connectToMetamask, connectWallet, connected } = selectors.dashboard
let { poolsSideMenu, standardSideMenu, createPair, createAddTitle } = selectors.pools

//To run each file
//npx env-cmd -f .env npx synpress run --spec 'tests/e2e/specs/pool.spec.js' -cf synpress.json
describe('pool standard', () => {
it('Connects with Metamask', () => {
//Connect to MetaMask from pool page
cy.visit('/dashboard')
cy.get(poolsSideMenu).click()
cy.get(standardSideMenu).click()
//MetaMask connection
cy.get(connectToWallet).click();
cy.get(connectToMetamask).contains("Metamask").click();
cy.get(connectWallet).click()
cy.switchToMetamaskWindow();
cy.acceptMetamaskAccess().should("be.true");
cy.switchToCypressWindow();
cy.get(connected).should("not.be.empty");
//After connecting, the Network name (Avalanche), native token (PNG) and the gas token (AVAX) in the menu will change to the chain specific ones
nativeDetails(0)
})

it('Details on Create a pair card', () => {
//Connect to MetaMask from pool page
cy.visit('/dashboard')
cy.get(poolsSideMenu).click()
cy.get(standardSideMenu).click()
//MetaMask connection
connectWalletftn()
//Create a pair
cy.get(createPair).contains("Create a pair").click()
//selecting tokens
selectTokensPoolftn("GRELF","USDt","Create a pair")
//create a pair card
cy.get(createAddTitle).contains("Create a pair").should('be.visible')
pairDetailsCardftn()
})

it('You are creating a pool card', () => {
//Connect to MetaMask from pool page
cy.visit('/dashboard')
cy.get(poolsSideMenu).click()
cy.get(standardSideMenu).click()
//MetaMask connection
connectWalletftn()
//Creating the pair
cy.get(createPair).contains("Create a pair").click()
//selecting tokens
selectTokensPoolftn("GRELF","USDt","Create a pair")
//entering values
//You are creating a pool card
createEnterValuesftn("You are creating a pool", "Create Pool & Supply", "GRELF", "USDt")
//Approve transaction
cy.confirmMetamaskTransaction()
cy.wait(10000);
//Notification
notificationftn("Added")
// //Successful card
// successfulCardftn(confirmSwapBtn, limitSuccessfulTransactionLink)

})

it('Details on Add liquidity card', () => {
//Connect to MetaMask from pool page
cy.visit('/dashboard')
cy.get(poolsSideMenu).click()
cy.get(standardSideMenu).click()
//MetaMask connection
connectWalletftn()
//Add Liquidity
cy.get(createPair).contains("Create a pair").click()
//selecting tokens
selectTokensPoolftn("PNG","USDt","Add Liquidity")
//Add liquidity card
cy.get(createAddTitle).contains("Add liquidity").should('be.visible')
pairDetailsCardftn()
})

it('You will receive card', () => {
//Connect to MetaMask from pool page
cy.visit('/dashboard')
cy.get(poolsSideMenu).click()
cy.get(standardSideMenu).click()
//MetaMask connection
connectWalletftn()
//Adding Liquidity
cy.get(createPair).contains("Create a pair").click()
//selecting tokens
selectTokensPoolftn("PNG","USDt","Add Liquidity")
//Add liquidity card
cy.get(createAddTitle).contains("Add liquidity").should('be.visible')
//entering values
//You will receive card
createEnterValuesftn("You will receive", "Confirm Supply", "PNG", "USDt")
//Approve transaction
cy.confirmMetamaskTransaction()
cy.wait(10000);
//Notification
notificationftn("Added")
// //Successful card
//successfulCardftn(confirmSwapBtn, limitSuccessfulTransactionLink)
})
})
40 changes: 25 additions & 15 deletions e2e/tests/e2e/specs/swap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ import { limitSellBuyTradeDetailsftn } from '../../../cypress/src/swap'
import { limitOrdersftn } from '../../../cypress/src/swap'
import { cancelLimitOrderftn } from '../../../cypress/src/swap'

let { swapSideMenu, testnetBtn, walletAddress, nativeTokenLogo} = selectors.dashboard
let { tokensToSwap, selectTokens, selectTokensValue, selectTokensMenuClose, fromInput, toInput, swapBtn, percentBtns, percentBtnActive, confirmSwapDetails, confirmSwapBtn, swappingMsg, recentTransactions, transactionLinks, clearAll, transactionAppear, accountMenuCloseSwap, transactionRejected, selectTokenBtn, priceField, tokenBalances, buyBtn, swapSuccessfulTransactionLink, limitSuccessfulTransactionLink, cancelOrderbtn, cancelOrderMsg, executionPrice, cancelOrderBtnPopup, cancellingOrderMsg, cancelLimitSuccessfulTransactionLink} = selectors.swap
let { swapSideMenu, testnetBtn, walletAddress, nativeTokenLogo, connectToWallet, connectToMetamask, connectWallet,connected, tokenSearch} = selectors.dashboard
let { tokensToSwap, selectTokens, selectTokensValue, selectTokensMenuClose, fromInput, toInput, swapBtn, percentBtns, percentBtnActive, confirmSwapDetails, confirmSwapBtn, swappingMsg, recentTransactions, transactionLinks, clearAll, transactionAppear, accountMenuCloseSwap, transactionRejected, selectTokenBtn, priceField, tokenBalances, buyBtn, swapSuccessfulTransactionLink, limitSuccessfulTransactionLink, cancelLimitSuccessfulTransactionLink} = selectors.swap
let { percentBtnArr, swapTokensArr} = data.swap

//To run each file
//npx env-cmd -f .env npx synpress run --spec 'tests/e2e/specs/swap.spec.js' -cf synpress.json
describe('Swap', () => {
it('Connects with Metamask', () => {
//Connect to MetaMask from swap page
cy.visit('/dashboard')
cy.get(swapSideMenu).click()
connectWalletftn()
//After switching, the Network name (Avalanche), native token (PNG) and the gas token (AVAX) in the menu will change to the chain specific ones
//MetaMask connection
cy.get(connectToWallet).click();
cy.get(connectToMetamask).contains("Metamask").click();
cy.get(connectWallet).click()
cy.switchToMetamaskWindow();
cy.acceptMetamaskAccess().should("be.true");
cy.switchToCypressWindow();
cy.get(connected).should("not.be.empty");
//After connecting, the Network name (Avalanche), native token (PNG) and the gas token (AVAX) in the menu will change to the chain specific ones
nativeDetails(0)
})

Expand Down Expand Up @@ -156,18 +164,17 @@ describe('Swap', () => {
cy.get(accountMenuCloseSwap).click()
})

it.skip('Details on Limit Sell card', () => {
it('Details on Limit Sell card', () => {
cy.visit('/dashboard')
cy.get(swapSideMenu).click()
connectWalletftn()
cy.get(testnetBtn).contains("LIMIT").click()
cy.get(tokensToSwap).click()
cy.wait(20000);
cy.get(tokenSearch).eq(0).type("PNG")
cy.get(selectTokens).contains("PNG").click()
cy.wait(5000);
cy.get(selectTokenBtn).contains("Select Token").click()
cy.get(tokenSearch).eq(0).type("USDC")
cy.get(selectTokens).contains("USDC").click()
cy.wait(5000);
cy.get(fromInput).type('0.001')
cy.wait(5000);
cy.get(priceField).should('not.have.value', '0.00');
Expand All @@ -181,15 +188,16 @@ describe('Swap', () => {
limitSellBuyTokenftn(0, 1);
})

it.skip('Sell token Confirm card', () => {
it('Sell token Confirm card', () => {
cy.visit('/dashboard')
cy.get(swapSideMenu).click()
connectWalletftn()
cy.get(testnetBtn).contains("LIMIT").click()
cy.get(tokensToSwap).click()
cy.wait(20000);
cy.get(tokenSearch).eq(0).type("PNG")
cy.get(selectTokens).contains("PNG").click()
cy.get(selectTokenBtn).contains("Select Token").click()
cy.get(tokenSearch).eq(0).type("USDC")
cy.get(selectTokens).contains("USDC").click()
cy.get(fromInput).type('0.001')
cy.wait(5000);
Expand All @@ -212,16 +220,17 @@ describe('Swap', () => {
successfulCardftn(confirmSwapBtn, limitSuccessfulTransactionLink)
})

it.skip('Details on Limit Buy card', () => {
it('Details on Limit Buy card', () => {
cy.visit('/dashboard')
cy.get(swapSideMenu).click()
connectWalletftn()
cy.get(testnetBtn).contains("LIMIT").click()
cy.get(buyBtn).contains("BUY").click()
cy.get(tokensToSwap).click()
cy.wait(20000);
cy.get(tokenSearch).eq(0).type("PNG")
cy.get(selectTokens).contains("PNG").click()
cy.get(selectTokenBtn).contains("Select Token").click()
cy.get(tokenSearch).eq(0).type("USDC")
cy.get(selectTokens).contains("USDC").click()
cy.get(fromInput).type('5')
cy.wait(5000);
Expand All @@ -236,16 +245,17 @@ describe('Swap', () => {
limitSellBuyTokenftn(1, 0);
})

it.skip('Buy token Confirm card', () => {
it('Buy token Confirm card', () => {
cy.visit('/dashboard')
cy.get(swapSideMenu).click()
connectWalletftn()
cy.get(testnetBtn).contains("LIMIT").click()
cy.get(buyBtn).contains("BUY").click()
cy.get(tokensToSwap).click()
cy.wait(20000);
cy.get(tokenSearch).eq(0).type("PNG")
cy.get(selectTokens).contains("PNG").click()
cy.get(selectTokenBtn).contains("Select Token").click()
cy.get(tokenSearch).eq(0).type("USDC")
cy.get(selectTokens).contains("USDC").click()
cy.get(fromInput).type('5')
cy.wait(5000);
Expand Down

1 comment on commit 844c9f0

@taimuraamer
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test run results for pool
Reference:
Screenshot_3

Please sign in to comment.