From a1b535c1aa4d78cd9731056670cc5c360a68cadf Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 1 Nov 2017 17:50:23 +0100 Subject: [PATCH 1/4] Unskip some broken tests --- src/actions/forging.js | 11 +++++++++-- src/actions/forging.test.js | 17 +++++++++-------- .../decryptMessage/decryptMessage.test.js | 10 ++++------ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/actions/forging.js b/src/actions/forging.js index 651912ef1..9e5ffa0c7 100644 --- a/src/actions/forging.js +++ b/src/actions/forging.js @@ -1,5 +1,6 @@ import actionTypes from '../constants/actions'; import { getForgedBlocks, getForgedStats } from '../utils/api/forging'; +import { errorAlertDialogDisplayed } from './dialog'; export const forgedBlocksUpdated = data => ({ data, @@ -11,7 +12,10 @@ export const fetchAndUpdateForgedBlocks = ({ activePeer, limit, offset, generato getForgedBlocks(activePeer, limit, offset, generatorPublicKey) .then(response => dispatch(forgedBlocksUpdated(response.blocks)), - ); + ) + .catch((error) => { + dispatch(errorAlertDialogDisplayed({ text: error.message })); + }); }; export const forgingStatsUpdated = data => ({ @@ -24,5 +28,8 @@ export const fetchAndUpdateForgedStats = ({ activePeer, key, startMoment, genera getForgedStats(activePeer, startMoment, generatorPublicKey) .then(response => dispatch(forgingStatsUpdated({ [key]: response.forged })), - ); + ) + .catch((error) => { + dispatch(errorAlertDialogDisplayed({ text: error.message })); + }); }; diff --git a/src/actions/forging.test.js b/src/actions/forging.test.js index 5920defc6..3f7e94d43 100644 --- a/src/actions/forging.test.js +++ b/src/actions/forging.test.js @@ -4,6 +4,7 @@ import actionTypes from '../constants/actions'; import { forgedBlocksUpdated, forgingStatsUpdated, fetchAndUpdateForgedBlocks, fetchAndUpdateForgedStats } from './forging'; import * as forgingApi from '../utils/api/forging'; +import { errorAlertDialogDisplayed } from './dialog'; describe('actions', () => { describe('forgedBlocksUpdated', () => { @@ -64,12 +65,12 @@ describe('actions', () => { expect(dispatch).to.have.been.calledWith(forgedBlocksUpdated('value')); }); - it.skip('should dispatch errorAlertDialogDisplayed action if caught', () => { + it('should dispatch errorAlertDialogDisplayed action if caught', () => { forgingApiMock.returnsPromise().rejects({ message: 'sample message' }); - // actionFunction(dispatch); - // const expectedAction = errorAlertDialogDisplayed({ text: 'sample message' }); - // expect(dispatch).to.have.been.calledWith(expectedAction); + actionFunction(dispatch); + const expectedAction = errorAlertDialogDisplayed({ text: 'sample message' }); + expect(dispatch).to.have.been.calledWith(expectedAction); }); }); @@ -105,12 +106,12 @@ describe('actions', () => { expect(dispatch).to.have.been.calledWith(forgingStatsUpdated({ [key]: 'value' })); }); - it.skip('should dispatch errorAlertDialogDisplayed action if caught', () => { + it('should dispatch errorAlertDialogDisplayed action if caught', () => { forgingApiMock.returnsPromise().rejects({ message: 'sample message' }); - // actionFunction(dispatch); - // const expectedAction = errorAlertDialogDisplayed({ text: 'sample message' }); - // expect(dispatch).to.have.been.calledWith(expectedAction); + actionFunction(dispatch); + const expectedAction = errorAlertDialogDisplayed({ text: 'sample message' }); + expect(dispatch).to.have.been.calledWith(expectedAction); }); }); }); diff --git a/src/components/decryptMessage/decryptMessage.test.js b/src/components/decryptMessage/decryptMessage.test.js index 121c1844e..7c2d9e68d 100644 --- a/src/components/decryptMessage/decryptMessage.test.js +++ b/src/components/decryptMessage/decryptMessage.test.js @@ -35,7 +35,7 @@ describe('DecryptMessage', () => { const props = { account, successToast: successToastSpy, - errorToast: sinon.spy(), + errorToast: errorSpy, copyToClipboard: copyMock, t: key => key, }; @@ -51,20 +51,18 @@ describe('DecryptMessage', () => { decryptMessageMock.restore(); }); - // ToDo find the problem with this test - it.skip('shows error toast when couldn\'t decrypt a message', () => { - decryptMessageMock.returnsPromise().rejects({ message: 'couldn\'t decrypt the message' }); + it('shows error toast when couldn\'t decrypt a message', () => { + decryptMessageMock.throws({ message: 'couldn\'t decrypt the message' }); wrapper.find('.message textarea').simulate('change', { target: { value: message } }); wrapper.find('.senderPublicKey input').simulate('change', { target: { value: senderPublicKey } }); wrapper.find('.nonce input').simulate('change', { target: { value: nonce } }); wrapper.find('form').simulate('submit'); - expect(errorSpy).to.have.been.calledOnce(); expect(errorSpy).to.have.been.calledWith({ label: 'couldn\'t decrypt the message' }); }); it('allows to decrypt a message, copies encrypted message result to clipboard and shows success toast', () => { copyMock.returns(true); - decryptMessageMock.returnsPromise().resolves(decryptedMessage); + decryptMessageMock.returns(decryptedMessage); wrapper.find('.message textarea').simulate('change', { target: { value: message } }); wrapper.find('.senderPublicKey input').simulate('change', { target: { value: senderPublicKey } }); wrapper.find('.nonce input').simulate('change', { target: { value: nonce } }); From 83f06bf45bf98e07333f15ec783d73fbe41108e5 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Fri, 3 Nov 2017 10:20:00 +0100 Subject: [PATCH 2/4] Unskip signMessage test --- src/components/signMessage/signMessage.js | 2 +- src/components/signMessage/signMessage.test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/signMessage/signMessage.js b/src/components/signMessage/signMessage.js index d8a607f44..579e688de 100644 --- a/src/components/signMessage/signMessage.js +++ b/src/components/signMessage/signMessage.js @@ -61,7 +61,7 @@ class SignMessageComponent extends React.Component {
{this.props.t('Note: Digital Signatures and signed messages are not encrypted!')} -
+
); }); - it.skip('allows to sign a message, copies sign message result to clipboard and shows success toast', () => { + 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('.primary-button').simulate('click'); - expect(wrapper.find('.result textarea').text()).to.equal(result); + wrapper.find('#signMessageForm').simulate('submit'); + expect(wrapper.find('.result Input').text()).to.equal(result); expect(successToastSpy).to.have.been.calledWith({ label: 'Result copied to clipboard' }); }); From cce2d27eb06b9b814cbc08b9e7410746d0d75cd7 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Fri, 3 Nov 2017 11:04:43 +0100 Subject: [PATCH 3/4] Solve Todos --- src/components/pricedButton/index.test.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/pricedButton/index.test.js b/src/components/pricedButton/index.test.js index 1f2d188b4..46eea1cb4 100644 --- a/src/components/pricedButton/index.test.js +++ b/src/components/pricedButton/index.test.js @@ -13,7 +13,7 @@ describe('PricedButton', () => { const props = { fee: 5e8, onClick: sinon.spy(), - t: key => i18n.t(key), + t: (key, options) => i18n.t(key, options), }; const insufficientBalance = 4.9999e8; const sufficientBalance = 6e8; @@ -29,8 +29,7 @@ describe('PricedButton', () => { }); it('renders a span saying "Fee: 5 LSK"', () => { - // TODO the text should actually contain 5 but in tests it doesn't - expect(wrapper.find(`.${styles.fee}`).text()).to.be.equal(i18n.t('Fee: LSK')); + expect(wrapper.find(`.${styles.fee}`).text()).to.be.equal(i18n.t('Fee: 5 LSK')); }); it('allows to click on Button', () => { @@ -45,8 +44,7 @@ describe('PricedButton', () => { }); it('renders a span saying "Insufficient funds for 5 LSK fee"', () => { - // TODO the text should actually contain 5 but in tests it doesn't - expect(wrapper.find(`.${styles.fee}`).text()).to.be.equal('Insufficient funds for LSK fee'); + expect(wrapper.find(`.${styles.fee}`).text()).to.be.equal('Insufficient funds for 5 LSK fee'); }); it('sets the disabled attribute of the button', () => { From 3e0a57929236894f3a541510c71fc4d353d4a858 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Fri, 3 Nov 2017 11:44:31 +0100 Subject: [PATCH 4/4] Remove specific saved account instead of all saved accounts in localStorage --- src/actions/savedAccounts.js | 4 ---- src/utils/saveAccount.js | 7 +++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/actions/savedAccounts.js b/src/actions/savedAccounts.js index 135a39804..2c9ba928b 100644 --- a/src/actions/savedAccounts.js +++ b/src/actions/savedAccounts.js @@ -15,10 +15,6 @@ export const accountSaved = (data) => { /** * An action to dispatch accountRemoved - * - * @todo Currently the utility removed the entire array from localStorage. - * it should remove only one item - * */ export const accountRemoved = (publicKey) => { removeSavedAccount(publicKey); diff --git a/src/utils/saveAccount.js b/src/utils/saveAccount.js index efdbffe7c..b0149e465 100644 --- a/src/utils/saveAccount.js +++ b/src/utils/saveAccount.js @@ -16,6 +16,9 @@ export const setSavedAccount = ({ publicKey, network, address }) => { }])); }; -export const removeSavedAccount = () => { - localStorage.removeItem('accounts'); +export const removeSavedAccount = (publicKey) => { + let accounts = localStorage.getItem('accounts'); + accounts = JSON.parse(accounts); + accounts = accounts.filter(account => account.publicKey !== publicKey); + localStorage.setItem('accounts', JSON.stringify(accounts)); };