Skip to content

Commit

Permalink
Covering the case in which a target element is beyond a sticky footer
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicola committed Jan 27, 2019
1 parent 4f58c4a commit 4249dc4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/lib/src/services/joyride-step.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('JoyrideStepService', () => {
let STEP1: any = new JoyrideStep();
let STEP2: any = new JoyrideStep();
let FAKE_WINDOW: { innerHeight: number; scrollTo: jasmine.Spy };
let FAKE_DOCUMENT: { body: { scrollHeight: number } };

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -52,7 +53,9 @@ describe('JoyrideStepService', () => {
beforeEach(() => {
domRefService = TestBed.get(DomRefService);
FAKE_WINDOW = { innerHeight: 200, scrollTo: jasmine.createSpy('scrollTo') };
FAKE_DOCUMENT = { body: { scrollHeight: 106 } };
domRefService.getNativeWindow.and.returnValue(FAKE_WINDOW);
domRefService.getNativeDocument.and.returnValue(FAKE_DOCUMENT);

joyrideStepService = TestBed.get(JoyrideStepService);
eventListenerService = TestBed.get(EventListenerService);
Expand Down Expand Up @@ -216,7 +219,7 @@ describe('JoyrideStepService', () => {

describe('when documentService.isElementBeyondOthers returns true', () => {
beforeEach(fakeAsync(() => {
documentService.isElementBeyondOthers.and.returnValue(true);
documentService.isElementBeyondOthers.and.returnValues(true, false);
joyrideStepService.startTour();
tick(1);
}));
Expand All @@ -239,9 +242,37 @@ describe('JoyrideStepService', () => {
}));
});

describe('when documentService.isElementBeyondOthers returns false', () => {
describe('when documentService.isElementBeyondOthers returns true twice', () => {
beforeEach(fakeAsync(() => {
documentService.isElementBeyondOthers.and.returnValue(false);
documentService.isElementBeyondOthers.and.returnValues(true, true);
joyrideStepService.startTour();
tick(1);
}));
it('should scroll to 0, 0 and then to the bottom when startTour() is called ', () => {
expect(FAKE_WINDOW.scrollTo.calls.argsFor(0)).toEqual([0, 0]);
expect(FAKE_WINDOW.scrollTo.calls.argsFor(1)).toEqual([0, FAKE_DOCUMENT.body.scrollHeight]);
});
it('should scroll to 0, 0 and then to the bottom when prev() is called ', fakeAsync(() => {
joyrideStepService.next();
tick(1);
joyrideStepService.prev();
tick(1);

expect(FAKE_WINDOW.scrollTo.calls.argsFor(0)).toEqual([0, 0]);
expect(FAKE_WINDOW.scrollTo.calls.argsFor(1)).toEqual([0, FAKE_DOCUMENT.body.scrollHeight]);
}));
it('should scroll to 0, 0 and then to the bottom when next() is called ', fakeAsync(() => {
joyrideStepService.next();
tick(1);

expect(FAKE_WINDOW.scrollTo.calls.argsFor(0)).toEqual([0, 0]);
expect(FAKE_WINDOW.scrollTo.calls.argsFor(1)).toEqual([0, FAKE_DOCUMENT.body.scrollHeight]);
}));
});

describe('when documentService.isElementBeyondOthers returns false twice', () => {
beforeEach(fakeAsync(() => {
documentService.isElementBeyondOthers.and.returnValues(false, false);
joyrideStepService.startTour();
tick(1);
}));
Expand Down
9 changes: 9 additions & 0 deletions src/lib/src/services/joyride-step.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,14 @@ export class JoyrideStepService implements IJoyrideStepService {
) {
this.DOMService.getNativeWindow().scrollTo(0, 0);
}

if (
this.documentService.isElementBeyondOthers(
this.currentStep.targetViewContainer.element,
this.currentStep.isElementOrAncestorFixed
)
) {
this.DOMService.getNativeWindow().scrollTo(0, this.DOMService.getNativeDocument().body.scrollHeight);
}
}
}

0 comments on commit 4249dc4

Please sign in to comment.