Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Move copy-to-clipboard to props of signMessageComponent
Browse files Browse the repository at this point in the history
... for the sake of testability. Else copy-to-clipboard was opening
window.alert which failed the tests
  • Loading branch information
slaweet committed Aug 2, 2017
1 parent 95e3ac1 commit 844dbb5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/components/signVerify/signMessage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { connect } from 'react-redux';
import copy from 'copy-to-clipboard';
import { successToastDisplayed } from '../../actions/toaster';
import SignMessageComponent from './signMessageComponent';

const mapDispatchToProps = dispatch => ({
successToast: data => dispatch(successToastDisplayed(data)),
copyToClipboard: (...args) => copy(...args),
});

export default connect(
Expand Down
3 changes: 1 addition & 2 deletions src/components/signVerify/signMessageComponent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import Input from 'react-toolbox/lib/input';
import Button from 'react-toolbox/lib/button';
import copy from 'copy-to-clipboard';
import lisk from 'lisk-js';

import InfoParagraph from '../infoParagraph';
Expand Down Expand Up @@ -32,7 +31,7 @@ class SignMessageComponent extends React.Component {
}

showResult() {
const copied = copy(this.state.result, {
const copied = this.props.copyToClipboard(this.state.result, {
message: 'Press #{key} to copy',
});
if (copied) {
Expand Down
23 changes: 20 additions & 3 deletions src/components/signVerify/signMessageComponent.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React from 'react';
import { expect } from 'chai';
import chai, { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';

import SignMessageComponent from './signMessageComponent';

chai.use(sinonChai);

describe('SignMessageComponent', () => {
let wrapper;
let successToastSpy;
let copyMock;
const publicKey = 'c094ebee7ec0c50ebee32918655e089f6e1a604b83bcaa760293c61e0f18ab6f';
const signature = '079331d868678fd5f272f09d6dc8792fb21335aec42af7f11caadbfbc17d4707e7' +
'd7f343854b0c619b647b81ba3f29b23edb4eaf382a47c534746bad4529560b48656c6c6f20776f726c64';
Expand All @@ -26,12 +31,24 @@ ${signature}

beforeEach(() => {
successToastSpy = sinon.spy();
wrapper = mount(<SignMessageComponent account={account} successToast={successToastSpy} />);
copyMock = sinon.mock();

wrapper = mount(<SignMessageComponent
account={account} successToast={successToastSpy} copyToClipboard={copyMock} />);
});

it('allows to sign a message', () => {
it('allows to sign a message, copies sign mesage result to clipboard and shows success toast', () => {
copyMock.returns(true);
wrapper.find('.message textarea').simulate('change', { target: { value: message } });
wrapper.find('.sign-button').simulate('click');
expect(wrapper.find('.result textarea').text()).to.equal(result);
expect(successToastSpy).to.have.been.calledWith({ label: 'Result copied to clipboard' });
});

it('does not show success toast if copy-to-clipboard failed', () => {
copyMock.returns(false);
wrapper.find('.message textarea').simulate('change', { target: { value: message } });
wrapper.find('.sign-button').simulate('click');
expect(successToastSpy).to.have.not.been.calledWith({ label: 'Result copied to clipboard' });
});
});

0 comments on commit 844dbb5

Please sign in to comment.