Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed showOn incorrectly skipping an index #1931

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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