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

DeleteAccount & LoadContract modal updates #4320

Merged
merged 2 commits into from
Jan 27, 2017
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
48 changes: 33 additions & 15 deletions js/src/modals/DeleteAccount/deleteAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

Expand Down Expand Up @@ -46,22 +47,33 @@ class DeleteAccount extends Component {
return (
<ConfirmDialog
className={ styles.body }
title='confirm removal'
visible
onDeny={ this.closeDeleteDialog }
onConfirm={ this.onDeleteConfirmed }
onDeny={ this.closeDeleteDialog }
title={
<FormattedMessage
id='deleteAccount.title'
defaultMessage='confirm removal'
/>
}
visible
>
<div className={ styles.hero }>
Are you sure you want to permanently delete the following account?
<FormattedMessage
id='deleteAccount.question'
defaultMessage='Are you sure you want to permanently delete the following account?'
/>
</div>
<div className={ styles.info }>
<IdentityIcon
className={ styles.icon }
address={ account.address }
className={ styles.icon }
/>
<div className={ styles.nameinfo }>
<div className={ styles.header }>
<IdentityName address={ account.address } unknown />
<IdentityName
address={ account.address }
unknown
/>
</div>
<div className={ styles.address }>
{ account.address }
Expand All @@ -73,11 +85,21 @@ class DeleteAccount extends Component {
</div>
<div className={ styles.password }>
<Input
label='account password'
hint='provide the account password to confirm the account deletion'
hint={
<FormattedMessage
id='deleteAccount.password.hint'
defaultMessage='provide the account password to confirm the account deletion'
/>
}
label={
<FormattedMessage
id='deleteAccount.password.label'
defaultMessage='account password'
/>
}
onChange={ this.onChangePassword }
type='password'
value={ password }
onChange={ this.onChangePassword }
/>
</div>
</ConfirmDialog>
Expand All @@ -93,7 +115,7 @@ class DeleteAccount extends Component {
const { account, newError } = this.props;
const { password } = this.state;

api.parity
return api.parity
.killAccount(account.address, password)
.then((result) => {
if (result === true) {
Expand All @@ -114,15 +136,11 @@ class DeleteAccount extends Component {
}
}

function mapStateToProps (state) {
return {};
}

function mapDispatchToProps (dispatch) {
return bindActionCreators({ newError }, dispatch);
}

export default connect(
mapStateToProps,
null,
mapDispatchToProps
)(DeleteAccount);
139 changes: 139 additions & 0 deletions js/src/modals/DeleteAccount/deleteAccount.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright 2015-2017 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 DeleteAccount from './';

let api;
let component;
let instance;
let onClose;
let router;
let store;

const TEST_ADDRESS = '0x123456789012345678901234567890';
const TEST_PASSWORD = 'testPassword';

function createApi () {
api = {
parity: {
killAccount: sinon.stub().resolves(true)
}
};

return api;
}

function createRouter () {
router = {
push: sinon.stub()
};

return router;
}

function createStore () {
store = {
dispatch: sinon.stub(),
subscribe: sinon.stub(),
getState: () => {
return {};
}
};

return store;
}

function render () {
onClose = sinon.stub();
component = shallow(
<DeleteAccount
account={ {
address: TEST_ADDRESS,
meta: {
description: 'testDescription'
}
} }
onClose={ onClose }
/>,
{
context: {
store: createStore()
}
}
).find('DeleteAccount').shallow({
context: {
api: createApi(),
router: createRouter()
}
});
instance = component.instance();

return component;
}

describe('modals/DeleteAccount', () => {
beforeEach(() => {
render();
});

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

describe('event handlers', () => {
describe('onChangePassword', () => {
it('sets the state with the new password', () => {
instance.onChangePassword(null, TEST_PASSWORD);
expect(instance.state.password).to.equal(TEST_PASSWORD);
});
});

describe('closeDeleteDialog', () => {
it('calls onClose', () => {
instance.closeDeleteDialog();
expect(onClose).to.have.been.called;
});
});

describe('onDeleteConfirmed', () => {
beforeEach(() => {
sinon.spy(instance, 'closeDeleteDialog');
instance.onChangePassword(null, TEST_PASSWORD);
return instance.onDeleteConfirmed();
});

afterEach(() => {
instance.closeDeleteDialog.restore();
});

it('calls parity_killAccount', () => {
expect(api.parity.killAccount).to.have.been.calledWith(TEST_ADDRESS, TEST_PASSWORD);
});

it('changes the route to /accounts', () => {
expect(router.push).to.have.been.calledWith('/accounts');
});

it('closes the dialog', () => {
expect(instance.closeDeleteDialog).to.have.been.called;
});
});
});
});
Loading