Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into kyberai-ui-improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoYhun committed Aug 29, 2023
2 parents 49e1e76 + 489c5a9 commit e045e73
Show file tree
Hide file tree
Showing 32 changed files with 401 additions and 320 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ jobs:
REF_BRANCH=${REF/refs\/tags\//}
BRANCH=$REF_BRANCH
fi
echo "::set-output name=value::$BRANCH"
echo "value=$BRANCH" >> $GITHUB_OUTPUT
- name: Extract GitHub HEAD SHA
id: head_sha
run: echo "::set-output name=value::$(git rev-parse HEAD)"
run: echo "value=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: Get Docker image tag
id: get_tag
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
short_sha="$(echo $HEAD_SHA | head -c7)"
echo "::set-output name=image_tag::adpr-$short_sha"
echo "image_tag=adpr-$short_sha" >> $GITHUB_OUTPUT
cypress-test:
runs-on: ubuntu-latest
Expand All @@ -87,24 +87,24 @@ jobs:
sudo apt-get install --no-install-recommends -y \
fluxbox \
xvfb
- name: Yarn Build
env:
CI: false
VITE_TAG: ${{ needs.prepare.outputs.image_tag }}
CURRENT_BRANCH: ${{ needs.prepare.outputs.current_branch }}
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn build-adpr

- name: Install cypress
run: yarn cypress install --force
run: yarn cypress install --force

- name: Run xvfb and fluxbox
run: |
Xvfb :0 -screen 0 1024x768x24 -listen tcp -ac &
fluxbox &
env:
DISPLAY: :0.0
DISPLAY: :0.0

- name: Run Cypress Test
run: |+
Expand All @@ -113,13 +113,13 @@ jobs:
yarn test-e2e -e grepTags=smoke,NETWORK=Ethereum
env:
DISPLAY: :0.0
- name: Archive e2e artifacts

- name: Archive e2e artifacts
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
if: always()
with:
name: e2e-artifacts
path: |
cypress/videos
cypress/screenshots
continue-on-error: true
continue-on-error: true
14 changes: 7 additions & 7 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ jobs:
sudo apt-get install --no-install-recommends -y \
fluxbox \
xvfb
- name: Install cypress
run: yarn cypress install --force
run: yarn cypress install --force

- name: Run xvfb and fluxbox
run: Xvfb :0 -screen 0 1024x768x24 -listen tcp -ac &
fluxbox &
env:
DISPLAY: :0.0
DISPLAY: :0.0

- name: Run Cypress Test
run: |+
#!/bin/bash
yarn test-schedule -e grepTags=regression,NETWORK=${{ matrix.network }}
env:
DISPLAY: :0.0

- name: Notify on failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
Expand All @@ -61,8 +61,8 @@ jobs:
SLACK_TITLE: E2E Test ${{inputs.BASE_URL}}
SLACK_USERNAME: autoBot
SLACK_LINK_NAMES: true
- name: Archive e2e artifacts

- name: Archive e2e artifacts
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
if: always()
with:
Expand Down
6 changes: 3 additions & 3 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export default defineConfig({
viewportWidth: 1920,
viewportHeight: 1080,
env: {
grepFilterSpecs:true,
grepOmitFiltered:true
grepFilterSpecs: true,
grepOmitFiltered: true,
},
e2e: {
setupNodeEvents(on, config) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@cypress/grep/src/plugin')(config)
synpressPlugins(on, config)
},
specPattern: 'cypress/e2e/specs/*.e2e.cy.ts'
specPattern: 'cypress/e2e/specs/*.e2e.cy.ts',
},
})
46 changes: 46 additions & 0 deletions cypress/e2e/pages/farm-page.po.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FarmLocators, HeaderLocators } from "../selectors/selectors.cy"

export class FarmPage {

getTvlValues() {
const arr: string[] = []
const listData = cy.get(FarmLocators.lblTvl)
listData
.each(item => {
arr.push(item.text().split('$')[1])
})
return arr
}

getAprValues() {
const arr: string[] = []
const listData = cy.get(FarmLocators.lblApr)
listData
.each(item => {
arr.push(item.text().split('%')[0])
})
return arr
}

countInvalidFarms(arrApr: string[], arrTvl: string[]) {
const totalFarms = arrApr.length
let count = 0;
for (let i = 0; i < totalFarms; i++) {
if (((arrTvl[i]) === undefined || Number(arrTvl[i]) === 0) && Number(arrApr[i]) === 0) {
count = count + 1;
}
}
return count
}

checkExistData() {
return cy.get(FarmLocators.lblApr, {timeout: 5000}).should(() => { }).then($obj => {
if ($obj.length > 0) {
return true
}
else {
return false
}
})
}
}
21 changes: 18 additions & 3 deletions cypress/e2e/pages/swap-page.po.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkLocators, SwapPageLocators, TokenCatalogLocators, WalletLocators } from "../selectors/selectors.cy"
import { HeaderLocators, NetworkLocators, SwapPageLocators, TokenCatalogLocators, WalletLocators } from "../selectors/selectors.cy"

export interface myCallbackType<T> {
(myArgument: T): void
Expand Down Expand Up @@ -35,14 +35,29 @@ export const SwapPage = {

getStatusConnectedWallet() {
cy.get(WalletLocators.statusConnected, { timeout: 10000 }).should('be.visible')
}
},

goToFarmPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblFarms).click({ force: true })
},

goToPoolPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblPools).click({ force: true })
},

goToMyPoolsPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblMyPools).click({ force: true })
},
}

export class Network {
selectNetwork(network: string) {
cy.get(NetworkLocators.btnSelectNetwork, { timeout: 30000 }).should('be.visible').click()
cy.get(NetworkLocators.btnNetwork).contains(network).click({ force: true })
}
}
}

export class TokenCatalog {
Expand Down
5 changes: 5 additions & 0 deletions cypress/e2e/selectors/selectors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ export const HeaderLocators = {
lblMyPools: '[data-testid=my-pools-nav-link]',
lblFarms: '[data-testid=farms-nav-link]',
}

export const FarmLocators = {
lblApr: '[data-testid=apr-value]',
lblTvl: '[data-testid=tvl-value]',
}
24 changes: 24 additions & 0 deletions cypress/e2e/specs/farm-page.e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { FarmPage } from "../pages/farm-page.po.cy";
import { SwapPage } from "../pages/swap-page.po.cy"
import { DEFAULT_URL, TAG, } from "../selectors/constants.cy"
const farm = new FarmPage()

describe('Farm', { tags: TAG.regression }, () => {
beforeEach(() => {
SwapPage.open(DEFAULT_URL)
SwapPage.goToFarmPage()
farm.checkExistData().then((value) => {
if (value === true) {
cy.wrap(farm.getAprValues()).as('arrApr')
cy.wrap(farm.getTvlValues()).as('arrTvl')
}
cy.wrap(value).as('checkData')
})
})
it('Should be displayed APR and TVL values', function () {
if (this.checkData === true) {
const count = farm.countInvalidFarms(this.arrApr, this.arrTvl)
expect(count).not.to.equal(this.arrApr.length)
}
})
})
31 changes: 23 additions & 8 deletions cypress/e2e/specs/intercept.e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { SwapPage } from "../pages/swap-page.po.cy"
import { DEFAULT_URL, TAG, } from "../selectors/constants.cy"
import { FarmPage } from "../pages/farm-page.po.cy";
import { SwapPage, TokenCatalog } from "../pages/swap-page.po.cy"
import { DEFAULT_URL, TAG, } from "../selectors/constants.cy"
import { HeaderLocators } from "../selectors/selectors.cy"
const tokenCatalog = new TokenCatalog()
const farm = new FarmPage()

describe('Intercept', { tags: TAG.regression }, () => {
beforeEach(() => {
Expand All @@ -19,19 +22,32 @@ describe('Intercept', { tags: TAG.regression }, () => {
cy.intercept('GET', '**/farm-pools?**').as('get-farm-list')
cy.intercept('GET', '**/pools?**').as('get-pool-list')
cy.intercept('GET', '**/block?**').as('get-block')
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblPools).click({ force: true })
SwapPage.goToPoolPage()
cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
cy.wait('@get-block', { timeout: 60000 }).its('response.statusCode').should('equal', 200)
})

it('Should be displayed APR and TVL values', () => {
cy.intercept('GET', '**/pools?**').as('get-pools')
SwapPage.goToPoolPage()
cy.wait('@get-pools', { timeout: 20000 }).its('response.body.data').then(response => {
const totalPools = response.pools.length;
const count = response.pools.reduce((acc: number, pool: { totalValueLockedUsd: string; apr: string }) => {
if (pool.totalValueLockedUsd === '0' && pool.apr === '0') {
return acc + 1;
}
return acc;
}, 0);
expect(count).not.to.equal(totalPools);
})
})
})

describe('My Pools', () => {
it('Should get farm list successfully', () => {
cy.intercept('GET', '**/farm-pools?**').as('get-farm-list')
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblPools).click({ force: true })
SwapPage.goToMyPoolsPage()
cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
})
})
Expand All @@ -41,8 +57,7 @@ describe('Intercept', { tags: TAG.regression }, () => {
cy.intercept('GET', '**/farm-pools?**').as('get-farm-list')
cy.intercept('GET', '**/pools?**').as('get-pool-list')
cy.intercept('GET', '**/block?**').as('get-block')
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblFarms).click({ force: true })
SwapPage.goToFarmPage()
cy.get('[data-testid=farm-block]')
.should(_ => {})
.then($list => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@kybernetwork/oauth2": "1.0.0",
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "1.0.9",
"@kyberswap/ks-sdk-core": "1.0.10",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
"@kyberswap/ks-sdk-solana": "^1.0.2",
"@lingui/loader": "~3.14.0",
Expand Down Expand Up @@ -197,7 +197,7 @@
"vite-tsconfig-paths": "^4.0.8"
},
"resolutions": {
"@kyberswap/ks-sdk-core": "1.0.9",
"@kyberswap/ks-sdk-core": "1.0.10",
"react-error-overlay": "6.0.9",
"@lingui/babel-plugin-extract-messages": "3.14.0",
"@lingui/cli": "3.14.0",
Expand Down
Loading

0 comments on commit e045e73

Please sign in to comment.