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

Commit

Permalink
Merge pull request #941 from LiskHQ/751-skip-and-todos
Browse files Browse the repository at this point in the history
Unskip tests and solve TODOs - Closes #751
  • Loading branch information
slaweet authored Nov 3, 2017
2 parents 0a7345d + 3e0a579 commit 891cf58
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 31 deletions.
11 changes: 9 additions & 2 deletions src/actions/forging.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 => ({
Expand All @@ -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 }));
});
};
17 changes: 9 additions & 8 deletions src/actions/forging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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);
});
});
});
4 changes: 0 additions & 4 deletions src/actions/savedAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions src/components/decryptMessage/decryptMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('DecryptMessage', () => {
const props = {
account,
successToast: successToastSpy,
errorToast: sinon.spy(),
errorToast: errorSpy,
copyToClipboard: copyMock,
t: key => key,
};
Expand All @@ -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 } });
Expand Down
8 changes: 3 additions & 5 deletions src/components/pricedButton/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/signMessage/signMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SignMessageComponent extends React.Component {
<br />
{this.props.t('Note: Digital Signatures and signed messages are not encrypted!')}
</InfoParagraph>
<form onSubmit={this.showResult.bind(this)}>
<form onSubmit={this.showResult.bind(this)} id='signMessageForm'>
<section>
<Input className='message' multiline label={this.props.t('Message')}
autoFocus={true}
Expand Down
6 changes: 3 additions & 3 deletions src/components/signMessage/signMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ ${signature}
</Provider>);
});

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' });
});

Expand Down
7 changes: 5 additions & 2 deletions src/utils/saveAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

0 comments on commit 891cf58

Please sign in to comment.