From de2b8ee751da78ea39f479f9bc99e72ddd496944 Mon Sep 17 00:00:00 2001 From: Izaak Schroeder Date: Mon, 22 May 2017 18:54:19 -0700 Subject: [PATCH] Fix incorrect edge detection logic. It looks like previously `.indexOf !== region` should have been `.indexOf(region) !== -1`. Since incorrect edge flipping to the point of UI breakage doesn't happen that often this went undetected for quite some time. So the logic is now fixed to do the right thing and does so in a way a little more performant than calling `indexOf` on a two-element constant array. --- src/flowtip.js | 4 ++-- test/spec/flowtip.spec.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/flowtip.js b/src/flowtip.js index b6f43a6..7df6b9d 100644 --- a/src/flowtip.js +++ b/src/flowtip.js @@ -354,12 +354,12 @@ export default class Flowtip extends Component { // Edge detection - squeeze if ( - (['top', 'bottom'].indexOf !== region) && + (region === 'top' || region === 'bottom') && !regionParameter.top.fits && !regionParameter.bottom.fits ) { region = this.availableAndFitsIn(['left', 'right'], regionParameter); } else if ( - (['left', 'right'].indexOf !== region) && + (region === 'left' || region === 'right') && !regionParameter.left.fits && !regionParameter.right.fits ) { region = this.availableAndFitsIn(['top', 'bottom'], regionParameter); diff --git a/test/spec/flowtip.spec.js b/test/spec/flowtip.spec.js index 84f0843..2784870 100644 --- a/test/spec/flowtip.spec.js +++ b/test/spec/flowtip.spec.js @@ -28,4 +28,29 @@ describe('FlowTip', () => { ); expect(component.text()).to.equal('left'); }); + + it('should edge detect properly', () => { + const parent = {left: 0, top: 0, width: 300, height: 300}; + const anchor = parent; + const tail = {width: 50, height: 50}; + const content = {width: 150, height: 100}; + const region = 'top'; + const offset = {left: 0, top: 0}; + const target = {left: 150, top: 50, width: 50, height: 50}; + const component = shallow( + +
{region}
+ } + /> + ); + expect(component.text()).to.equal('bottom'); + }); });