Skip to content

Commit

Permalink
(#38) Allow to navigate back once the tour start with a specific test
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicola committed Mar 6, 2019
1 parent e7ba0ee commit 3bc37c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/lib/src/services/joyride-steps-container.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ describe('JoyrideStepsContainerService', () => {

expect(joyrideStepsContainerService.getStepsCount()).toBe(3);
});

it('should return the number of steps passed by optionService even if the tour start with another step', () => {
joyrideOptionsService.getStepsOrder.and.returnValue(['one', 'two', 'three']);
joyrideOptionsService.getFirstStep.and.returnValue('two');

expect(joyrideStepsContainerService.getStepsCount()).toBe(3);
});
});

describe('updatePosition', () => {
Expand Down Expand Up @@ -164,7 +171,7 @@ describe('JoyrideStepsContainerService', () => {
joyrideStepsContainerService.get(StepActionType.NEXT);
joyrideStepsContainerService.get(StepActionType.NEXT);
joyrideStepsContainerService.get(StepActionType.NEXT);

expect(() => joyrideStepsContainerService.get(StepActionType.NEXT)).toThrowError(
'The first or last step of the tour cannot be found!'
);
Expand Down Expand Up @@ -194,10 +201,6 @@ describe('JoyrideStepsContainerService', () => {
);
});
});

it('', () => {});
it('', () => {});
it('', () => {});
});

describe('addStep', () => {
Expand Down Expand Up @@ -230,15 +233,15 @@ describe('JoyrideStepsContainerService', () => {
expect(joyrideStepsContainerService.getStepNumber(STEP3.name)).toBe(3);
});

it('should return 1 for the stepPosition of the first step selected in the options', () => {
it('should return 3 for the stepPosition of the first step selected in the options', () => {
joyrideOptionsService.getFirstStep.and.returnValue('third');
setSteps(['firstStep', 'second', 'third', 'fourth']);

expect(joyrideStepsContainerService.getStepNumber(STEP3.name)).toBe(1);
expect(joyrideStepsContainerService.getStepNumber(STEP3.name)).toBe(3);
});
});

describe('getStepRoute()', () => {
describe('getStepRoute', () => {
beforeEach(() => {
joyrideOptionsService.getStepsOrder.and.returnValue(['step1@url1', 'step2@url2', 'step3@url3']);
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/src/services/joyride-steps-container.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ export class JoyrideStepsContainerService {
}
}
getStepNumber(stepName: string): number {
return this.getStepIndex(stepName) - this.getFirstStepIndex() + 1;
return this.getStepIndex(stepName) + 1;
}

getStepsCount() {
let stepsOrder = this.stepOptions.getStepsOrder();
return stepsOrder.length - this.getFirstStepIndex();
return stepsOrder.length;
}

private getStepIndex(stepName: string): number {
Expand Down

0 comments on commit 3bc37c8

Please sign in to comment.