Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Display AccountCard name via IdentityName (#4235)
Browse files Browse the repository at this point in the history
* Display AccountCard name via IdentityName

* Pass name through (catches registry reverse display)
  • Loading branch information
jacogr authored Jan 23, 2017
1 parent f4149cc commit 183efe9
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 45 deletions.
21 changes: 9 additions & 12 deletions js/src/ui/AccountCard/accountCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ReactDOM from 'react-dom';
import keycode from 'keycode';

import IdentityIcon from '~/ui/IdentityIcon';
import IdentityName from '~/ui/IdentityName';
import Tags from '~/ui/Tags';

import { fromWei } from '~/api/util/wei';
Expand All @@ -41,12 +42,8 @@ export default class AccountCard extends Component {
render () {
const { account } = this.props;
const { copied } = this.state;

const { address, name, description, meta = {} } = account;

const displayName = (name && name.toUpperCase()) || address;
const { address, description, meta = {}, name } = account;
const { tags = [] } = meta;

const classes = [ styles.account ];

if (copied) {
Expand All @@ -65,12 +62,16 @@ export default class AccountCard extends Component {
<IdentityIcon address={ address } />
<div className={ styles.accountInfo }>
<div className={ styles.accountName }>
<span>{ displayName }</span>
<IdentityName
address={ address }
name={ name }
unknown
/>
</div>

{ this.renderTags(tags, address) }
{ this.renderDescription(description) }
{ this.renderAddress(displayName, address) }
{ this.renderAddress(address) }
{ this.renderBalance(address) }
</div>
</div>
Expand All @@ -89,11 +90,7 @@ export default class AccountCard extends Component {
);
}

renderAddress (name, address) {
if (name === address) {
return null;
}

renderAddress (address) {
return (
<div className={ styles.addressContainer }>
<span
Expand Down
104 changes: 104 additions & 0 deletions js/src/ui/AccountCard/accountCard.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { shallow } from 'enzyme';
import React from 'react';
import sinon from 'sinon';

import AccountCard from './';

const TEST_ADDRESS = '0x1234567890123456789012345678901234567890';
const TEST_NAME = 'Jimmy';

let component;
let onClick;
let onFocus;

function render (props = {}) {
if (!props.account) {
props.account = {
address: TEST_ADDRESS,
description: 'testDescription',
name: TEST_NAME,
meta: {}
};
}

onClick = sinon.stub();
onFocus = sinon.stub();

component = shallow(
<AccountCard
{ ...props }
onClick={ onClick }
onFocus={ onFocus }
/>
);

return component;
}

describe('ui/AccountCard', () => {
beforeEach(() => {
render();
});

it('renders defaults', () => {
expect(component).to.be.ok;
});

describe('components', () => {
describe('IdentityIcon', () => {
let icon;

beforeEach(() => {
icon = component.find('Connect(IdentityIcon)');
});

it('renders the icon', () => {
expect(icon.length).to.equal(1);
});

it('passes the address through', () => {
expect(icon.props().address).to.equal(TEST_ADDRESS);
});
});

describe('IdentityName', () => {
let name;

beforeEach(() => {
name = component.find('Connect(IdentityName)');
});

it('renders the name', () => {
expect(name.length).to.equal(1);
});

it('passes the address through', () => {
expect(name.props().address).to.equal(TEST_ADDRESS);
});

it('passes the name through', () => {
expect(name.props().name).to.equal(TEST_NAME);
});

it('renders unknown (no name)', () => {
expect(name.props().unknown).to.be.true;
});
});
});
});
77 changes: 44 additions & 33 deletions js/src/ui/IdentityName/identityName.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ADDR_A = '0x123456789abcdef0123456789A';
const ADDR_B = '0x123456789abcdef0123456789B';
const ADDR_C = '0x123456789abcdef0123456789C';
const ADDR_NULL = '0x0000000000000000000000000000000000000000';
const NAME_JIMMY = 'Jimmy Test';
const STORE = {
dispatch: sinon.stub(),
subscribe: sinon.stub(),
Expand Down Expand Up @@ -53,41 +54,51 @@ function render (props) {
}

describe('ui/IdentityName', () => {
describe('rendering', () => {
it('renders defaults', () => {
expect(render({ address: ADDR_A })).to.be.ok;
it('renders defaults', () => {
expect(render({ address: ADDR_A })).to.be.ok;
});

describe('account not found', () => {
it('renders null with empty', () => {
expect(
render({ address: ADDR_C, empty: true }).html()
).to.be.null;
});

it('renders address without empty', () => {
expect(
render({ address: ADDR_C }).text()
).to.equal(ADDR_C);
});

it('renders short address with shorten', () => {
expect(
render({ address: ADDR_C, shorten: true }).find('ShortenedHash').props().data
).to.equal(ADDR_C);
});

it('renders unknown with flag', () => {
expect(
render({ address: ADDR_C, unknown: true }).find('FormattedMessage').props().id
).to.equal('ui.identityName.unnamed');
});

it('renders name when not found and passed', () => {
expect(
render({ address: ADDR_C, name: NAME_JIMMY }).text()
).to.equal(NAME_JIMMY.toUpperCase());
});

it('renders name when not found, unknown and passed', () => {
expect(
render({ address: ADDR_C, name: NAME_JIMMY, unknown: true }).text()
).to.equal(NAME_JIMMY.toUpperCase());
});

describe('account not found', () => {
it('renders null with empty', () => {
expect(
render({ address: ADDR_C, empty: true }).html()
).to.be.null;
});

it('renders address without empty', () => {
expect(
render({ address: ADDR_C }).text()
).to.equal(ADDR_C);
});

it('renders short address with shorten', () => {
expect(
render({ address: ADDR_C, shorten: true }).find('ShortenedHash').props().data
).to.equal(ADDR_C);
});

it('renders unknown with flag', () => {
expect(
render({ address: ADDR_C, unknown: true }
).find('FormattedMessage').props().id).to.equal('ui.identityName.unnamed');
});

it('renders 0x000...000 as null', () => {
expect(
render({ address: ADDR_NULL }).find('FormattedMessage').props().id
).to.equal('ui.identityName.null');
});
it('renders 0x000...000 as null', () => {
expect(
render({ address: ADDR_NULL }).find('FormattedMessage').props().id
).to.equal('ui.identityName.null');
});
});
});

0 comments on commit 183efe9

Please sign in to comment.