Skip to content

Commit

Permalink
fixed showOn incorrectly skipping an index (#1931)
Browse files Browse the repository at this point in the history
* fixed showOn incorrectly skipping an index

* moved creation of nextIndex to be just before it's needed
  • Loading branch information
liam-jones-lucout authored May 26, 2022
1 parent 32e713f commit 7f0a304
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/js/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ export class Tour extends Evented {
*/
_skipStep(step, forward) {
const index = this.steps.indexOf(step);
const nextIndex = forward ? index + 1 : index - 1;
if (nextIndex === this.steps.length - 1) {

if (index === this.steps.length - 1) {
this.complete();
} else {
const nextIndex = forward ? index + 1 : index - 1;
this.show(nextIndex, forward);
}
}
Expand Down
19 changes: 11 additions & 8 deletions test/unit/tour.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ describe('Tour | Top-Level Class', function() {
title: 'This is a test step for our tour'
});


instance.addStep({
id: 'test2',
title: 'Another Step'
});

instance.addStep({
classes: 'skipped',
id: 'skipped-step',
Expand All @@ -107,11 +113,6 @@ describe('Tour | Top-Level Class', function() {
}
});

instance.addStep({
id: 'test2',
title: 'Another Step'
});

instance.addStep({
id: 'test3',
title: 'Yet, another test step'
Expand All @@ -125,13 +126,13 @@ describe('Tour | Top-Level Class', function() {
});

it('adds tour steps at specified index', function() {
expect(instance.steps[2].options.id, 'original step at index 2').toBe('test2');
expect(instance.steps[1].options.id, 'original step at index 1').toBe('test2');
instance.addStep({
id: 'index-test',
title: 'Test index insertion'
}, 2);
}, 1);
expect(instance.steps.length).toBe(5);
expect(instance.steps[2].options.id, 'step inserted at index 2').toBe('index-test');
expect(instance.steps[1].options.id, 'step inserted at index 1').toBe('index-test');
});

it('adds steps with only one arg', function() {
Expand Down Expand Up @@ -400,6 +401,8 @@ describe('Tour | Top-Level Class', function() {
expect(instance.getCurrentStep().id).toBe('test');
instance.next();
expect(instance.getCurrentStep().id).toBe('test2');
instance.next();
expect(instance.getCurrentStep().id).toBe('test3');
expect(instance.getCurrentStep().id, 'step skipped because `showOn` returns false').not.toBe('skipped-step');
instance.back();
shouldShowStep = true;
Expand Down

0 comments on commit 7f0a304

Please sign in to comment.