Skip to content

Commit

Permalink
Merge pull request #50 from QuickSwap/test/tcs
Browse files Browse the repository at this point in the history
Test/tcs
  • Loading branch information
FriskyHamTitz authored Jan 26, 2022
2 parents b226121 + cf901b4 commit 62a1d70
Show file tree
Hide file tree
Showing 27 changed files with 1,326 additions and 1,339 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Unit Tests
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up node
uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run unit tests
run: yarn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

cypress/videos
cypress/screenshots
cypress/fixtures/example.json
26 changes: 26 additions & 0 deletions cypress/integration/add-liquidity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe('Add Liquidity', () => {
it('loads the two correct tokens', () => {
cy.visit('/pools?currency0=0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6&currency1=0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619')
cy.get('#add-liquidity-input-tokena .token-symbol-container').should('contain.text', 'WBTC')
cy.get('#add-liquidity-input-tokenb .token-symbol-container').should('contain.text', 'ETH')
})

it('does not crash if ETH is duplicated', () => {
cy.visit('/pools?currency0=0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619&currency1=0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619')
cy.get('#add-liquidity-input-tokena .token-symbol-container').should('not.contain.text', 'ETH')
cy.get('#add-liquidity-input-tokenb .token-symbol-container').should('contain.text', 'ETH')
})

it('token not in storage is loaded', () => {
cy.visit('/pools?currency0=0x64aFDF9e28946419E325d801Fb3053d8B8FFdC23&currency1=0x60bB3D364B765C497C8cE50AE0Ae3f0882c5bD05')
cy.get('#add-liquidity-input-tokena .token-symbol-container').should('contain.text', 'MEEB')
cy.get('#add-liquidity-input-tokenb .token-symbol-container').should('contain.text', 'IMX')
})

it('single token can be selected', () => {
cy.visit('/pools?currency0=0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6')
cy.get('#add-liquidity-input-tokena .token-symbol-container').should('contain.text', 'WBTC')
cy.visit('/pools?currency0=0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619')
cy.get('#add-liquidity-input-tokena .token-symbol-container').should('contain.text', 'ETH')
})
})
39 changes: 39 additions & 0 deletions cypress/integration/landing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { TEST_ADDRESS_NEVER_USE_SHORTENED } from '../support/commands'

describe('Landing Page', () => {
beforeEach(() => cy.visit('/'))
it('loads landing page', () => {
cy.get('#landing-page')
})


it('allows navigation to pool', () => {
cy.get('#pools-page-link').click()
cy.url().should('include', '/pools')
})

it('allows navigation to swap', () => {
cy.get('#swap-page-link').click()
cy.url().should('include', '/swap')
})

it('allows navigation to farm', () => {
cy.get('#farm-page-link').click()
cy.url().should('include', '/farm')
})

it('allows navigation to dragons lair', () => {
cy.get('#dragons-page-link').click()
cy.url().should('include', '/dragons')
})

it('allows navigation to analytics', () => {
cy.get('#analytics-page-link').click()
cy.url().should('include', '/analytics')
})

/**it('is connected', () => {
cy.get('#web3-status-connected').click()
cy.get('#web3-account-identifier-row').contains(TEST_ADDRESS_NEVER_USE_SHORTENED)
})*/
})
20 changes: 20 additions & 0 deletions cypress/integration/lists.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe('Lists', () => {
beforeEach(() => {
cy.visit('/swap')
})

it('defaults to uniswap list', () => {
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get('#currency-search-selected-list-name').should('contain', 'Uniswap')
})

it('change list', () => {
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get('#currency-search-change-list-button').click()
cy.get('#list-row-tokens-1inch-eth .select-button').click()
cy.get('#currency-search-selected-list-name').should('contain', '1inch')
cy.get('#currency-search-change-list-button').click()
cy.get('#list-row-tokens-uniswap-eth .select-button').click()
cy.get('#currency-search-selected-list-name').should('contain', 'Uniswap')
})
})
8 changes: 8 additions & 0 deletions cypress/integration/migrate-v1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe('Migrate V1 Liquidity', () => {
describe('Remove V1 liquidity', () => {
it('renders the correct page', () => {
cy.visit('/remove/v1/0x93bB63aFe1E0180d0eF100D774B473034fd60C36')
cy.get('#remove-v1-exchange').should('contain', 'MKR/ETH')
})
})
})
12 changes: 12 additions & 0 deletions cypress/integration/pool.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe('Pool', () => {
beforeEach(() => cy.visit('/pool'))
it('add liquidity links to /add/ETH', () => {
cy.get('#join-pool-button').click()
cy.url().should('contain', '/add/ETH')
})

it('import pool links to /import', () => {
cy.get('#import-pool-link').click()
cy.url().should('contain', '/find')
})
})
39 changes: 39 additions & 0 deletions cypress/integration/remove-liquidity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
describe('Remove Liquidity', () => {
it('redirects', () => {
cy.visit('/remove/0xc778417E063141139Fce010982780140Aa0cD5Ab-0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85')
cy.url().should(
'contain',
'/remove/0xc778417E063141139Fce010982780140Aa0cD5Ab/0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85'
)
})

it('eth remove', () => {
cy.visit('/remove/ETH/0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85')
cy.get('#remove-liquidity-tokena-symbol').should('contain.text', 'ETH')
cy.get('#remove-liquidity-tokenb-symbol').should('contain.text', 'MKR')
})

it('eth remove swap order', () => {
cy.visit('/remove/0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85/ETH')
cy.get('#remove-liquidity-tokena-symbol').should('contain.text', 'MKR')
cy.get('#remove-liquidity-tokenb-symbol').should('contain.text', 'ETH')
})

it('loads the two correct tokens', () => {
cy.visit('/remove/0xc778417E063141139Fce010982780140Aa0cD5Ab-0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85')
cy.get('#remove-liquidity-tokena-symbol').should('contain.text', 'WETH')
cy.get('#remove-liquidity-tokenb-symbol').should('contain.text', 'MKR')
})

it('does not crash if ETH is duplicated', () => {
cy.visit('/remove/0xc778417E063141139Fce010982780140Aa0cD5Ab-0xc778417E063141139Fce010982780140Aa0cD5Ab')
cy.get('#remove-liquidity-tokena-symbol').should('contain.text', 'WETH')
cy.get('#remove-liquidity-tokenb-symbol').should('contain.text', 'WETH')
})

it('token not in storage is loaded', () => {
cy.visit('/remove/0xb290b2f9f8f108d03ff2af3ac5c8de6de31cdf6d-0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85')
cy.get('#remove-liquidity-tokena-symbol').should('contain.text', 'SKL')
cy.get('#remove-liquidity-tokenb-symbol').should('contain.text', 'MKR')
})
})
11 changes: 11 additions & 0 deletions cypress/integration/send.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe('Send', () => {
it('should redirect', () => {
cy.visit('/send')
cy.url().should('include', '/swap')
})

it('should redirect with url params', () => {
cy.visit('/send?outputCurrency=ETH&recipient=bob.argent.xyz')
cy.url().should('contain', '/swap?outputCurrency=ETH&recipient=bob.argent.xyz')
})
})
75 changes: 75 additions & 0 deletions cypress/integration/swap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
describe('Swap', () => {
beforeEach(() => {
cy.visit('/swap')
})
it('can enter an amount into input', () => {
cy.get('#swap-currency-input .token-amount-input')
.type('0.001', { delay: 200 })
.should('have.value', '0.001')
})

it('zero swap amount', () => {
cy.get('#swap-currency-input .token-amount-input')
.type('0.0', { delay: 200 })
.should('have.value', '0.0')
})

it('invalid swap amount', () => {
cy.get('#swap-currency-input .token-amount-input')
.type('\\', { delay: 200 })
.should('have.value', '')
})

it('can enter an amount into output', () => {
cy.get('#swap-currency-output .token-amount-input')
.type('0.001', { delay: 200 })
.should('have.value', '0.001')
})

it('zero output amount', () => {
cy.get('#swap-currency-output .token-amount-input')
.type('0.0', { delay: 200 })
.should('have.value', '0.0')
})

it('can swap ETH for DAI', () => {
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').should('be.visible')
cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').click({ force: true })
cy.get('#swap-currency-input .token-amount-input').should('be.visible')
cy.get('#swap-currency-input .token-amount-input').type('0.001', { force: true, delay: 200 })
cy.get('#swap-currency-output .token-amount-input').should('not.equal', '')
cy.get('#swap-button').click()
cy.get('#confirm-swap-or-send').should('contain', 'Confirm Swap')
})

it('add a recipient does not exist unless in expert mode', () => {
cy.get('#add-recipient-button').should('not.exist')
})

describe('expert mode', () => {
beforeEach(() => {
cy.window().then(win => {
cy.stub(win, 'prompt').returns('confirm')
})
cy.get('#open-settings-dialog-button').click()
cy.get('#toggle-expert-mode-button').click()
cy.get('#confirm-expert-mode').click()
})

it('add a recipient is visible', () => {
cy.get('#add-recipient-button').should('be.visible')
})

it('add a recipient', () => {
cy.get('#add-recipient-button').click()
cy.get('#recipient').should('exist')
})

it('remove recipient', () => {
cy.get('#add-recipient-button').click()
cy.get('#remove-recipient-button').click()
cy.get('#recipient').should('not.exist')
})
})
})
17 changes: 17 additions & 0 deletions cypress/integration/token-warning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe('Warning', () => {
beforeEach(() => {
cy.visit('/swap?outputCurrency=0x0a40f26d74274b7f22b28556a27b35d97ce08e0a')
})

it('Check that warning is displayed', () => {
cy.get('.token-warning-container').should('be.visible')
})

it('Check that warning hides after button dismissal', () => {
cy.get('.token-dismiss-button').should('be.disabled')
cy.get('.understand-checkbox').click()
cy.get('.token-dismiss-button').should('not.be.disabled')
cy.get('.token-dismiss-button').click()
cy.get('.token-warning-container').should('not.be.visible')
})
})
10 changes: 10 additions & 0 deletions cypress/support/commands.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const TEST_ADDRESS_NEVER_USE: string

export const TEST_ADDRESS_NEVER_USE_SHORTENED: string

// declare namespace Cypress {
// // eslint-disable-next-line @typescript-eslint/class-name-casing
// interface cy {
// additionalCommands(): void
// }
// }
Loading

0 comments on commit 62a1d70

Please sign in to comment.