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

[GH-175] totalSteps should be i18n-ified #182

Merged
merged 1 commit into from
Jun 12, 2015
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
7 changes: 5 additions & 2 deletions src/js/hopscotch.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
unsafe,
currTour,
totalSteps,
totalStepsI18n,
nextBtnText,
isLast,
opts;
Expand All @@ -748,7 +749,8 @@
unsafe = currTour.unsafe;
if(Array.isArray(currTour.steps)){
totalSteps = currTour.steps.length;
isLast = (idx === totalSteps - 1);
totalStepsI18n = this._getStepI18nNum(this._getStepNum(totalSteps - 1));
isLast = (this._getStepNum(idx) === this._getStepNum(totalSteps - 1));
}
}
}else{
Expand Down Expand Up @@ -778,7 +780,8 @@
prevBtn: utils.getI18NString('prevBtn'),
nextBtn: nextBtnText,
closeTooltip: utils.getI18NString('closeTooltip'),
stepNum: this._getStepI18nNum(this._getStepNum(idx))
stepNum: this._getStepI18nNum(this._getStepNum(idx)),
numSteps: totalStepsI18n
},
buttons:{
showPrev: (utils.valOrDefault(step.showPrevButton, this.opt.showPrevButton) && (this._getStepNum(idx) > 0)),
Expand Down
84 changes: 53 additions & 31 deletions test/js/test.hopscotch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,35 +1155,44 @@ describe('Hopscotch', function() {

describe('Custom render methods', function(){
var mockTour = {
id: 'hopscotch-test-tour',
steps: [
{
target: 'shopping-list',
placement: 'left',
title: 'Shopping List',
content: 'It\'s a shopping list'
},
{
target: 'shopping-list',
placement: 'left',
title: 'Shopping List',
content: 'It\'s a shopping list'
}
],
skipIfNoElement: false
},
mockCallout = {
id: 'shopping-callout',
target: 'shopping-list',
placement: 'left',
title: 'Shopping List Callout',
content: 'It\'s a shopping list'
},
customRenderer = {
render: function(){
return '<h1>Content!</h1><div class="hopscotch-arrow"></div>';
id: 'hopscotch-test-tour',
steps: [
{
target: 'shopping-list',
placement: 'left',
title: 'Shopping List',
content: 'It\'s a shopping list'
},
{
target: 'i-do-not-exist',
placement: 'left',
title: 'Not there',
content: 'Not there at all'
},
{
target: 'shopping-list',
placement: 'left',
title: 'Shopping List',
content: 'Back to the shopping list'
}
};
],
i18n : {
stepNums : ['one', 'two', 'three', 'four', 'five']
}
},
mockCallout = {
id: 'shopping-callout',
target: 'shopping-list',
placement: 'left',
title: 'Shopping List Callout',
content: 'It\'s a shopping list'
},
customRenderer = {
render: function(){
return '<h1>Content!</h1><div class="hopscotch-arrow"></div>';
}
},
args;

beforeEach(function(){
hopscotch.templates.customTemplate = function(){
Expand All @@ -1199,15 +1208,28 @@ describe('Hopscotch', function() {
hopscotch.getCalloutManager().removeAllCallouts();
hopscotch.setRenderer('bubble_default');
delete hopscotch.templates.customTemplate;
hopscotch.resetDefaultI18N();

});

it('setRenderer() should allow setting a global renderer within the hopscotch.templates namespace', function(){
hopscotch.setRenderer('customTemplate');

hopscotch.startTour(mockTour);
expect(hopscotch.templates.customTemplate.calls.count()).toEqual(1);
expect(customRenderer.render).not.toHaveBeenCalled();
expect(hopscotch.templates.bubble_default).not.toHaveBeenCalled();
args = hopscotch.templates.customTemplate.calls.argsFor(0);
expect(args[0].i18n.numSteps).toEqual("three");
expect(args[0].step.isLast).toEqual(false);
expect(customRenderer.render.calls.count()).toEqual(0);
expect(hopscotch.templates.bubble_default.calls.count()).toEqual(0);

//go to step 3, since step 2 does not exist
hopscotch.nextStep();
expect(hopscotch.templates.customTemplate.calls.count()).toEqual(2);

args = hopscotch.templates.customTemplate.calls.argsFor(1);
//we skipped one step, so num of steps should go down to two
expect(args[0].i18n.numSteps).toEqual("two");
expect(args[0].step.isLast).toEqual(true);

hopscotch.endTour();
hopscotch.templates.customTemplate.calls.reset();
Expand Down