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

Commit

Permalink
Improve test coverage of signMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Nov 24, 2017
1 parent b9a4208 commit 3e5774d
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/components/signMessage/signMessage.test.js
Expand Up @@ -16,21 +16,24 @@ describe('SignMessage', () => {
let store;
let options;
const publicKey = 'c094ebee7ec0c50ebee32918655e089f6e1a604b83bcaa760293c61e0f18ab6f';
const signature = '079331d868678fd5f272f09d6dc8792fb21335aec42af7f11caadbfbc17d4707e7' +
const signature1 = '079331d868678fd5f272f09d6dc8792fb21335aec42af7f11caadbfbc17d4707e7' +
'd7f343854b0c619b647b81ba3f29b23edb4eaf382a47c534746bad4529560b48656c6c6f20776f726c64';
const message = 'Hello world';
const signature2 = '40f339db0d00f7909ab3818a1181e1fcb4139c9cb092c56aa88108b821eb6769bb' +
'970a99edf2ec60729612fb04a4470cc190786fcb5142b72a6b2a0100e7f90148656c6c6f203220776f726c6473';
const message1 = 'Hello world';
const message2 = 'Hello 2 worlds';
const account = {
passphrase: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble',
publicKey,
};
const result = `-----BEGIN LISK SIGNED MESSAGE-----
const getResult = (message, signature) => (`-----BEGIN LISK SIGNED MESSAGE-----
-----MESSAGE-----
${message}
-----PUBLIC KEY-----
${publicKey}
-----SIGNATURE-----
${signature}
-----END LISK SIGNED MESSAGE-----`;
-----END LISK SIGNED MESSAGE-----`);

beforeEach(() => {
successToastSpy = sinon.spy();
Expand All @@ -57,9 +60,24 @@ ${signature}

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

it('allows to sign multiple messages, shows the signed message and success toast each time', () => {
copyMock.returns(true);
wrapper.find('.message textarea').simulate('change', { target: { value: message1 } });
wrapper.find('#signMessageForm').simulate('submit');
expect(wrapper.find('.result Input').text()).to.equal(getResult(message1, signature1));
expect(successToastSpy).to.have.been.calledWith({ label: 'Result copied to clipboard' });

copyMock.reset();
copyMock.returns(true);
wrapper.find('.message textarea').simulate('change', { target: { value: message2 } });
wrapper.find('#signMessageForm').simulate('submit');
expect(wrapper.find('.result Input').text()).to.equal(getResult(message2, signature2));
expect(successToastSpy).to.have.been.calledWith({ label: 'Result copied to clipboard' });
});

Expand All @@ -86,16 +104,16 @@ ${signature}
},
});

wrapper.find('.message textarea').simulate('change', { target: { value: message } });
wrapper.find('.message textarea').simulate('change', { target: { value: message1 } });
wrapper.find('.passphrase input').simulate('change', { target: { value: account.passphrase } });
wrapper.find('#signMessageForm').simulate('submit');
expect(wrapper.find('.result Input').text()).to.equal(result);
expect(wrapper.find('.result Input').text()).to.equal(getResult(message1, signature1));
});

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('.primary-button').simulate('click');
wrapper.find('.message textarea').simulate('change', { target: { value: message1 } });
wrapper.find('#signMessageForm').simulate('submit');
expect(successToastSpy).to.have.not.been.calledWith();
});
});

0 comments on commit 3e5774d

Please sign in to comment.