Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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