From 7f0a3043abfa2b1bd64e11d7c7613b4071c40b17 Mon Sep 17 00:00:00 2001 From: liam-jones-lucout <61188949+liam-jones-lucout@users.noreply.github.com> Date: Thu, 26 May 2022 04:41:57 +0100 Subject: [PATCH] fixed showOn incorrectly skipping an index (#1931) * fixed showOn incorrectly skipping an index * moved creation of nextIndex to be just before it's needed --- src/js/tour.js | 5 +++-- test/unit/tour.spec.js | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/js/tour.js b/src/js/tour.js index 91d4ff084..92cb75bbf 100644 --- a/src/js/tour.js +++ b/src/js/tour.js @@ -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); } } diff --git a/test/unit/tour.spec.js b/test/unit/tour.spec.js index f20ef107d..55aa4447b 100644 --- a/test/unit/tour.spec.js +++ b/test/unit/tour.spec.js @@ -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', @@ -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' @@ -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() { @@ -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;