Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix integration tests #141

Merged
merged 10 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
Empty file.
3 changes: 1 addition & 2 deletions test/e2e/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
labelText: By.className('Would you like to add these tokens?'),
button: {
add: By.className('btn-primary'),
cancel: By.className('btn-default btn-violet'),
back: By.className('btn-default btn-violet'),
},
token: {
item: By.className('confirm-add-token__token-list-item'),
Expand Down Expand Up @@ -275,4 +275,3 @@ module.exports = {
CUSTOM: 'http://test.com',
},
}

94 changes: 53 additions & 41 deletions test/e2e/metamask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('Metamask popup page', async function () {
await delay(300)
const windowHandles = await driver.getAllWindowHandles()
await driver.switchTo().window(windowHandles[0])
await delay(5000)
})
})

Expand All @@ -71,7 +72,7 @@ describe('Metamask popup page', async function () {
})

it('screen \'Terms of Use\' has not empty agreement', async () => {
const terms = await waitUntilShowUp(screens.TOU.agreement)
const terms = await waitUntilShowUp(screens.TOU.agreement, 300)
const text = await terms.getText()
assert.equal(text.length > 400, true, 'agreement is too short')
})
Expand Down Expand Up @@ -707,7 +708,7 @@ describe('Metamask popup page', async function () {
assert.notEqual(buttonAdd, false, 'failed to open screen confirmation')
})

it('two selected tokens displayed and have correct parameters', async function () {
it('confirm screen: two selected tokens are displayed and have correct parameters', async function () {
const tokens = await driver.findElements(screens.addToken.search.confirm.token.item)
assert.equal(tokens.length, 2, 'incorrect number of tokens are presented')

Expand All @@ -724,28 +725,55 @@ describe('Metamask popup page', async function () {
assert.equal(balance1, '0', 'balance isn\'t 0')
})

it('button \'Cancel\' is enabled and leads to main screen ', async function () {
const button = await waitUntilShowUp(screens.addToken.search.button.cancel)
it('button \'Back\' is enabled and leads to previous screen ', async function () {
const button = await waitUntilShowUp(screens.addToken.search.confirm.button.back)
assert.equal(await button.isEnabled(), true, 'button isn\'t enabled')
await click(button)
const identicon = await waitUntilShowUp(screens.main.identicon)
assert.notEqual(identicon, false, 'main screen didn\'t opened')
const fieldSearch = await waitUntilShowUp(screens.addToken.search.fieldSearch)
assert.notEqual(fieldSearch, false, 'add token screen didn\'t opened')
})

it('button \'Next\' is enabled if confirmation list isn\'t empty', async function () {
const buttonAdd = await waitUntilShowUp(screens.main.tokens.buttonAdd)
await click(buttonAdd)
await waitUntilShowUp(screens.addToken.search.fieldSearch)
const button = await waitUntilShowUp(screens.addToken.search.button.next)
assert.equal(await button.isEnabled(), true, 'button is disabled')
})

it('previous selected tokens remain selected after new search', async function () {
const field = await waitUntilShowUp(screens.addToken.search.fieldSearch)
await clearField(field)
await field.sendKeys(request.valid)
await waitUntilShowUp(screens.addToken.search.token.selected)
const listSelected = await driver.findElements(screens.addToken.search.token.selected)
assert.equal(listSelected.length, 2, 'tokens are unselected')
})

it('user can unselect token', async function () {
const tokensUnselected = await driver.findElements(screens.addToken.search.token.unselected)
assert.notEqual(tokensUnselected.length, 0, 'all tokens are selected')

let tokensSelected = await driver.findElements(screens.addToken.search.token.selected)
await tokensSelected[0].click()
const old = tokensSelected.length

tokensSelected = await driver.findElements(screens.addToken.search.token.selected)
assert.equal(tokensSelected.length, old - 1, 'can\'t unselect token')
})

it('confirm screen: unselected token aren\'t displayed', async function () {
const button = await waitUntilShowUp(screens.addToken.search.button.next)
await click(button)
await waitUntilShowUp(screens.addToken.search.confirm.token.item)
const tokens = await driver.findElements(screens.addToken.search.confirm.token.item)
assert.equal(tokens.length, 1, 'incorrect number of tokens are presented')
const back = await waitUntilShowUp(screens.addToken.search.confirm.button.back)
await click(back)
})

it('Search by contract address: searching result list is empty if address invalid ', async function () {
const field = await waitUntilShowUp(screens.addToken.search.fieldSearch)
await field.sendKeys(request.notExistingAddress)
const list = await waitUntilShowUp(screens.addToken.search.token.unselected, 20)
assert.equal(list, false, 'unexpected tokens are displayed')

})

it('Search by valid contract address: searching result list contains one token ', async function () {
Expand All @@ -769,7 +797,7 @@ describe('Metamask popup page', async function () {
await click(button)
await waitUntilShowUp(screens.addToken.search.confirm.token.item)
const list = await driver.findElements(screens.addToken.search.confirm.token.item)
assert.equal(list.length, 3, 'token wasn\'t added')
assert.equal(list.length, 2, 'token wasn\'t added')
})

it('button \'Add tokens\' is enabled and clickable', async function () {
Expand All @@ -783,12 +811,12 @@ describe('Metamask popup page', async function () {
it('all selected tokens are displayed on main screen', async function () {
await waitUntilShowUp(screens.main.tokens.token)
const tokens = await driver.findElements(screens.main.tokens.token)
assert.equal(tokens.length, 3, 'tokens weren\'t added')
assert.equal(tokens.length, 2, 'tokens weren\'t added')
})

it('correct value of counter of owned tokens', async function () {
const counter = await waitUntilShowUp(screens.main.tokens.counter)
assert.equal(await counter.getText(), 'You own 3 tokens', 'incorrect value of counter')
assert.equal(await counter.getText(), 'You own 2 tokens', 'incorrect value of counter')

})

Expand Down Expand Up @@ -834,24 +862,15 @@ describe('Metamask popup page', async function () {
let button
let counter
let buttonYes
let tokensNumber

button = await waitUntilShowUp(screens.main.tokens.remove)
await button.click()
buttonYes = await waitUntilShowUp(screens.removeToken.buttons.yes)
await buttonYes.click()
counter = await waitUntilShowUp(screens.main.tokens.counter)
assert.equal(await counter.getText(), 'You own 2 tokens', 'incorrect value of counter')
tokensNumber = await driver.findElements(screens.main.tokens.token)
assert.equal(tokensNumber.length, 2, 'incorrect amount of token\'s is displayed')

button = await waitUntilShowUp(screens.main.tokens.remove)
await button.click()
buttonYes = await waitUntilShowUp(screens.removeToken.buttons.yes)
await buttonYes.click()
await delay(500)
counter = await waitUntilShowUp(screens.main.tokens.counter)
assert.equal(await counter.getText(), 'You own 1 token', 'incorrect value of counter')
tokensNumber = await driver.findElements(screens.main.tokens.token)
const tokensNumber = await driver.findElements(screens.main.tokens.token)
assert.equal(tokensNumber.length, 1, 'incorrect amount of token\'s is displayed')

button = await waitUntilShowUp(screens.main.tokens.remove)
Expand All @@ -863,12 +882,9 @@ describe('Metamask popup page', async function () {

assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})


})
})


describe('Add Token: Custom', function () {

describe('Token Factory', function () {
Expand Down Expand Up @@ -1015,13 +1031,6 @@ describe('Metamask popup page', async function () {
assert.notEqual(await tokenBalance.getText(), '')
})

it('adds token with the same address to MAINNET network', async function () {
await setProvider(NETWORKS.MAINNET)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
})

it('adds token with the same address to ROPSTEN network', async function () {
await setProvider(NETWORKS.ROPSTEN)
await addToken(tokenAddress, tokenName, tokenDecimals)
Expand All @@ -1043,6 +1052,13 @@ describe('Metamask popup page', async function () {
assert.notEqual(await tokenBalance.getText(), '')
})

it('adds token with the same address to MAINNET network', async function () {
await setProvider(NETWORKS.MAINNET)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
})

it('token still should be displayed in LOCALHOST network', async function () {
await setProvider(NETWORKS.LOCALHOST)
await waitUntilDisappear(screens.main.tokens.amount)
Expand Down Expand Up @@ -1363,10 +1379,9 @@ describe('Metamask popup page', async function () {
await waitUntilDisappear(elements.loader)
assert.notEqual(await waitUntilShowUp(screens.main.tokens.amount), false, 'App is frozen')
// Check tokens title
await waitUntilShowUp(screens.main.tokens.counter)
const tokensStatus = await driver.findElements(screens.main.tokens.counter)
assert.equal(tokensStatus.length, 1, '\'Tokens\' section doesn\'t contain field with amount of tokens')
assert.equal(await tokensStatus[0].getText(), screens.main.tokens.textNoTokens, 'Unexpected token presents')
const tokensCounter = await waitUntilShowUp(screens.main.tokens.counter)
assert.notEqual(tokensCounter, false, '\'Token\'s counter isn\'t displayed ')
assert.equal(await tokensCounter.getText(), screens.main.tokens.textNoTokens, 'Unexpected token presents')
// Check if token presents
const tokens = await driver.findElements(screens.main.tokens.token)
assert.equal(tokens.length, 0, 'Unexpected token presents')
Expand All @@ -1381,14 +1396,12 @@ describe('Metamask popup page', async function () {
try {
const button = await waitUntilShowUp(screens.main.tokens.buttonAdd, 300)
await click(button)

do {
const tab = await waitUntilShowUp(screens.addToken.tab.custom, 10)
try {
await tab.click()
} catch (err) {
}

}
while (await waitUntilShowUp(screens.addToken.custom.fields.contractAddress) === false)
const field = await waitUntilShowUp(screens.addToken.custom.fields.contractAddress)
Expand Down Expand Up @@ -1441,4 +1454,3 @@ describe('Metamask popup page', async function () {
await pify(fs.writeFile)(`${filepathBase}-dom.html`, htmlSource)
}
})

133 changes: 47 additions & 86 deletions test/integration/lib/add-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,108 +33,69 @@ async function runAddTokenFlowTest (assert, done) {
// Go to Add Token screen
let addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button')
assert.ok(addTokenButton[0], 'add token button present')
addTokenButton[0].click()
await addTokenButton[0].click()

// Verify Add Token screen
let addTokenWrapper = await queryAsync($, '.page-container')
assert.ok(addTokenWrapper[0], 'add token wrapper renders')

let addTokenTitle = await queryAsync($, '.page-container__title')
assert.equal(addTokenTitle[0].textContent, 'Add Tokens', 'add token title is correct')
let addTokenTitle = await queryAsync($, '.page-subtitle')
assert.equal(addTokenTitle[0].textContent, 'Add Token', 'add token title is correct')

// Cancel Add Token
const cancelAddTokenButton = await queryAsync($, 'button.btn-default.btn--large.page-container__footer-button')
const cancelAddTokenButton = await queryAsync($, 'button.btn-violet')
assert.ok(cancelAddTokenButton[0], 'cancel add token button present')
cancelAddTokenButton.click()

assert.ok($('.wallet-view')[0], 'cancelled and returned to account detail wallet view')
await cancelAddTokenButton.click()
assert.ok((await queryAsync($, '.identicon-wrapper'))[0], 'cancelled and returned to account detail wallet view')

// Return to Add Token Screen
addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button')
assert.ok(addTokenButton[0], 'add token button present')
addTokenButton[0].click()
await addTokenButton[0].click()

// Verify Add Token Screen
addTokenWrapper = await queryAsync($, '.page-container')
addTokenTitle = await queryAsync($, '.page-container__title')
assert.ok(addTokenWrapper[0], 'add token wrapper renders')
assert.equal(addTokenTitle[0].textContent, 'Add Tokens', 'add token title is correct')

// Search for token
const searchInput = (await findAsync(addTokenWrapper, '#search-tokens'))[0]
searchInput.focus()
await timeout(1000)
nativeInputValueSetter.call(searchInput, 'a')
searchInput.dispatchEvent(new Event('input', { bubbles: true}))

// Click token to add
const tokenWrapper = await queryAsync($, 'div.token-list__token')
assert.ok(tokenWrapper[0], 'token found')
const tokenImageProp = tokenWrapper.find('.token-list__token-icon').css('background-image')
const tokenImageUrl = tokenImageProp.slice(5, -2)
tokenWrapper[0].click()

// Click Next button
const nextButton = await queryAsync($, 'button.btn-primary.btn--large')
assert.equal(nextButton[0].textContent, 'Next', 'next button rendered')
nextButton[0].click()

// Confirm Add token
const confirmAddToken = await queryAsync($, '.confirm-add-token')
assert.ok(confirmAddToken[0], 'confirm add token rendered')
assert.ok($('button.btn-primary.btn--large')[0], 'confirm add token button found')
$('button.btn-primary.btn--large')[0].click()

// Verify added token image
let heroBalance = await queryAsync($, '.hero-balance')
assert.ok(heroBalance, 'rendered hero balance')
assert.ok(tokenImageUrl.indexOf(heroBalance.find('img').attr('src')) > -1, 'token added')

// Return to Add Token Screen
addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button')
assert.ok(addTokenButton[0], 'add token button present')
addTokenButton[0].click()

addTokenWrapper = await queryAsync($, '.page-container')
const addTokenTabs = await queryAsync($, '.page-container__tab')
assert.equal(addTokenTabs.length, 2, 'expected number of tabs')
assert.equal(addTokenTabs[1].textContent, 'Custom Token', 'Custom Token tab present')
assert.ok(addTokenTabs[1], 'add custom token tab present')
addTokenTabs[1].click()
await timeout(1000)
addTokenTitle = await queryAsync($, '.page-subtitle')
assert.equal(addTokenTitle[0].textContent, 'Add Token', 'add token title is correct')

// Input token contract address
const customInput = (await findAsync(addTokenWrapper, '#custom-address'))[0]
customInput.focus()
// Input invalid token contract address
const customAddress = (await findAsync($, '#token-address'))[0]
await customAddress.focus()
await timeout(1000)
nativeInputValueSetter.call(customInput, '0x177af043D3A1Aed7cc5f2397C70248Fc6cDC056c')
customInput.dispatchEvent(new Event('input', { bubbles: true}))

await nativeInputValueSetter.call(customAddress, 'invalid address')
await customAddress.dispatchEvent(new Event('input', { bubbles: true }))
const buttonAdd = await queryAsync($, '#app-content > div > div.app-primary.from-right > div > div.flex-column.flex-justify-center.flex-grow.select-none > div.flex-space-around > div:nth-child(7) > button:nth-child(2)')

// Click Next button
// nextButton = await queryAsync($, 'button.btn-primary--lg')
// assert.equal(nextButton[0].textContent, 'Next', 'next button rendered')
// nextButton[0].click()
assert.ok(buttonAdd[0], 'add button rendered')
await buttonAdd[0].click()

// // Verify symbol length error since contract address won't return symbol
const errorMessage = await queryAsync($, '#custom-symbol-helper-text')
// Verify contract error since contract address is invalid
const errorMessage = await queryAsync($, '.error')
assert.ok(errorMessage[0], 'error rendered')

$('button.btn-default.btn--large')[0].click()
// Input valid token contract address
await nativeInputValueSetter.call(customAddress, '0x177af043D3A1Aed7cc5f2397C70248Fc6cDC056c')
await customAddress.dispatchEvent(new Event('input', { bubbles: true }))

// await timeout(100000)

// Confirm Add token
// assert.equal(
// $('.page-container__subtitle')[0].textContent,
// 'Would you like to add these tokens?',
// 'confirm add token rendered'
// )
// assert.ok($('button.btn-primary--lg')[0], 'confirm add token button found')
// $('button.btn-primary--lg')[0].click()

// Verify added token image
heroBalance = await queryAsync($, '.hero-balance')
assert.ok(heroBalance, 'rendered hero balance')
assert.ok(heroBalance.find('.identicon')[0], 'token added')
// Input token symbol with length more than 10
const customSymbol = (await findAsync($, '#token_symbol'))[0]
assert.ok(customSymbol, 'symbol field rendered')
/*
await customSymbol.focus()
await timeout(1000)
await nativeInputValueSetter.call(customSymbol, 'POAPOAPOA20')
await customSymbol.dispatchEvent(new Event('input', { bubbles: true }))
await buttonAdd[0].click()
// Verify symbol length error since length more than 10
errorMessage = await queryAsync($, '.error')[0]
assert.ok(errorMessage, 'error rendered')
*/
// Input valid token symbol
await nativeInputValueSetter.call(customSymbol, 'POA')
await customSymbol.dispatchEvent(new Event('input', { bubbles: true }))
// Input valid decimals
const customDecimals = (await findAsync($, '#token_decimals'))[0]
assert.ok(customDecimals, 'decimals field rendered')

// Click Add button
await buttonAdd[0].click()

// check if main screen
assert.ok((await queryAsync($, '.identicon-wrapper'))[0], 'returned to account detail wallet view')
}
Loading