Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Commit b2fd9bf

Browse files
author
Timothy Lindvall
committed
Add unit test to cover new functionality. Also destroy HopscotchBubble when a tour ends (we should create a new one for each tour).
1 parent cfc71c6 commit b2fd9bf

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/js/hopscotch.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,9 @@
10891089
utils.addClass(el, 'hopscotch-callout no-number');
10901090
} else {
10911091
currTour = winHopscotch.getCurrTour();
1092-
utils.addClass(el, 'tour-' + currTour.id);
1092+
if(currTour){
1093+
utils.addClass(el, 'tour-' + currTour.id);
1094+
}
10931095
}
10941096

10951097
/**
@@ -1323,6 +1325,19 @@
13231325
return bubble;
13241326
},
13251327

1328+
/**
1329+
* Destroy the bubble currently associated with Hopscotch.
1330+
* This is done when we end the current tour.
1331+
*
1332+
* @private
1333+
*/
1334+
destroyBubble = function() {
1335+
if(bubble){
1336+
bubble.destroy();
1337+
bubble = null;
1338+
}
1339+
},
1340+
13261341
/**
13271342
* Convenience method for getting an option. Returns custom config option
13281343
* or the default config option if no custom value exists.
@@ -1996,6 +2011,7 @@
19962011

19972012
this.removeCallbacks(null, true);
19982013
this.resetDefaultOptions();
2014+
destroyBubble();
19992015

20002016
currTour = null;
20012017

test/js/test.hopscotch.js

+22
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ describe('Hopscotch', function() {
156156
hopscotch.endTour();
157157
});
158158

159+
it('should complain if no tour data is passed in', function(){
160+
expect(function(){
161+
hopscotch.startTour();
162+
}).toThrow(new Error('Tour data is required for startTour.'));
163+
});
164+
159165
it('should reject tour IDs that include invalid characters', function(){
160166
expect(function(){
161167
hopscotch.startTour({
@@ -1285,6 +1291,22 @@ describe('HopscotchBubble', function() {
12851291
expect(content).toBe('It\'s a shopping list');
12861292
hopscotch.endTour();
12871293
});
1294+
1295+
it('Should include tour ID as part of bubble classes', function(){
1296+
hopscotch.startTour({
1297+
id: 'hs-test-tour-class',
1298+
steps: [ {
1299+
target: 'shopping-list',
1300+
placement: 'left',
1301+
title: 'Shopping List',
1302+
content: 'It\'s a shopping list'
1303+
} ]
1304+
});
1305+
bubble = document.querySelector('.hopscotch-bubble.tour-hs-test-tour-class');
1306+
console.log(document.querySelector('.hopscotch-bubble').classList);
1307+
expect(bubble).not.toBe(null);
1308+
hopscotch.endTour();
1309+
});
12881310
});
12891311

12901312
describe('Step Number', function() {

0 commit comments

Comments
 (0)