2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import AccountDetailsModal from '../account-details-modal';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Account Details Modal', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
global.platform = { openTab: sinon.spy() };
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
hideModal: sinon.spy(),
|
|
|
|
setAccountLabel: sinon.spy(),
|
|
|
|
showExportPrivateKeyModal: sinon.spy(),
|
|
|
|
network: 'test',
|
|
|
|
rpcPrefs: {},
|
|
|
|
selectedIdentity: {
|
|
|
|
address: '0xAddress',
|
|
|
|
name: 'Account 1',
|
|
|
|
},
|
|
|
|
keyrings: [
|
|
|
|
{
|
|
|
|
type: 'HD Key Tree',
|
2020-11-03 00:41:28 +01:00
|
|
|
accounts: ['0xAddress'],
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
identities: {
|
|
|
|
'0xAddress': {
|
|
|
|
address: '0xAddress',
|
|
|
|
name: 'Account 1',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(<AccountDetailsModal.WrappedComponent {...props} />, {
|
|
|
|
context: {
|
|
|
|
t: (str) => str,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('sets account label when changing default account label', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const accountLabel = wrapper.find('.account-details-modal__name').first();
|
|
|
|
accountLabel.simulate('submit', 'New Label');
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(props.setAccountLabel.calledOnce);
|
|
|
|
assert.strictEqual(props.setAccountLabel.getCall(0).args[1], 'New Label');
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-04-16 23:34:40 +02:00
|
|
|
it('opens new tab when view block explorer is clicked', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const modalButton = wrapper.find('.account-details-modal__button');
|
|
|
|
const etherscanLink = modalButton.first();
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
etherscanLink.simulate('click');
|
|
|
|
assert(global.platform.openTab.calledOnce);
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('shows export private key modal when clicked', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const modalButton = wrapper.find('.account-details-modal__button');
|
|
|
|
const etherscanLink = modalButton.last();
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
etherscanLink.simulate('click');
|
|
|
|
assert(props.showExportPrivateKeyModal.calledOnce);
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('sets blockexplorerview text when block explorer url in rpcPrefs exists', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const blockExplorerUrl = 'https://block.explorer';
|
|
|
|
wrapper.setProps({ rpcPrefs: { blockExplorerUrl } });
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const modalButton = wrapper.find('.account-details-modal__button');
|
2021-02-22 17:20:42 +01:00
|
|
|
const blockExplorerLink = modalButton.first().shallow();
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-22 17:20:42 +01:00
|
|
|
assert.strictEqual(blockExplorerLink.text(), 'blockExplorerView');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|