diff --git a/src/fsm-transitions.js b/src/fsm-transitions.js index f8f81a9..2410f74 100644 --- a/src/fsm-transitions.js +++ b/src/fsm-transitions.js @@ -6,7 +6,16 @@ export default { to: states.FINISH, when: (d) => [ d.isSideInnerWithinPath === true, - d.viewportTop + d.sideInnerHeight > d.finishPoint + d.isSideInnerWithinViewport === false, + d.viewportBottom > d.finishPoint + ] + }, + { + to: states.FINISH, + when: (d) => [ + d.isSideInnerWithinPath === true, + d.isSideInnerWithinViewport === true, + d.viewportTop + d.sideInnerHeight + d.bottomSpacing > d.finishPoint ] }, { @@ -60,7 +69,7 @@ export default { }, { to: states.FINISH, - when: (d) => [d.viewportTop + d.sideInnerHeight > d.finishPoint] + when: (d) => [d.viewportBottom > d.finishPoint] }, { to: states.TOP_FIXED, diff --git a/test/transitions.test.js b/test/transitions.test.js index eb8bdad..f546a66 100644 --- a/test/transitions.test.js +++ b/test/transitions.test.js @@ -205,11 +205,12 @@ describe('transitions', function() { // isSideInnerWithinPath === true describe('when height(content) > height(sidebarInner)', () => { beforeEach(async () => { - setContentHeight(sidebarInnerHeight * 2); + setContentHeight(sidebarInnerHeight * 1.5); await nextFrame(); }); - it('START => BOTTOM_FIXED', async () => { + it.only('START => BOTTOM_FIXED', async () => { + await scrollTo(); await scrollTo(getElementBottom(sidebarInnerElement) - window.innerHeight + 1); await forceUpdate(); expectTransitionTo(BOTTOM_FIXED); @@ -220,7 +221,7 @@ describe('transitions', function() { await forceUpdate(); expectTransitionTo(BOTTOM_FIXED); - setContentHeight(sidebarInnerHeight / 2); + setContentHeight(sidebarInnerHeight / 1.5); await forceUpdate(); expectTransitionTo(START); }); @@ -274,7 +275,7 @@ describe('transitions', function() { await forceUpdate(); expectTransitionTo(UNFIXED); - setContentHeight(sidebarInnerHeight / 2); + setContentHeight(sidebarInnerHeight / 1.5); await forceUpdate(); expectTransitionTo(START); }); @@ -408,7 +409,7 @@ describe('transitions', function() { }); it('START => FINISH', async () => { - await scrollTo(getElementBottom(contentElement) - window.innerHeight); + await scrollTo(getElementBottom(contentElement) - window.innerHeight + 1); await forceUpdate(); expectTransitionTo(FINISH); });