This repository was archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathcommands.js
65 lines (55 loc) · 2.04 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function _clickOnToken(inputOrOutput) {
cy.get(`#swap-currency-${inputOrOutput} .open-currency-select-button`).click()
}
function _selectTokenFromSelector(tokenAddress, inputOrOutput) {
cy.get('.token-item-' + tokenAddress).should('be.visible')
cy.get('.token-item-' + tokenAddress).click({ force: true })
cy.get(`#swap-currency-${inputOrOutput} .token-amount-input`).should('be.visible')
}
function _responseHandlerFactory(body) {
return (req) =>
req.reply((res) => {
const newBody = JSON.stringify(body || res.body)
res.body = newBody
})
}
function clickInputToken() {
_clickOnToken('input')
}
function clickOutputToken() {
_clickOnToken('output')
}
function selectOutput(tokenAddress) {
clickOutputToken()
_selectTokenFromSelector(tokenAddress, 'output')
}
function selectInput(tokenAddress) {
clickInputToken()
_selectTokenFromSelector(tokenAddress, 'input')
}
function enterInputAmount(tokenAddress, amount, selectToken = false) {
// Choose whether to also select token
// or just input amount
if (selectToken) {
selectOutput(tokenAddress)
}
cy.get('#swap-currency-input .token-amount-input').type(amount.toString(), { force: true, delay: 400 })
}
function enterOutputAmount(tokenAddress, amount, selectToken = false) {
// Choose whether to also select token
// or just input amount
if (selectToken) {
selectOutput(tokenAddress)
}
cy.get('#swap-currency-input .token-amount-output').type(amount.toString(), { force: true, delay: 400 })
}
function stubResponse({ url, alias = 'stubbedResponse', body }) {
cy.intercept({ method: 'GET', url }, _responseHandlerFactory(body)).as(alias)
}
Cypress.Commands.add('swapClickInputToken', () => clickInputToken)
Cypress.Commands.add('swapClickOutputToken', () => clickOutputToken)
Cypress.Commands.add('swapSelectInput', selectInput)
Cypress.Commands.add('swapSelectOutput', selectOutput)
Cypress.Commands.add('swapEnterInputAmount', enterInputAmount)
Cypress.Commands.add('swapEnterOutputAmount', enterOutputAmount)
Cypress.Commands.add('stubResponse', stubResponse)