Enter text below to generate random bytes
{
@@ -11,34 +12,14 @@ describe('PassphraseGenerator', () => {
changeHandler: () => {},
t: key => key,
};
- const mockEvent = {
- pageX: 140,
- pageY: 140,
- };
-
- it('calls setState to setValues locally', () => {
- const wrapper = shallow(
);
- const spyFn = spy(wrapper.instance(), 'setState');
- wrapper.instance().seedGenerator(mockEvent);
- expect(spyFn).to.have.been.calledWith();
- wrapper.instance().setState.restore();
- });
it('shows an Input fallback if this.isTouchDevice()', () => {
- const wrapper = mount(
);
- const isTouchDeviceMock = mock(wrapper.instance()).expects('isTouchDevice');
- isTouchDeviceMock.returns(true);
- wrapper.instance().setState({}); // to rerender the component
- wrapper.update();
+ const wrapper = mount(
);
expect(wrapper.find('Input.touch-fallback textarea')).to.have.lengthOf(1);
});
it('shows at least some progress on pressing input if this.isTouchDevice()', () => {
- const wrapper = mount(
);
- const isTouchDeviceMock = mock(wrapper.instance()).expects('isTouchDevice');
- isTouchDeviceMock.returns(true).twice();
- wrapper.instance().setState({}); // to rerender the component
- wrapper.update();
+ const wrapper = mount(
);
wrapper.find('Input.touch-fallback textarea').simulate('change', { target: { value: 'random key presses' } });
expect(wrapper.find('ProgressBar').props().value).to.be.at.least(1);
});
@@ -46,53 +27,28 @@ describe('PassphraseGenerator', () => {
it('removes mousemove event listener in componentWillUnmount', () => {
const wrapper = mount(
);
const documentSpy = spy(document, 'removeEventListener');
- wrapper.instance().componentWillUnmount();
+ wrapper.unmount();
expect(documentSpy).to.have.be.been.calledWith('mousemove');
documentSpy.restore();
});
- it('sets "data" and "lastCaptured" if distance is over 120', () => {
- const wrapper = shallow(
);
- wrapper.instance().seedGenerator(mockEvent);
-
- expect(wrapper.instance().state.data).to.not.equal(undefined);
- expect(wrapper.instance().state.lastCaptured).to.deep.equal({
- x: 140,
- y: 140,
- });
- });
-
- it('should do nothing if distance is bellow 120', () => {
- const wrapper = shallow(
);
- const nativeEvent = {
- pageX: 10,
- pageY: 10,
- };
- wrapper.instance().seedGenerator(nativeEvent);
+ it('should call generateSeed for every event triggered', () => {
+ const generateSeedSpy = spy(passphraseUtil, 'generateSeed');
+ const wrapper = mount(
);
+ wrapper.find('Input.touch-fallback textarea').simulate('change', { target: { value: 'random key presses' } });
- expect(wrapper.instance().state.data).to.be.equal(undefined);
- expect(wrapper.instance().state.lastCaptured).to.deep.equal({
- x: 0,
- y: 0,
- });
+ expect(generateSeedSpy.callCount).to.be.equal(1);
});
- it('should generate passphrase if seed is completed', () => {
- const wrapper = shallow(
);
- // set mock data
- wrapper.instance().setState({
- data: {
- seed: ['e6', '3c', 'd1', '36', 'e9', '70', '5f',
- 'c0', '4d', '31', 'ef', 'b8', 'd6', '53', '48', '11'],
- percentage: 100,
- step: 1,
- byte: [0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0],
- },
- });
-
- wrapper.instance().seedGenerator(mockEvent);
+ it('should call generatePassphrase after enough event passed', () => {
+ const generatePassphraseSpy = spy(passphraseUtil, 'generatePassphrase');
+ const wrapper = mount(
);
+ const input = wrapper.find('Input.touch-fallback textarea');
+ for (let i = 0; i < 101; i++) {
+ input.simulate('change', { target: { value: 'random key presses' } });
+ }
- expect(wrapper.instance().state.passphrase).to.not.equal(undefined);
+ expect(generatePassphraseSpy.callCount).to.be.equal(1);
});
});
});
diff --git a/src/components/passphrase/passphraseVerifier.js b/src/components/passphrase/passphraseVerifier.js
index baeb11b3c..752928c41 100644
--- a/src/components/passphrase/passphraseVerifier.js
+++ b/src/components/passphrase/passphraseVerifier.js
@@ -13,7 +13,8 @@ class PassphraseConfirmator extends React.Component {
componentDidMount() {
this.props.updateAnswer(false);
- this.hideRandomWord.call(this);
+ // this.props.randomIndex is used in unit teasing
+ this.hideRandomWord.call(this, this.props.randomIndex);
}
hideRandomWord(rand = Math.random()) {
@@ -40,7 +41,7 @@ class PassphraseConfirmator extends React.Component {
return (
-
+
{this.state.passphraseParts[0]}
-----
{this.state.passphraseParts[1]}
diff --git a/src/components/passphrase/passphraseVerifier.test.js b/src/components/passphrase/passphraseVerifier.test.js
index f16a84bb4..09731596c 100644
--- a/src/components/passphrase/passphraseVerifier.test.js
+++ b/src/components/passphrase/passphraseVerifier.test.js
@@ -1,7 +1,7 @@
import React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
-import { mount, shallow } from 'enzyme';
+import { mount } from 'enzyme';
import PassphraseVerifier from './passphraseVerifier';
@@ -11,44 +11,50 @@ describe('PassphraseVerifier', () => {
passphrase: 'survey stereo pool fortune oblige slight gravity goddess mistake sentence anchor pool',
t: key => key,
};
+ let updateAnswerSpy;
- describe('componentDidMount', () => {
- it('should call updateAnswer with "false"', () => {
- const spyFn = spy(props, 'updateAnswer');
- mount();
- expect(spyFn).to.have.been.calledWith();
- props.updateAnswer.restore();
- });
+ let wrapper;
+
+ beforeEach(() => {
+ updateAnswerSpy = spy(props, 'updateAnswer');
+ wrapper = mount();
});
- describe('changeHandler', () => {
- it('call updateAnswer with received value', () => {
- const spyFn = spy(props, 'updateAnswer');
- const value = 'sample';
- const wrapper = shallow();
- wrapper.instance().changeHandler(value);
- expect(spyFn).to.have.been.calledWith();
- props.updateAnswer.restore();
- });
+ afterEach(() => {
+ updateAnswerSpy.restore();
+ });
+
+ it('should initially call updateAnswer with "false"', () => {
+ expect(updateAnswerSpy).to.have.been.calledWith(false);
+ });
+
+ it('should call updateAnswer every time the input has changed', () => {
+ const value = 'sample value';
+
+ updateAnswerSpy.restore();
+ wrapper.find('input').simulate('change', { target: { value } });
+ expect(updateAnswerSpy.callCount).to.be.equal(2);
});
- describe('hideRandomWord', () => {
- it('should break passphrase, hide a word and store all in state', () => {
- const wrapper = shallow();
-
- const randomIndex = 0.6;
- const expectedValues = {
- passphraseParts: [
- 'survey stereo pool fortune oblige slight ',
- ' goddess mistake sentence anchor pool',
- ],
- missing: 'gravity',
- answer: '',
- };
- const spyFn = spy(wrapper.instance(), 'setState');
-
- wrapper.instance().hideRandomWord(randomIndex);
- expect(spyFn).to.have.been.calledWith(expectedValues);
+ it('should refocus if use blurs the input', () => {
+ const focusSpy = spy();
+ wrapper.find('input').simulate('blur', {
+ nativeEvent: { target: { focus: focusSpy } },
});
+
+ expect(focusSpy.callCount).to.be.equal(1);
+ });
+
+ it('should break passphrase, hide a word and show it', () => {
+ const expectedValues = [
+ 'survey stereo pool fortune oblige ',
+ '-----',
+ ' gravity goddess mistake sentence anchor pool',
+ ];
+ const spanTags = wrapper.find('.passphrase-holder span');
+
+ expect(spanTags.at(0).text()).to.be.equal(expectedValues[0]);
+ expect(spanTags.at(1).text()).to.be.equal(expectedValues[1]);
+ expect(spanTags.at(2).text()).to.be.equal(expectedValues[2]);
});
});
diff --git a/src/components/spinner/index.test.js b/src/components/spinner/index.test.js
index 9e38050fb..d4d77f5a8 100644
--- a/src/components/spinner/index.test.js
+++ b/src/components/spinner/index.test.js
@@ -4,7 +4,7 @@ import { mount } from 'enzyme';
import Spinner from './index';
describe('Spinner', () => {
- it('should render 1 span and 3 divs', () => {
+ it('should render 1 span and 3 div tags', () => {
const wrapper = mount();
expect(wrapper.find('span')).to.have.lengthOf(1);
expect(wrapper.find('div')).to.have.lengthOf(3);
diff --git a/src/components/toaster/toaster.test.js b/src/components/toaster/toaster.test.js
index 38a9f7292..f43b99086 100644
--- a/src/components/toaster/toaster.test.js
+++ b/src/components/toaster/toaster.test.js
@@ -5,7 +5,6 @@ import { mount } from 'enzyme';
import Toaster from './toaster';
describe('Toaster', () => {
- let wrapper;
const toasts = [{
label: 'test',
type: 'success',
@@ -16,25 +15,33 @@ describe('Toaster', () => {
hideToast: sinon.spy(),
};
- beforeEach(() => {
- wrapper = mount();
- });
-
it('renders component from react-toolbox', () => {
+ const wrapper = mount();
expect(wrapper.find('Snackbar')).to.have.length(1);
});
describe('hideToast', () => {
it('hides the toast and after the animation ends calls this.props.hideToast()', () => {
+ document.body.prepend(document.createElement('div'));
const clock = sinon.useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'Date'],
});
- wrapper.instance().hideToast(toasts[0]);
- expect(wrapper.state('hidden')).to.deep.equal({ [toasts[0].index]: true });
- clock.tick(510);
- expect(wrapper.state('hidden')).to.deep.equal({ [toasts[0].index]: false });
- clock.restore();
+ mount(, { attachTo: document.body.firstChild });
+ let toastElement = document.getElementsByClassName('toast');
+
+ // check if the toast is activated
+ expect(toastElement.length > 0 &&
+ toastElement[0].className.indexOf('active') > 0)
+ .to.equal(true);
+
+ clock.tick(4510);
+
+ // check if the toast is deactivated
+ toastElement = document.getElementsByClassName('toast');
+
+ // check if hideToast is called
expect(toasterProps.hideToast).to.have.been.calledWith(toasts[0]);
+ clock.restore();
});
});
});
diff --git a/src/components/voteDialog/voteAutocomplete.js b/src/components/voteDialog/voteAutocomplete.js
index d9b3de4b8..5dd2f5c0c 100644
--- a/src/components/voteDialog/voteAutocomplete.js
+++ b/src/components/voteDialog/voteAutocomplete.js
@@ -208,14 +208,14 @@ export class VoteAutocompleteRaw extends React.Component {
-
+
{this.state.votedResult.map(
item =>
-
+
{this.state.unvotedResult.map(
item => key,
};
let wrapper;
+const keyCodes = {
+ arrowDown: 40,
+ arrowUp: 38,
+ enter: 13,
+ escape: 27,
+};
const store = configureMockStore([])({
peers: {},
@@ -36,8 +46,12 @@ const store = configureMockStore([])({
describe('VoteAutocomplete', () => {
let voteAutocompleteApiMock;
let unvoteAutocompleteApiMock;
+ let clock;
beforeEach(() => {
+ clock = sinon.useFakeTimers({
+ toFake: ['setTimeout', 'clearTimeout', 'Date'],
+ });
sinon.spy(VoteAutocomplete.prototype, 'keyPress');
sinon.spy(VoteAutocomplete.prototype, 'handleArrowDown');
sinon.spy(VoteAutocomplete.prototype, 'handleArrowUp');
@@ -48,6 +62,7 @@ describe('VoteAutocomplete', () => {
});
afterEach(() => {
+ clock.restore();
voteAutocompleteApiMock.restore();
unvoteAutocompleteApiMock.restore();
VoteAutocomplete.prototype.keyPress.restore();
@@ -55,42 +70,27 @@ describe('VoteAutocomplete', () => {
VoteAutocomplete.prototype.handleArrowUp.restore();
});
- it('should suggestionStatus(false, className) change value of className in state', () => {
- const clock = sinon.useFakeTimers({
- toFake: ['setTimeout', 'clearTimeout', 'Date'],
- });
- wrapper.instance().suggestionStatus(false, 'className');
- clock.tick(200);
- expect(wrapper.state('className').match(/hidden/g)).to.have.lengthOf(1);
- });
+ it('should suggest with full username if finds a non-voted delegate with a username starting with given string', () => {
+ const voteAutocompleteApiStub = sinon.stub(delegateApi, 'voteAutocomplete');
+ voteAutocompleteApiStub.returnsPromise().resolves([unvotedDelegate[0]]);
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: 'user' } });
- it('should suggestionStatus(true, className) clear value of className in state', () => {
- const clock = sinon.useFakeTimers({
- toFake: ['setTimeout', 'clearTimeout', 'Date'],
- });
- wrapper.instance().suggestionStatus(true, 'className');
- clock.tick(200);
- expect(wrapper.state('className')).to.be.equal('');
+ clock.tick(300);
+ expect(wrapper.find('Card .vote-auto-complete-list ul').html().indexOf(unvotedDelegate[0].username)).to.be.greaterThan(-1);
+ voteAutocompleteApiStub.restore();
});
- it('should search hide suggestion boxes when value is equal to ""', () => {
- const clock = sinon.useFakeTimers({
- toFake: ['setTimeout', 'clearTimeout', 'Date'],
- });
- sinon.spy(VoteAutocomplete.prototype, 'setState');
- wrapper.instance().search('votedListSearch', '');
- clock.tick(250);
- expect(VoteAutocomplete.prototype.setState).to.have.property('callCount', 2);
- expect(wrapper.state('votedResult')).to.have.lengthOf(0);
- expect(wrapper.state('unvotedResult')).to.have.lengthOf(0);
- expect(wrapper.state('votedSuggestionClass').match(/hidden/g)).to.have.lengthOf(1);
- expect(wrapper.state('unvotedSuggestionClass').match(/hidden/g)).to.have.lengthOf(1);
- VoteAutocomplete.prototype.setState.restore();
+ it('should suggest with full username if dows not find a non-voted delegate with a username starting with given string', () => {
+ const voteAutocompleteApiStub = sinon.stub(delegateApi, 'voteAutocomplete');
+ voteAutocompleteApiStub.returnsPromise().rejects([]);
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: 'user' } });
+
+ clock.tick(400);
+ expect(wrapper.find('Card .vote-auto-complete-list ul')).to.be.blank();
+ voteAutocompleteApiStub.restore();
});
+
it('search should call "voteAutocomplete" when name is equal to "votedListSearch" when search term exists', () => {
- const clock = sinon.useFakeTimers({
- toFake: ['setTimeout', 'clearTimeout', 'Date'],
- });
const existingSearchTerm = 'username2';
const delegateApiMock = sinon.mock(delegateApi).expects('voteAutocomplete');
@@ -105,9 +105,6 @@ describe('VoteAutocomplete', () => {
});
it('search should call "voteAutocomplete" when name is equal to "votedListSearch" when search term does not exist', () => {
- const clock = sinon.useFakeTimers({
- toFake: ['setTimeout', 'clearTimeout', 'Date'],
- });
const nonExistingSearchTerm = 'doesntexist';
const delegateApiMock = sinon.mock(delegateApi).expects('voteAutocomplete');
@@ -123,9 +120,6 @@ describe('VoteAutocomplete', () => {
});
it('search should call "unvoteAutocomplete" when name is equal to "unvotedListSearch" when search term exists', () => {
- const clock = sinon.useFakeTimers({
- toFake: ['setTimeout', 'clearTimeout', 'Date'],
- });
const existingSearchTerm = 'username1';
const delegateApiMock = sinon.mock(delegateApi).expects('unvoteAutocomplete');
@@ -140,9 +134,6 @@ describe('VoteAutocomplete', () => {
});
it('search should call "unvoteAutocomplete" when name is equal to "unvotedListSearch" when search term does not exists', () => {
- const clock = sinon.useFakeTimers({
- toFake: ['setTimeout', 'clearTimeout', 'Date'],
- });
const nonExistingSearchTerm = 'username2';
const delegateApiMock = sinon.mock(delegateApi).expects('unvoteAutocomplete');
@@ -155,81 +146,119 @@ describe('VoteAutocomplete', () => {
delegateApiMock.restore();
});
- it('should "votedSearchKeydown" call "keyPress"', () => {
- wrapper.instance().votedSearchKeyDown({});
- expect(VoteAutocomplete.prototype.keyPress).to.have.property('callCount', 1);
- });
- it('should "unvotedSearchKeydown" call "keyPress"', () => {
- wrapper.instance().unvotedSearchKeyDown({});
- expect(VoteAutocomplete.prototype.keyPress).to.have.property('callCount', 1);
+ it('should let you choose one of the options by arrow down', () => {
+ const voteAutocompleteApiStub = sinon.stub(delegateApi, 'voteAutocomplete');
+ voteAutocompleteApiStub.returnsPromise().resolves(unvotedDelegate);
+ // write a username
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: 'user' } });
+ clock.tick(400);
+
+ // select it with arrow down
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.arrowDown });
+ clock.tick(200);
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.enter });
+ voteAutocompleteApiStub.restore();
+ expect(props.voteToggled).to.have.been.calledWith({
+ publicKey: unvotedDelegate[0].publicKey,
+ username: unvotedDelegate[0].username,
+ });
});
- it('should keyPress call "handleArrowDown" when event.keyCode is equal to 40', () => {
- const list = [
- { address: 'address 0' },
- { address: 'address 1', hovered: true },
- { address: 'address 2' },
- ];
- wrapper.setState({ votedResult: list });
- wrapper.instance().keyPress({ keyCode: 40 }, 'votedSuggestionClass', 'votedResult');
- expect(VoteAutocomplete.prototype.handleArrowDown).to.have.property('callCount', 1);
+ it('should let you navigate and choose one of the options in voteList using arrow up/down', () => {
+ const voteAutocompleteApiStub = sinon.stub(delegateApi, 'voteAutocomplete');
+ voteAutocompleteApiStub.returnsPromise().resolves(unvotedDelegate);
+ // write a username
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: 'user' } });
+ clock.tick(400);
+
+ // Arrow down
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.arrowDown });
+ // Arrow down
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.arrowDown });
+ // Arrow up
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.arrowUp });
+ // Hit enter
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.enter });
+ voteAutocompleteApiStub.restore();
+ expect(props.voteToggled).to.have.been.calledWith({
+ publicKey: unvotedDelegate[0].publicKey,
+ username: unvotedDelegate[0].username,
+ });
});
- it('should handleArrowDown select first item in votedResult when no one is selected', () => {
- const list = [
- { address: 'address 0' },
- { address: 'address 1' },
- { address: 'address 2' },
- ];
- wrapper.setState({ votedResult: list });
- wrapper.instance().handleArrowDown(wrapper.state('votedResult'), 'votedResult');
- expect(wrapper.state('votedResult')[0].hovered).to.have.be.equal(true);
+
+ it('should let you navigate and then escape the suggestion list', () => {
+ const voteAutocompleteApiStub = sinon.stub(delegateApi, 'voteAutocomplete');
+ voteAutocompleteApiStub.returnsPromise().resolves(unvotedDelegate);
+ // write a username
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: 'user' } });
+ clock.tick(400);
+
+ // Arrow down
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.arrowDown });
+ // Arrow down
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.arrowDown });
+ // Arrow up
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.arrowUp });
+ // Hit enter
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('keyDown', { keyCode: keyCodes.escape });
+ voteAutocompleteApiStub.restore();
+ clock.tick(400);
+ expect(wrapper.find('Card .vote-auto-complete-list').at(0).prop('className')).to.include('hidden');
});
- it('should handleArrowDown select first item in unvotedResult when no one is selected', () => {
- const list = [
- { address: 'address 0' },
- { address: 'address 1' },
- { address: 'address 2' },
- ];
- wrapper.setState({ unvotedResult: list });
- wrapper.instance().handleArrowDown(wrapper.state('unvotedResult'), 'unvotedResult');
- expect(wrapper.state('unvotedResult')[0].hovered).to.have.be.equal(true);
+ it('should remove suggestion list if you clean the input', () => {
+ const voteAutocompleteApiStub = sinon.stub(delegateApi, 'voteAutocomplete');
+ voteAutocompleteApiStub.returnsPromise().resolves(unvotedDelegate);
+ // write a username
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: 'user' } });
+ clock.tick(400);
+ wrapper.update();
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: '' } });
+ voteAutocompleteApiStub.restore();
+ clock.tick(400);
+ wrapper.update();
+ expect(wrapper.find('Card .vote-auto-complete-list ul')).to.be.blank();
});
- it('should keyPress call "handleArrowUp" when event.keyCode is equal to 38', () => {
- const list = [
- { address: 'address 0' },
- { address: 'address 1', hovered: true },
- ];
- wrapper.setState({ votedResult: list });
- wrapper.instance().keyPress({ keyCode: 38 }, 'votedSuggestionClass', 'votedResult');
- expect(VoteAutocomplete.prototype.handleArrowUp).to.have.property('callCount', 1);
+
+ it('should hide suggestion list if you blur the input', () => {
+ const voteAutocompleteApiStub = sinon.stub(delegateApi, 'voteAutocomplete');
+ voteAutocompleteApiStub.returnsPromise().resolves(unvotedDelegate);
+ // write a username
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('change', { target: { value: 'user' } });
+ clock.tick(400);
+ wrapper.find('.votedListSearch.vote-auto-complete input').simulate('blur', {});
+ voteAutocompleteApiStub.restore();
+ clock.tick(200);
+ wrapper.update();
+ expect(wrapper.find('Card .vote-auto-complete-list').at(0).prop('className')).to.include('hidden');
});
- it('should keyPress hide suggestions when event.keyCode is equal to 27', () => {
- const returnValue = wrapper.instance()
- .keyPress({ keyCode: 27 }, 'votedSuggestionClass', 'votedResult');
- expect(wrapper.state('votedSuggestionClass').match(/hidden/g)).to.have.lengthOf(1);
- expect(returnValue).to.be.equal(false);
+ it('should suggest with full username to unvote if finds a voted delegate with a username starting with given string', () => {
+ const unvoteAutocompleteApiStub = sinon.stub(delegateApi, 'unvoteAutocomplete');
+ unvoteAutocompleteApiStub.returnsPromise().resolves([delegates[1]]);
+ wrapper.find('.unvotedListSearch input').simulate('change', { target: { value: 'user' } });
+
+ clock.tick(300);
+ expect(wrapper.find('Card .unvote-auto-complete-list ul').html()).to.include(delegates[1].username);
+ unvoteAutocompleteApiStub.restore();
});
- it(`should keyPress call "addToVoted" when event.keyCode is equal to 13 and
- list name is equal to votedResult`, () => {
- const list = [{ address: 'address 1', hovered: true }];
- wrapper.setState({ votedResult: list });
- const returnValue = wrapper.instance()
- .keyPress({ keyCode: 13 }, 'votedSuggestionClass', 'votedResult');
- expect(props.voteToggled).to.have.property('callCount', 1);
- expect(returnValue).to.be.equal(false);
- });
+ it('should let you navigate and choose one of the options in unvoteList using arrow up/down', () => {
+ const unvoteAutocompleteApiStub = sinon.stub(delegateApi, 'unvoteAutocomplete');
+ unvoteAutocompleteApiStub.returnsPromise().resolves([delegates[1]]);
+ // write a username
+ wrapper.find('.unvotedListSearch input').simulate('change', { target: { value: 'user' } });
+ clock.tick(400);
- it(`should keyPress call "voteToggled" when event.keyCode is equal to 13 and
- list name is equal to unvotedResult`, () => {
- const list = [{ address: 'address 1', hovered: true }];
- wrapper.setState({ unvotedResult: list });
- const returnValue = wrapper.instance()
- .keyPress({ keyCode: 13 }, 'unvotedSuggestionClass', 'unvotedResult');
- expect(props.voteToggled).to.have.property('callCount', 2);
- expect(returnValue).to.be.equal(false);
+ // Arrow down
+ wrapper.find('.unvotedListSearch input').simulate('keyDown', { keyCode: keyCodes.arrowDown });
+ // Hit enter
+ wrapper.find('.unvotedListSearch input').simulate('keyDown', { keyCode: keyCodes.enter });
+ unvoteAutocompleteApiStub.restore();
+ expect(props.voteToggled).to.have.been.calledWith({
+ publicKey: delegates[1].publicKey,
+ username: delegates[1].username,
});
+ });
});