Skip to content

Instantly share code, notes, and snippets.

@trotzig
Created January 26, 2017 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trotzig/4321f7846c35039563411b94498a7d5c to your computer and use it in GitHub Desktop.
Save trotzig/4321f7846c35039563411b94498a7d5c to your computer and use it in GitHub Desktop.
diff --git a/spec/waypoint_spec.js b/spec/waypoint_spec.js
index 2f7e316..d739cef 100644
--- a/spec/waypoint_spec.js
+++ b/spec/waypoint_spec.js
@@ -329,6 +329,46 @@ describe('<Waypoint>', function() {
});
});
+ describe('with children', () => {
+ beforeEach(() => {
+ this.childrenHeight = 80;
+ this.props.children = [
+ React.createElement('div', {
+ key: 1,
+ style: {
+ height: this.childrenHeight / 2,
+ }
+ }),
+ React.createElement('div', {
+ key: 2,
+ style: {
+ height: this.childrenHeight / 2,
+ }
+ }),
+ ];
+ });
+
+ describe('when scrolling down far enough', () => {
+ beforeEach(() => {
+ this.component = this.subject();
+ this.props.onPositionChange.calls.reset();
+ scrollNodeTo(this.component, 100);
+ });
+
+ it('calls the onEnter handler', () => {
+ expect(this.props.onEnter).
+ toHaveBeenCalledWith({
+ currentPosition: Waypoint.inside,
+ previousPosition: Waypoint.below,
+ event: jasmine.any(Event),
+ waypointTop: this.margin + this.topSpacerHeight - 100,
+ viewportTop: this.margin,
+ viewportBottom: this.margin + this.parentHeight,
+ });
+ });
+ });
+ });
+
describe('when scrolling down just below the threshold', () => {
beforeEach(() => {
this.component = this.subject();
@@ -784,6 +824,57 @@ describe('<Waypoint>', function() {
});
});
+ describe('when the Waypoint has children and is above the top', () => {
+ beforeEach(() => {
+ this.topSpacerHeight = 200;
+ this.bottomSpacerHeight = 200;
+ this.props.children = React.createElement('div', {
+ style: {
+ height: 100,
+ }
+ });
+ this.scrollable = this.subject();
+
+ // Because of how we detect when a Waypoint is scrolled past without any
+ // scroll event fired when it was visible, we need to reset callback
+ // spies.
+ scrollNodeTo(this.scrollable, 400);
+ this.props.onEnter.calls.reset();
+ this.props.onLeave.calls.reset();
+ scrollNodeTo(this.scrollable, 400);
+ });
+
+ it('does not call the onEnter handler', () => {
+ expect(this.props.onEnter).not.toHaveBeenCalled();
+ });
+
+ it('does not call the onLeave handler', () => {
+ expect(this.props.onLeave).not.toHaveBeenCalled();
+ });
+
+ describe('when scrolled back up just past the bottom', () => {
+ beforeEach(() => {
+ scrollNodeTo(this.scrollable, this.topSpacerHeight + 50);
+ });
+
+ it('calls the onEnter handler', () => {
+ expect(this.props.onEnter).
+ toHaveBeenCalledWith({
+ currentPosition: Waypoint.inside,
+ previousPosition: Waypoint.above,
+ event: jasmine.any(Event),
+ waypointTop: -40,
+ viewportTop: this.margin,
+ viewportBottom: this.margin + this.parentHeight,
+ });
+ });
+
+ it('does not call the onLeave handler', () => {
+ expect(this.props.onLeave).not.toHaveBeenCalled();
+ });
+ });
+ });
+
describe('when the Waypoint is above the top', () => {
beforeEach(() => {
this.topSpacerHeight = 200;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment