From 0162142ce0375c954b59f2d8b31be44d47defb29 Mon Sep 17 00:00:00 2001 From: Misha Moroshko Date: Sun, 9 Sep 2018 20:56:06 -0700 Subject: [PATCH] Cleanup --- src/Autosuggest.js | 13 +++++-- .../AutosuggestApp.test.js | 19 +++++----- test/helpers.js | 12 +++--- test/plain-list/AutosuggestApp.test.js | 38 ++++++++++--------- 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/Autosuggest.js b/src/Autosuggest.js index 17d6b57b..4779148b 100644 --- a/src/Autosuggest.js +++ b/src/Autosuggest.js @@ -336,6 +336,7 @@ export default class Autosuggest extends Component { onSuggestionMouseEnter = (event, { sectionIndex, itemIndex }) => { this.updateHighlightedSuggestion(sectionIndex, itemIndex); + if (event.target === this.pressedSuggestion) { this.justSelectedSuggestion = true; } @@ -358,12 +359,12 @@ export default class Autosuggest extends Component { } }; - onSuggestionMouseDown = e => { + onSuggestionMouseDown = event => { // Checking if this.justSelectedSuggestion is already true to not duplicate touch events in chrome // See: https://github.com/facebook/react/issues/9809#issuecomment-413978405 if (!this.justSelectedSuggestion) { this.justSelectedSuggestion = true; - this.pressedSuggestion = e.target; + this.pressedSuggestion = event.target; } }; @@ -446,9 +447,13 @@ export default class Autosuggest extends Component { onBlur && onBlur(this.blurEvent, { highlightedSuggestion }); }; - onSuggestionMouseLeave = e => { + onSuggestionMouseLeave = event => { this.resetHighlightedSuggestion(false); // shouldResetValueBeforeUpDown - if (this.justSelectedSuggestion && e.target === this.pressedSuggestion) { + + if ( + this.justSelectedSuggestion && + event.target === this.pressedSuggestion + ) { this.justSelectedSuggestion = false; } }; diff --git a/test/focus-first-suggestion/AutosuggestApp.test.js b/test/focus-first-suggestion/AutosuggestApp.test.js index 6048865b..9a4cc66c 100644 --- a/test/focus-first-suggestion/AutosuggestApp.test.js +++ b/test/focus-first-suggestion/AutosuggestApp.test.js @@ -128,15 +128,16 @@ describe('Autosuggest with highlightFirstSuggestion={true}', () => { onSuggestionSelected.reset(); clickEnter(); expect(onSuggestionSelected).to.have.been.calledOnce; - expect( - onSuggestionSelected - ).to.have.been.calledWithExactly(syntheticEventMatcher, { - suggestion: { name: 'Perl', year: 1987 }, - suggestionValue: 'Perl', - suggestionIndex: 0, - sectionIndex: null, - method: 'enter' - }); + expect(onSuggestionSelected).to.have.been.calledWithExactly( + syntheticEventMatcher, + { + suggestion: { name: 'Perl', year: 1987 }, + suggestionValue: 'Perl', + suggestionIndex: 0, + sectionIndex: null, + method: 'enter' + } + ); }); }); diff --git a/test/helpers.js b/test/helpers.js index 69a1883a..b55308ea 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -92,11 +92,13 @@ export const getSuggestion = suggestionIndex => { throw Error( ` Cannot find suggestion #${suggestionIndex}. - ${suggestions.length === 0 - ? 'No suggestions found.' - : `Only ${suggestions.length} suggestion${suggestions.length === 1 - ? '' - : 's'} found.`} + ${ + suggestions.length === 0 + ? 'No suggestions found.' + : `Only ${suggestions.length} suggestion${ + suggestions.length === 1 ? '' : 's' + } found.` + } ` ); } diff --git a/test/plain-list/AutosuggestApp.test.js b/test/plain-list/AutosuggestApp.test.js index 6a1b4b73..c13bde13 100644 --- a/test/plain-list/AutosuggestApp.test.js +++ b/test/plain-list/AutosuggestApp.test.js @@ -602,30 +602,32 @@ describe('Default Autosuggest', () => { it('should be called once with the right parameters when suggestion is clicked', () => { clickSuggestion(1); expect(onSuggestionSelected).to.have.been.calledOnce; - expect( - onSuggestionSelected - ).to.have.been.calledWithExactly(syntheticEventMatcher, { - suggestion: { name: 'JavaScript', year: 1995 }, - suggestionValue: 'JavaScript', - suggestionIndex: 1, - sectionIndex: null, - method: 'click' - }); + expect(onSuggestionSelected).to.have.been.calledWithExactly( + syntheticEventMatcher, + { + suggestion: { name: 'JavaScript', year: 1995 }, + suggestionValue: 'JavaScript', + suggestionIndex: 1, + sectionIndex: null, + method: 'click' + } + ); }); it('should be called once with the right parameters when Enter is pressed and suggestion is highlighted', () => { clickDown(); clickEnter(); expect(onSuggestionSelected).to.have.been.calledOnce; - expect( - onSuggestionSelected - ).to.have.been.calledWithExactly(syntheticEventMatcher, { - suggestion: { name: 'Java', year: 1995 }, - suggestionValue: 'Java', - suggestionIndex: 0, - sectionIndex: null, - method: 'enter' - }); + expect(onSuggestionSelected).to.have.been.calledWithExactly( + syntheticEventMatcher, + { + suggestion: { name: 'Java', year: 1995 }, + suggestionValue: 'Java', + suggestionIndex: 0, + sectionIndex: null, + method: 'enter' + } + ); }); it('should not be called when Enter is pressed and there is no highlighted suggestion', () => {