aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorThomas <tmashuang@gmail.com>2018-03-22 03:25:41 +0800
committerThomas <tmashuang@gmail.com>2018-03-22 03:25:41 +0800
commitd646f377416ea6bfcd7682d21e011be5fa65cd3f (patch)
treedd5a1116920bc73738dcc1fefcc649927230a369 /test
parent6306c7b1901fa831e25ddd29607618122f805749 (diff)
parent072dd7ea2f7ce189b551b9fc8fd8e58aaaec4158 (diff)
downloadtangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.gz
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.bz2
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.lz
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.xz
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.zst
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.zip
Merge branch 'master' into selenium-e2e
Diffstat (limited to 'test')
-rw-r--r--test/integration/lib/send-new-ui.js18
-rw-r--r--test/lib/react-trigger-change.js161
-rw-r--r--test/unit/components/binary-renderer-test.js2
-rw-r--r--test/unit/components/bn-as-decimal-input-test.js2
-rw-r--r--test/unit/nameForAccount_test.js2
-rw-r--r--test/unit/tx-controller-test.js45
6 files changed, 217 insertions, 13 deletions
diff --git a/test/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js
index faab10fdf..3fc7c79f8 100644
--- a/test/integration/lib/send-new-ui.js
+++ b/test/integration/lib/send-new-ui.js
@@ -1,4 +1,4 @@
-const reactTriggerChange = require('react-trigger-change')
+const reactTriggerChange = require('../../lib/react-trigger-change')
const {
timeout,
queryAsync,
@@ -93,7 +93,7 @@ async function runSendFlowTest(assert, done) {
'send gas field should show estimated gas total converted to USD'
)
- const sendGasOpenCustomizeModalButton = await queryAsync($, '.send-v2__sliders-icon-container')
+ const sendGasOpenCustomizeModalButton = await queryAsync($, '.sliders-icon-container')
sendGasOpenCustomizeModalButton[0].click()
const customizeGasModal = await queryAsync($, '.send-v2__customize-gas')
@@ -128,19 +128,19 @@ async function runSendFlowTest(assert, done) {
selectState.val('send edit')
reactTriggerChange(selectState[0])
- const confirmFromName = (await queryAsync($, '.confirm-screen-account-name')).first()
+ const confirmFromName = (await queryAsync($, '.sender-to-recipient__sender-name')).first()
assert.equal(confirmFromName[0].textContent, 'Send Account 2', 'confirm screen should show correct from name')
- const confirmToName = (await queryAsync($, '.confirm-screen-account-name')).last()
+ const confirmToName = (await queryAsync($, '.sender-to-recipient__recipient-name')).last()
assert.equal(confirmToName[0].textContent, 'Send Account 3', 'confirm screen should show correct to name')
const confirmScreenRows = await queryAsync($, '.confirm-screen-rows')
- const confirmScreenGas = confirmScreenRows.find('.confirm-screen-row-info')[2]
- assert.equal(confirmScreenGas.textContent, '3.6 USD', 'confirm screen should show correct gas')
- const confirmScreenTotal = confirmScreenRows.find('.confirm-screen-row-info')[3]
+ const confirmScreenGas = confirmScreenRows.find('.currency-display__converted-value')[0]
+ assert.equal(confirmScreenGas.textContent, '3.60 USD', 'confirm screen should show correct gas')
+ const confirmScreenTotal = confirmScreenRows.find('.confirm-screen-row-info')[2]
assert.equal(confirmScreenTotal.textContent, '2405.36 USD', 'confirm screen should show correct total')
- const confirmScreenBackButton = await queryAsync($, '.confirm-screen-back-button')
+ const confirmScreenBackButton = await queryAsync($, '.page-container__back-button')
confirmScreenBackButton[0].click()
const sendFromFieldItemInEdit = await queryAsync($, '.account-list-item')
@@ -167,7 +167,7 @@ async function runSendFlowTest(assert, done) {
// TODO: Need a way to mock background so that we can test correct transition from editing to confirm
selectState.val('confirm new ui')
reactTriggerChange(selectState[0])
- const confirmScreenConfirmButton = await queryAsync($, '.confirm-screen-confirm-button')
+ const confirmScreenConfirmButton = await queryAsync($, '.btn-confirm.page-container__footer-button')
console.log(`+++++++++++++++++++++++++++++++= confirmScreenConfirmButton[0]`, confirmScreenConfirmButton[0]);
confirmScreenConfirmButton[0].click()
diff --git a/test/lib/react-trigger-change.js b/test/lib/react-trigger-change.js
new file mode 100644
index 000000000..a25ddff00
--- /dev/null
+++ b/test/lib/react-trigger-change.js
@@ -0,0 +1,161 @@
+// Trigger React's synthetic change events on input, textarea and select elements
+// https://github.com/vitalyq/react-trigger-change
+
+/******************IMPORTANT NOTE******************/
+/* This file is a modification of the */
+/* 'react-trigger-change' library linked above. */
+/* That library breaks when 'onFocus' events are */
+/* added to components under test because it */
+/* dispatches focus events to ensure changes are */
+/* triggered in some versions of IE. */
+/* This modification removes the accomodations */
+/* 'react-trigger-change' makes for IE to ensure */
+/* our tests can pass in chrome and firefox. */
+/**************************************************/
+
+'use strict';
+
+// Constants and functions are declared inside the closure.
+// In this way, reactTriggerChange can be passed directly to executeScript in Selenium.
+module.exports = function reactTriggerChange(node) {
+ var supportedInputTypes = {
+ color: true,
+ date: true,
+ datetime: true,
+ 'datetime-local': true,
+ email: true,
+ month: true,
+ number: true,
+ password: true,
+ range: true,
+ search: true,
+ tel: true,
+ text: true,
+ time: true,
+ url: true,
+ week: true
+ };
+ var nodeName = node.nodeName.toLowerCase();
+ var type = node.type;
+ var event;
+ var descriptor;
+ var initialValue;
+ var initialChecked;
+ var initialCheckedRadio;
+
+ // Do not try to delete non-configurable properties.
+ // Value and checked properties on DOM elements are non-configurable in PhantomJS.
+ function deletePropertySafe(elem, prop) {
+ var desc = Object.getOwnPropertyDescriptor(elem, prop);
+ if (desc && desc.configurable) {
+ delete elem[prop];
+ }
+ }
+
+ function getCheckedRadio(radio) {
+ var name = radio.name;
+ var radios;
+ var i;
+ if (name) {
+ radios = document.querySelectorAll('input[type="radio"][name="' + name + '"]');
+ for (i = 0; i < radios.length; i += 1) {
+ if (radios[i].checked) {
+ return radios[i] !== radio ? radios[i] : null;
+ }
+ }
+ }
+ return null;
+ }
+
+ function preventChecking(e) {
+ e.preventDefault();
+ if (!initialChecked) {
+ e.target.checked = false;
+ }
+ if (initialCheckedRadio) {
+ initialCheckedRadio.checked = true;
+ }
+ }
+
+ if (nodeName === 'select' ||
+ (nodeName === 'input' && type === 'file')) {
+ // IE9-IE11, non-IE
+ // Dispatch change.
+ event = document.createEvent('HTMLEvents');
+ event.initEvent('change', true, false);
+ node.dispatchEvent(event);
+ } else if ((nodeName === 'input' && supportedInputTypes[type]) ||
+ nodeName === 'textarea') {
+ // React 16
+ // Cache artificial value property descriptor.
+ // Property doesn't exist in React <16, descriptor is undefined.
+ descriptor = Object.getOwnPropertyDescriptor(node, 'value');
+
+ // Update inputValueTracking cached value.
+ // Remove artificial value property.
+ // Restore initial value to trigger event with it.
+ initialValue = node.value;
+ node.value = initialValue + '#';
+ deletePropertySafe(node, 'value');
+ node.value = initialValue;
+
+ // React 0.14: IE10-IE11, non-IE
+ // React 15: non-IE
+ // React 16: IE10-IE11, non-IE
+ event = document.createEvent('HTMLEvents');
+ event.initEvent('input', true, false);
+ node.dispatchEvent(event);
+
+ // React 16
+ // Restore artificial value property descriptor.
+ if (descriptor) {
+ Object.defineProperty(node, 'value', descriptor);
+ }
+ } else if (nodeName === 'input' && type === 'checkbox') {
+ // Invert inputValueTracking cached value.
+ node.checked = !node.checked;
+
+ // Dispatch click.
+ // Click event inverts checked value.
+ event = document.createEvent('MouseEvents');
+ event.initEvent('click', true, true);
+ node.dispatchEvent(event);
+ } else if (nodeName === 'input' && type === 'radio') {
+ // Cache initial checked value.
+ initialChecked = node.checked;
+
+ // Find and cache initially checked radio in the group.
+ initialCheckedRadio = getCheckedRadio(node);
+
+ // React 16
+ // Cache property descriptor.
+ // Invert inputValueTracking cached value.
+ // Remove artificial checked property.
+ // Restore initial value, otherwise preventDefault will eventually revert the value.
+ descriptor = Object.getOwnPropertyDescriptor(node, 'checked');
+ node.checked = !initialChecked;
+ deletePropertySafe(node, 'checked');
+ node.checked = initialChecked;
+
+ // Prevent toggling during event capturing phase.
+ // Set checked value to false if initialChecked is false,
+ // otherwise next listeners will see true.
+ // Restore initially checked radio in the group.
+ node.addEventListener('click', preventChecking, true);
+
+ // Dispatch click.
+ // Click event inverts checked value.
+ event = document.createEvent('MouseEvents');
+ event.initEvent('click', true, true);
+ node.dispatchEvent(event);
+
+ // Remove listener to stop further change prevention.
+ node.removeEventListener('click', preventChecking, true);
+
+ // React 16
+ // Restore artificial checked property descriptor.
+ if (descriptor) {
+ Object.defineProperty(node, 'checked', descriptor);
+ }
+ }
+};
diff --git a/test/unit/components/binary-renderer-test.js b/test/unit/components/binary-renderer-test.js
index ee2fa8b60..7bf9250cc 100644
--- a/test/unit/components/binary-renderer-test.js
+++ b/test/unit/components/binary-renderer-test.js
@@ -1,5 +1,5 @@
var assert = require('assert')
-var BinaryRenderer = require('../../../ui/app/components/binary-renderer')
+var BinaryRenderer = require('../../../old-ui/app/components/binary-renderer')
describe('BinaryRenderer', function () {
let binaryRenderer
diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js
index 58ecc9c89..7b9d9814f 100644
--- a/test/unit/components/bn-as-decimal-input-test.js
+++ b/test/unit/components/bn-as-decimal-input-test.js
@@ -6,7 +6,7 @@ const ReactTestUtils = require('react-addons-test-utils')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
-var BnInput = require('../../../ui/app/components/bn-as-decimal-input')
+var BnInput = require('../../../old-ui/app/components/bn-as-decimal-input')
describe('BnInput', function () {
it('can tolerate a gas decimal number at a high precision', function (done) {
diff --git a/test/unit/nameForAccount_test.js b/test/unit/nameForAccount_test.js
index e7c0b18b4..32af49e9d 100644
--- a/test/unit/nameForAccount_test.js
+++ b/test/unit/nameForAccount_test.js
@@ -2,7 +2,7 @@ var assert = require('assert')
var sinon = require('sinon')
var path = require('path')
-var contractNamer = require(path.join(__dirname, '..', '..', 'ui', 'lib', 'contract-namer.js'))
+var contractNamer = require(path.join(__dirname, '..', '..', 'old-ui', 'lib', 'contract-namer.js'))
describe('contractNamer', function () {
beforeEach(function () {
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index cc99afee4..712097fce 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -392,6 +392,49 @@ describe('Transaction Controller', function () {
})
})
+ describe('#retryTransaction', function () {
+ it('should create a new txMeta with the same txParams as the original one', function (done) {
+ let txParams = {
+ nonce: '0x00',
+ from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
+ to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
+ data: '0x0',
+ }
+ txController.txStateManager._saveTxList([
+ { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams },
+ ])
+ txController.retryTransaction(1)
+ .then((txMeta) => {
+ assert.equal(txMeta.txParams.nonce, txParams.nonce, 'nonce should be the same')
+ assert.equal(txMeta.txParams.from, txParams.from, 'from should be the same')
+ assert.equal(txMeta.txParams.to, txParams.to, 'to should be the same')
+ assert.equal(txMeta.txParams.data, txParams.data, 'data should be the same')
+ assert.ok(('lastGasPrice' in txMeta), 'should have the key `lastGasPrice`')
+ assert.equal(txController.txStateManager.getTxList().length, 2)
+ done()
+ }).catch(done)
+ })
+ })
+
+ describe('#_markNonceDuplicatesDropped', function () {
+ it('should mark all nonce duplicates as dropped without marking the confirmed transaction as dropped', function () {
+ txController.txStateManager._saveTxList([
+ { id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 4, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 6, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ ])
+ txController._markNonceDuplicatesDropped(1)
+ const confirmedTx = txController.txStateManager.getTx(1)
+ const droppedTxs = txController.txStateManager.getFilteredTxList({ nonce: '0x01', status: 'dropped' })
+ assert.equal(confirmedTx.status, 'confirmed', 'the confirmedTx should remain confirmed')
+ assert.equal(droppedTxs.length, 6, 'their should be 6 dropped txs')
+
+ })
+ })
describe('#getPendingTransactions', function () {
beforeEach(function () {
@@ -401,7 +444,7 @@ describe('Transaction Controller', function () {
{ id: 3, status: 'approved', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 4, status: 'signed', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} },
- { id: 6, status: 'confimed', metamaskNetworkId: currentNetworkId, txParams: {} },
+ { id: 6, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 7, status: 'failed', metamaskNetworkId: currentNetworkId, txParams: {} },
])
})