2018-02-06 03:47:46 +01:00
|
|
|
const reactTriggerChange = require('react-trigger-change')
|
2018-03-11 22:52:29 +01:00
|
|
|
const {
|
|
|
|
timeout,
|
|
|
|
queryAsync,
|
|
|
|
findAsync,
|
|
|
|
} = require('../../lib/util')
|
2018-02-06 03:47:46 +01:00
|
|
|
|
|
|
|
QUnit.module('Add token flow')
|
|
|
|
|
|
|
|
QUnit.test('successful add token flow', (assert) => {
|
|
|
|
const done = assert.async()
|
|
|
|
runAddTokenFlowTest(assert)
|
|
|
|
.then(done)
|
|
|
|
.catch(err => {
|
|
|
|
assert.notOk(err, `Error was thrown: ${err.stack}`)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
async function runAddTokenFlowTest (assert, done) {
|
2018-03-11 22:52:29 +01:00
|
|
|
const selectState = await queryAsync($, 'select')
|
2018-02-06 03:47:46 +01:00
|
|
|
selectState.val('add token')
|
|
|
|
reactTriggerChange(selectState[0])
|
|
|
|
|
|
|
|
// Check that no tokens have been added
|
|
|
|
assert.ok($('.token-list-item').length === 0, 'no tokens added')
|
|
|
|
|
|
|
|
// Go to Add Token screen
|
2018-03-26 07:19:42 +02:00
|
|
|
let addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(addTokenButton[0], 'add token button present')
|
|
|
|
addTokenButton[0].click()
|
|
|
|
|
|
|
|
// Verify Add Token screen
|
2018-03-11 22:52:29 +01:00
|
|
|
let addTokenWrapper = await queryAsync($, '.add-token__wrapper')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(addTokenWrapper[0], 'add token wrapper renders')
|
|
|
|
|
2018-03-26 10:36:28 +02:00
|
|
|
let addTokenTitle = await queryAsync($, '.add-token__header__title')
|
|
|
|
assert.equal(addTokenTitle[0].textContent, 'Add Tokens', 'add token title is correct')
|
2018-02-06 03:47:46 +01:00
|
|
|
|
|
|
|
// Cancel Add Token
|
2018-03-26 07:19:42 +02:00
|
|
|
const cancelAddTokenButton = await queryAsync($, 'button.btn-secondary--lg.add-token__cancel-button')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(cancelAddTokenButton[0], 'cancel add token button present')
|
|
|
|
cancelAddTokenButton.click()
|
|
|
|
|
|
|
|
assert.ok($('.wallet-view')[0], 'cancelled and returned to account detail wallet view')
|
|
|
|
|
|
|
|
// Return to Add Token Screen
|
2018-03-26 07:19:42 +02:00
|
|
|
addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(addTokenButton[0], 'add token button present')
|
|
|
|
addTokenButton[0].click()
|
|
|
|
|
|
|
|
// Verify Add Token Screen
|
2018-03-11 22:52:29 +01:00
|
|
|
addTokenWrapper = await queryAsync($, '.add-token__wrapper')
|
2018-03-26 10:36:28 +02:00
|
|
|
addTokenTitle = await queryAsync($, '.add-token__header__title')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(addTokenWrapper[0], 'add token wrapper renders')
|
2018-03-26 10:36:28 +02:00
|
|
|
assert.equal(addTokenTitle[0].textContent, 'Add Tokens', 'add token title is correct')
|
2018-02-06 03:47:46 +01:00
|
|
|
|
|
|
|
// Search for token
|
2018-03-11 22:52:29 +01:00
|
|
|
const searchInput = await queryAsync($, 'input.add-token__input')
|
2018-02-06 03:47:46 +01:00
|
|
|
searchInput.val('a')
|
|
|
|
reactTriggerChange(searchInput[0])
|
|
|
|
|
|
|
|
// Click token to add
|
2018-03-11 22:52:29 +01:00
|
|
|
const tokenWrapper = await queryAsync($, 'div.add-token__token-wrapper')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(tokenWrapper[0], 'token found')
|
|
|
|
const tokenImageProp = tokenWrapper.find('.add-token__token-icon').css('background-image')
|
|
|
|
const tokenImageUrl = tokenImageProp.slice(5, -2)
|
|
|
|
tokenWrapper[0].click()
|
|
|
|
|
|
|
|
// Click Next button
|
2018-03-26 07:19:42 +02:00
|
|
|
let nextButton = await queryAsync($, 'button.btn-primary--lg')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.equal(nextButton[0].textContent, 'Next', 'next button rendered')
|
|
|
|
nextButton[0].click()
|
|
|
|
|
|
|
|
// Confirm Add token
|
|
|
|
assert.equal(
|
|
|
|
$('.add-token__description')[0].textContent,
|
|
|
|
'Would you like to add these tokens?',
|
|
|
|
'confirm add token rendered'
|
|
|
|
)
|
2018-03-26 07:19:42 +02:00
|
|
|
assert.ok($('button.btn-primary--lg')[0], 'confirm add token button found')
|
|
|
|
$('button.btn-primary--lg')[0].click()
|
2018-02-06 03:47:46 +01:00
|
|
|
|
|
|
|
// Verify added token image
|
2018-03-11 22:52:29 +01:00
|
|
|
let heroBalance = await queryAsync($, '.hero-balance')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(heroBalance, 'rendered hero balance')
|
|
|
|
assert.ok(tokenImageUrl.indexOf(heroBalance.find('img').attr('src')) > -1, 'token added')
|
|
|
|
|
|
|
|
// Return to Add Token Screen
|
2018-03-26 07:19:42 +02:00
|
|
|
addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(addTokenButton[0], 'add token button present')
|
|
|
|
addTokenButton[0].click()
|
|
|
|
|
2018-03-26 10:36:28 +02:00
|
|
|
const addTokenTabs = await queryAsync($, '.add-token__header__tabs__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()
|
2018-02-06 03:47:46 +01:00
|
|
|
|
|
|
|
// Input token contract address
|
2018-03-11 22:52:29 +01:00
|
|
|
const customInput = await queryAsync($, 'input.add-token__add-custom-input')
|
2018-02-06 03:47:46 +01:00
|
|
|
customInput.val('0x177af043D3A1Aed7cc5f2397C70248Fc6cDC056c')
|
|
|
|
reactTriggerChange(customInput[0])
|
|
|
|
|
|
|
|
// Click Next button
|
2018-03-26 07:19:42 +02:00
|
|
|
nextButton = await queryAsync($, 'button.btn-primary--lg')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.equal(nextButton[0].textContent, 'Next', 'next button rendered')
|
|
|
|
nextButton[0].click()
|
|
|
|
|
|
|
|
// Verify symbol length error since contract address won't return symbol
|
2018-03-11 22:52:29 +01:00
|
|
|
const errorMessage = await queryAsync($, '.add-token__add-custom-error-message')
|
2018-02-06 03:47:46 +01:00
|
|
|
assert.ok(errorMessage[0], 'error rendered')
|
2018-03-26 21:21:02 +02:00
|
|
|
|
2018-03-26 07:19:42 +02:00
|
|
|
$('button.btn-secondary--lg')[0].click()
|
2018-02-06 03:47:46 +01:00
|
|
|
|
|
|
|
// // Confirm Add token
|
|
|
|
// assert.equal(
|
|
|
|
// $('.add-token__description')[0].textContent,
|
|
|
|
// 'Would you like to add these tokens?',
|
|
|
|
// 'confirm add token rendered'
|
|
|
|
// )
|
2018-03-26 07:19:42 +02:00
|
|
|
// assert.ok($('button.btn-primary--lg')[0], 'confirm add token button found')
|
|
|
|
// $('button.btn-primary--lg')[0].click()
|
2018-02-06 03:47:46 +01:00
|
|
|
|
|
|
|
// // Verify added token image
|
2018-03-11 22:52:29 +01:00
|
|
|
// heroBalance = await queryAsync($, '.hero-balance')
|
2018-02-06 03:47:46 +01:00
|
|
|
// assert.ok(heroBalance, 'rendered hero balance')
|
|
|
|
// assert.ok(heroBalance.find('.identicon')[0], 'token added')
|
|
|
|
}
|