diff --git a/tests/tests.js b/tests/tests.js
index 687cd37f..f78146a9 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -1,591 +1,594 @@
// Generated by CoffeeScript 1.6.1
+(function() {
+
+ module("bootstrap-tour", {
+ teardown: function() {
+ this.tour.setState("current_step", null);
+ this.tour.setState("end", null);
+ return $.each(this.tour._steps, function(i, s) {
+ if ((s.element != null) && (s.element.popover != null)) {
+ return s.element.popover("hide").removeData("popover");
+ }
+ });
+ }
+ });
-module("bootstrap-tour", {
- teardown: function() {
- this.tour.setState("current_step", null);
- this.tour.setState("end", null);
- return $.each(this.tour._steps, function(i, s) {
- if ((s.element != null) && (s.element.popover != null)) {
- return s.element.popover("hide").removeData("popover");
+ test("Tour should set the tour options", function() {
+ this.tour = new Tour({
+ name: "test",
+ afterSetState: function() {
+ return true;
+ },
+ afterGetState: function() {
+ return true;
}
});
- }
-});
-
-test("Tour should set the tour options", function() {
- this.tour = new Tour({
- name: "test",
- afterSetState: function() {
- return true;
- },
- afterGetState: function() {
- return true;
- }
+ equal(this.tour._options.name, "test", "options.name is set");
+ ok(this.tour._options.afterGetState, "options.afterGetState is set");
+ return ok(this.tour._options.afterSetState, "options.afterSetState is set");
});
- equal(this.tour._options.name, "test", "options.name is set");
- ok(this.tour._options.afterGetState, "options.afterGetState is set");
- return ok(this.tour._options.afterSetState, "options.afterSetState is set");
-});
-
-test("Tour should have default name of 'tour'", function() {
- this.tour = new Tour();
- return equal(this.tour._options.name, "tour", "tour default name is 'tour'");
-});
-
-test("Tour should accept an array of steps and set the current step", function() {
- this.tour = new Tour();
- deepEqual(this.tour._steps, [], "tour accepts an array of steps");
- return strictEqual(this.tour._current, 0, "tour initializes current step");
-});
-
-test("Tour.setState should save state cookie", function() {
- this.tour = new Tour();
- this.tour.setState("test", "yes");
- return strictEqual($.cookie("tour_test"), "yes", "tour saves state cookie");
-});
-
-test("Tour.getState should get state cookie", function() {
- this.tour = new Tour();
- this.tour.setState("test", "yes");
- strictEqual(this.tour.getState("test"), "yes", "tour gets state cookie");
- return $.cookie("tour_test", null);
-});
-
-test("Tour.setState should save state localStorage items", function() {
- this.tour = new Tour({
- useLocalStorage: true
- });
- this.tour.setState("test", "yes");
- return strictEqual(window.localStorage.getItem("tour_test"), "yes", "tour save state localStorage items");
-});
-
-test("Tour.getState should get state localStorage items", function() {
- this.tour = new Tour({
- useLocalStorage: true
- });
- this.tour.setState("test", "yes");
- strictEqual(this.tour.getState("test"), "yes", "tour save state localStorage items");
- return window.localStorage.setItem("tour_test", null);
-});
-
-test("Tour.addStep should add a step", function() {
- var step;
- this.tour = new Tour();
- step = {
- element: $("
").appendTo("#qunit-fixture")
- };
- this.tour.addStep(step);
- return deepEqual(this.tour._steps, [step], "tour adds steps");
-});
-
-test("Tour with onStart option should run the callback before showing the first step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour({
- onStart: function() {
- return tour_test += 2;
- }
+
+ test("Tour should have default name of 'tour'", function() {
+ this.tour = new Tour();
+ return equal(this.tour._options.name, "tour", "tour default name is 'tour'");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
+
+ test("Tour should accept an array of steps and set the current step", function() {
+ this.tour = new Tour();
+ deepEqual(this.tour._steps, [], "tour accepts an array of steps");
+ return strictEqual(this.tour._current, 0, "tour initializes current step");
});
- this.tour.start();
- return strictEqual(tour_test, 2, "tour runs onStart when the first step shown");
-});
-test("Tour with onEnd option should run the callback after hiding the last step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour({
- onEnd: function() {
- return tour_test += 2;
- }
+ test("Tour.setState should save state cookie", function() {
+ this.tour = new Tour();
+ this.tour.setState("test", "yes");
+ return strictEqual($.cookie("tour_test"), "yes", "tour saves state cookie");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
+
+ test("Tour.getState should get state cookie", function() {
+ this.tour = new Tour();
+ this.tour.setState("test", "yes");
+ strictEqual(this.tour.getState("test"), "yes", "tour gets state cookie");
+ return $.cookie("tour_test", null);
});
- this.tour.start();
- this.tour.end();
- return strictEqual(tour_test, 2, "tour runs onEnd when the last step hidden");
-});
-test("Tour with onShow option should run the callback before showing the step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour({
- onShow: function() {
- return tour_test += 2;
- }
+ test("Tour.setState should save state localStorage items", function() {
+ this.tour = new Tour({
+ useLocalStorage: true
+ });
+ this.tour.setState("test", "yes");
+ return strictEqual(window.localStorage.getItem("tour_test"), "yes", "tour save state localStorage items");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
+
+ test("Tour.getState should get state localStorage items", function() {
+ this.tour = new Tour({
+ useLocalStorage: true
+ });
+ this.tour.setState("test", "yes");
+ strictEqual(this.tour.getState("test"), "yes", "tour save state localStorage items");
+ return window.localStorage.setItem("tour_test", null);
+ });
+
+ test("Tour.addStep should add a step", function() {
+ var step;
+ this.tour = new Tour();
+ step = {
+ element: $("").appendTo("#qunit-fixture")
+ };
+ this.tour.addStep(step);
+ return deepEqual(this.tour._steps, [step], "tour adds steps");
+ });
+
+ test("Tour with onStart option should run the callback before showing the first step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour({
+ onStart: function() {
+ return tour_test += 2;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ return strictEqual(tour_test, 2, "tour runs onStart when the first step shown");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
+
+ test("Tour with onEnd option should run the callback after hiding the last step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour({
+ onEnd: function() {
+ return tour_test += 2;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.end();
+ return strictEqual(tour_test, 2, "tour runs onEnd when the last step hidden");
});
- this.tour.start();
- strictEqual(tour_test, 2, "tour runs onShow when first step shown");
- this.tour.next();
- return strictEqual(tour_test, 4, "tour runs onShow when next step shown");
-});
-test("Tour with onShown option should run the callback after showing the step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour({
- onShown: function() {
- return tour_test += 2;
- }
+ test("Tour with onShow option should run the callback before showing the step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour({
+ onShow: function() {
+ return tour_test += 2;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ strictEqual(tour_test, 2, "tour runs onShow when first step shown");
+ this.tour.next();
+ return strictEqual(tour_test, 4, "tour runs onShow when next step shown");
+ });
+
+ test("Tour with onShown option should run the callback after showing the step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour({
+ onShown: function() {
+ return tour_test += 2;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ return strictEqual(tour_test, 2, "tour runs onShown after first step shown");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
+
+ test("Tour with onHide option should run the callback before hiding the step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour({
+ onHide: function() {
+ return tour_test += 2;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.next();
+ strictEqual(tour_test, 2, "tour runs onHide when first step hidden");
+ this.tour.hideStep(1);
+ return strictEqual(tour_test, 4, "tour runs onHide when next step hidden");
+ });
+
+ test("Tour with onHidden option should run the callback after hiding the step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour({
+ onHidden: function() {
+ return tour_test += 2;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.next();
+ strictEqual(tour_test, 2, "tour runs onHidden after first step hidden");
+ this.tour.next();
+ return strictEqual(tour_test, 4, "tour runs onHidden after next step hidden");
+ });
+
+ test("Tour.addStep with onShow option should run the callback before showing the step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture"),
+ onShow: function() {
+ return tour_test = 2;
+ }
+ });
+ this.tour.start();
+ strictEqual(tour_test, 0, "tour does not run onShow when step not shown");
+ this.tour.next();
+ return strictEqual(tour_test, 2, "tour runs onShow when step shown");
+ });
+
+ test("Tour.addStep with onHide option should run the callback before hiding the step", function() {
+ var tour_test;
+ tour_test = 0;
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture"),
+ onHide: function() {
+ return tour_test = 2;
+ }
+ });
+ this.tour.start();
+ this.tour.next();
+ strictEqual(tour_test, 0, "tour does not run onHide when step not hidden");
+ this.tour.hideStep(1);
+ return strictEqual(tour_test, 2, "tour runs onHide when step hidden");
+ });
+
+ test("Tour.getStep should get a step", function() {
+ var step;
+ this.tour = new Tour();
+ step = {
+ element: $("").appendTo("#qunit-fixture"),
+ path: "test",
+ placement: "left",
+ title: "Test",
+ content: "Just a test",
+ id: "step-0",
+ prev: -1,
+ next: 2,
+ end: false,
+ animation: false,
+ onShow: function(tour) {},
+ onShown: function(tour) {},
+ onHide: function(tour) {},
+ onHidden: function(tour) {},
+ template: ""
+ };
+ this.tour.addStep(step);
+ return deepEqual(this.tour.getStep(0), step, "tour gets a step");
+ });
+
+ test("Tour.start should start a tour", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ return strictEqual($(".popover").length, 1, "tour starts");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
+
+ test("Tour.start should not start a tour that ended", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.setState("end", "yes");
+ this.tour.start();
+ return strictEqual($(".popover").length, 0, "previously ended tour don't start again");
});
- this.tour.start();
- return strictEqual(tour_test, 2, "tour runs onShown after first step shown");
-});
-test("Tour with onHide option should run the callback before hiding the step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour({
- onHide: function() {
- return tour_test += 2;
- }
+ test("Tour.start(true) should force starting a tour that ended", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.setState("end", "yes");
+ this.tour.start(true);
+ return strictEqual($(".popover").length, 1, "previously ended tour starts again if forced to");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.next();
- strictEqual(tour_test, 2, "tour runs onHide when first step hidden");
- this.tour.hideStep(1);
- return strictEqual(tour_test, 4, "tour runs onHide when next step hidden");
-});
-
-test("Tour with onHidden option should run the callback after hiding the step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour({
- onHidden: function() {
- return tour_test += 2;
- }
+
+ test("Tour.next should hide current step and show next step", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.next();
+ strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 0, "tour hides current step");
+ return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour shows next step");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.next();
- strictEqual(tour_test, 2, "tour runs onHidden after first step hidden");
- this.tour.next();
- return strictEqual(tour_test, 4, "tour runs onHidden after next step hidden");
-});
-
-test("Tour.addStep with onShow option should run the callback before showing the step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture"),
- onShow: function() {
- return tour_test = 2;
- }
+
+ test("Tour.end should hide current step and set end state", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.end();
+ strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 0, "tour hides current step");
+ return strictEqual(this.tour.getState("end"), "yes", "tour sets end state");
});
- this.tour.start();
- strictEqual(tour_test, 0, "tour does not run onShow when step not shown");
- this.tour.next();
- return strictEqual(tour_test, 2, "tour runs onShow when step shown");
-});
-
-test("Tour.addStep with onHide option should run the callback before hiding the step", function() {
- var tour_test;
- tour_test = 0;
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture"),
- onHide: function() {
- return tour_test = 2;
- }
+
+ test("Tour.ended should return true is tour ended and false if not", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ strictEqual(this.tour.ended(), false, "tour returns false if not ended");
+ this.tour.end();
+ return strictEqual(this.tour.ended(), true, "tour returns true if ended");
});
- this.tour.start();
- this.tour.next();
- strictEqual(tour_test, 0, "tour does not run onHide when step not hidden");
- this.tour.hideStep(1);
- return strictEqual(tour_test, 2, "tour runs onHide when step hidden");
-});
-
-test("Tour.getStep should get a step", function() {
- var step;
- this.tour = new Tour();
- step = {
- element: $("").appendTo("#qunit-fixture"),
- path: "test",
- placement: "left",
- title: "Test",
- content: "Just a test",
- id: "step-0",
- prev: -1,
- next: 2,
- end: false,
- animation: false,
- onShow: function(tour) {},
- onShown: function(tour) {},
- onHide: function(tour) {},
- onHidden: function(tour) {},
- template: ""
- };
- this.tour.addStep(step);
- return deepEqual(this.tour.getStep(0), step, "tour gets a step");
-});
-
-test("Tour.start should start a tour", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- return strictEqual($(".popover").length, 1, "tour starts");
-});
-
-test("Tour.start should not start a tour that ended", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.setState("end", "yes");
- this.tour.start();
- return strictEqual($(".popover").length, 0, "previously ended tour don't start again");
-});
-
-test("Tour.start(true) should force starting a tour that ended", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.setState("end", "yes");
- this.tour.start(true);
- return strictEqual($(".popover").length, 1, "previously ended tour starts again if forced to");
-});
-
-test("Tour.next should hide current step and show next step", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.next();
- strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 0, "tour hides current step");
- return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour shows next step");
-});
-
-test("Tour.end should hide current step and set end state", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.end();
- strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 0, "tour hides current step");
- return strictEqual(this.tour.getState("end"), "yes", "tour sets end state");
-});
-
-test("Tour.ended should return true is tour ended and false if not", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- strictEqual(this.tour.ended(), false, "tour returns false if not ended");
- this.tour.end();
- return strictEqual(this.tour.ended(), true, "tour returns true if ended");
-});
-
-test("Tour.restart should clear all states and start tour", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.next();
- this.tour.end();
- this.tour.restart();
- strictEqual(this.tour.getState("end"), null, "tour sets end state");
- strictEqual(this.tour._current, 0, "tour sets first step");
- return strictEqual($(".popover").length, 1, "tour starts");
-});
-
-test("Tour.hideStep should hide a step", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.hideStep(0);
- return strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 0, "tour hides step");
-});
-
-test("Tour.showStep should set a step and show it", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.showStep(1);
- strictEqual(this.tour._current, 1, "tour sets step");
- strictEqual($(".popover").length, 1, "tour shows one step");
- return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour shows correct step");
-});
-
-test("Tour.showStep should not show anything when the step doesn't exist", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.showStep(2);
- return strictEqual($(".popover").length, 0, "tour doesn't show any step");
-});
-
-test("Tour.showStep should skip step when no element is specified", function() {
- this.tour = new Tour();
- this.tour.addStep({});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.showStep(1);
- return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour skips step with no element");
-});
-
-test("Tour.showStep should skip step when element doesn't exist", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: "#tour-test"
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.showStep(1);
- return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour skips step with no element");
-});
-
-test("Tour.showStep should skip step when element is invisible", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture").hide()
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.showStep(1);
- return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour skips step with no element");
-});
-
-test("Tour.setCurrentStep should set the current step", function() {
- this.tour = new Tour();
- this.tour.setCurrentStep(4);
- strictEqual(this.tour._current, 4, "tour sets current step if passed a value");
- this.tour.setState("current_step", 2);
- this.tour.setCurrentStep();
- return strictEqual(this.tour._current, 2, "tour reads current step state if not passed a value");
-});
-
-test("Tour.showNextStep should show the next step", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.showNextStep();
- return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour shows next step");
-});
-
-test("Tour.showPrevStep should show the previous step", function() {
- this.tour = new Tour();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.showStep(1);
- this.tour.showPrevStep();
- return strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 1, "tour shows previous step");
-});
-
-test("Tour.showStep should show multiple step on the same element", function() {
- var element;
- element = $("").appendTo("#qunit-fixture");
- this.tour = new Tour();
- this.tour.addStep({
- element: element
- });
- this.tour.addStep({
- element: element
- });
- this.tour.start();
- strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 1, "tour show the first step");
- this.tour.showNextStep();
- return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour show the second step on the same element");
-});
-
-test("Tour properly verify paths", function() {
- this.tour = new Tour();
- strictEqual(this.tour._redirect(void 0, "/"), false, "don't redirect if no path");
- strictEqual(this.tour._redirect("", "/"), false, "don't redirect if path empty");
- strictEqual(this.tour._redirect("/somepath", "/somepath"), false, "don't redirect if path matches current path");
- strictEqual(this.tour._redirect("/somepath/", "/somepath"), false, "don't redirect if path with slash matches current path");
- strictEqual(this.tour._redirect("/somepath", "/somepath/"), false, "don't redirect if path matches current path with slash");
- strictEqual(this.tour._redirect("/somepath?search=true", "/somepath"), false, "don't redirect if path with query params matches current path");
- strictEqual(this.tour._redirect("/somepath/?search=true", "/somepath"), false, "don't redirect if path with slash and query params matches current path");
- return strictEqual(this.tour._redirect("/anotherpath", "/somepath"), true, "redirect if path doesn't match current path");
-});
-
-test("Tour.getState should return null after Tour.removeState with null value using cookies", function() {
- this.tour = new Tour({
- useLocalStorage: false
- });
- this.tour.setState("test", "test");
- this.tour.removeState("test");
- return strictEqual(this.tour.getState("test"), null, "tour returns null after null setState");
-});
-
-test("Tour.getState should return null after Tour.removeState with null value using localStorage", function() {
- this.tour = new Tour({
- useLocalStorage: true
- });
- this.tour.setState("test", "test");
- this.tour.removeState("test");
- return strictEqual(this.tour.getState("test"), null, "tour returns null after null setState");
-});
-
-test("Tour.removeState should call afterRemoveState callback", function() {
- var sentinel;
- sentinel = false;
- this.tour = new Tour({
- afterRemoveState: function() {
- return sentinel = true;
- }
+
+ test("Tour.restart should clear all states and start tour", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.next();
+ this.tour.end();
+ this.tour.restart();
+ strictEqual(this.tour.getState("end"), null, "tour sets end state");
+ strictEqual(this.tour._current, 0, "tour sets first step");
+ return strictEqual($(".popover").length, 1, "tour starts");
+ });
+
+ test("Tour.hideStep should hide a step", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.hideStep(0);
+ return strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 0, "tour hides step");
});
- this.tour.removeState("current_step");
- return strictEqual(sentinel, true, "removeState calls callback");
-});
-
-test("Tour shouldn't move to the next state until the onShow promise is resolved", function() {
- var deferred;
- this.tour = new Tour();
- deferred = $.Deferred();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture"),
- onShow: function() {
- return deferred;
- }
+
+ test("Tour.showStep should set a step and show it", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.showStep(1);
+ strictEqual(this.tour._current, 1, "tour sets step");
+ strictEqual($(".popover").length, 1, "tour shows one step");
+ return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour shows correct step");
});
- this.tour.start();
- this.tour.next();
- strictEqual(this.tour._current, 0, "tour shows old state until resolving of onShow promise");
- deferred.resolve();
- return strictEqual(this.tour._current, 1, "tour shows new state after resolving onShow promise");
-});
-
-test("Tour shouldn't hide popover until the onHide promise is resolved", function() {
- var deferred;
- this.tour = new Tour();
- deferred = $.Deferred();
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture"),
- onHide: function() {
- return deferred;
- }
+
+ test("Tour.showStep should not show anything when the step doesn't exist", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.showStep(2);
+ return strictEqual($(".popover").length, 0, "tour doesn't show any step");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- this.tour.next();
- strictEqual(this.tour._current, 0, "tour shows old state until resolving of onHide promise");
- deferred.resolve();
- return strictEqual(this.tour._current, 1, "tour shows new state after resolving onShow promise");
-});
-
-test("Tour shouldn't start until the onStart promise is resolved", function() {
- var deferred;
- deferred = $.Deferred();
- this.tour = new Tour({
- onStart: function() {
- return deferred;
- }
+
+ test("Tour.showStep should skip step when no element is specified", function() {
+ this.tour = new Tour();
+ this.tour.addStep({});
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.showStep(1);
+ return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour skips step with no element");
+ });
+
+ test("Tour.showStep should skip step when element doesn't exist", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: "#tour-test"
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.showStep(1);
+ return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour skips step with no element");
+ });
+
+ test("Tour.showStep should skip step when element is invisible", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture").hide()
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.showStep(1);
+ return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour skips step with no element");
+ });
+
+ test("Tour.setCurrentStep should set the current step", function() {
+ this.tour = new Tour();
+ this.tour.setCurrentStep(4);
+ strictEqual(this.tour._current, 4, "tour sets current step if passed a value");
+ this.tour.setState("current_step", 2);
+ this.tour.setCurrentStep();
+ return strictEqual(this.tour._current, 2, "tour reads current step state if not passed a value");
+ });
+
+ test("Tour.showNextStep should show the next step", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.showNextStep();
+ return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour shows next step");
+ });
+
+ test("Tour.showPrevStep should show the previous step", function() {
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.showStep(1);
+ this.tour.showPrevStep();
+ return strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 1, "tour shows previous step");
+ });
+
+ test("Tour.showStep should show multiple step on the same element", function() {
+ var element;
+ element = $("").appendTo("#qunit-fixture");
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: element
+ });
+ this.tour.addStep({
+ element: element
+ });
+ this.tour.start();
+ strictEqual(this.tour.getStep(0).element.data("popover").tip().filter(":visible").length, 1, "tour show the first step");
+ this.tour.showNextStep();
+ return strictEqual(this.tour.getStep(1).element.data("popover").tip().filter(":visible").length, 1, "tour show the second step on the same element");
+ });
+
+ test("Tour properly verify paths", function() {
+ this.tour = new Tour();
+ strictEqual(this.tour._redirect(void 0, "/"), false, "don't redirect if no path");
+ strictEqual(this.tour._redirect("", "/"), false, "don't redirect if path empty");
+ strictEqual(this.tour._redirect("/somepath", "/somepath"), false, "don't redirect if path matches current path");
+ strictEqual(this.tour._redirect("/somepath/", "/somepath"), false, "don't redirect if path with slash matches current path");
+ strictEqual(this.tour._redirect("/somepath", "/somepath/"), false, "don't redirect if path matches current path with slash");
+ strictEqual(this.tour._redirect("/somepath?search=true", "/somepath"), false, "don't redirect if path with query params matches current path");
+ strictEqual(this.tour._redirect("/somepath/?search=true", "/somepath"), false, "don't redirect if path with slash and query params matches current path");
+ return strictEqual(this.tour._redirect("/anotherpath", "/somepath"), true, "redirect if path doesn't match current path");
+ });
+
+ test("Tour.getState should return null after Tour.removeState with null value using cookies", function() {
+ this.tour = new Tour({
+ useLocalStorage: false
+ });
+ this.tour.setState("test", "test");
+ this.tour.removeState("test");
+ return strictEqual(this.tour.getState("test"), null, "tour returns null after null setState");
+ });
+
+ test("Tour.getState should return null after Tour.removeState with null value using localStorage", function() {
+ this.tour = new Tour({
+ useLocalStorage: true
+ });
+ this.tour.setState("test", "test");
+ this.tour.removeState("test");
+ return strictEqual(this.tour.getState("test"), null, "tour returns null after null setState");
+ });
+
+ test("Tour.removeState should call afterRemoveState callback", function() {
+ var sentinel;
+ sentinel = false;
+ this.tour = new Tour({
+ afterRemoveState: function() {
+ return sentinel = true;
+ }
+ });
+ this.tour.removeState("current_step");
+ return strictEqual(sentinel, true, "removeState calls callback");
+ });
+
+ test("Tour shouldn't move to the next state until the onShow promise is resolved", function() {
+ var deferred;
+ this.tour = new Tour();
+ deferred = $.Deferred();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture"),
+ onShow: function() {
+ return deferred;
+ }
+ });
+ this.tour.start();
+ this.tour.next();
+ strictEqual(this.tour._current, 0, "tour shows old state until resolving of onShow promise");
+ deferred.resolve();
+ return strictEqual(this.tour._current, 1, "tour shows new state after resolving onShow promise");
+ });
+
+ test("Tour shouldn't hide popover until the onHide promise is resolved", function() {
+ var deferred;
+ this.tour = new Tour();
+ deferred = $.Deferred();
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture"),
+ onHide: function() {
+ return deferred;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ this.tour.next();
+ strictEqual(this.tour._current, 0, "tour shows old state until resolving of onHide promise");
+ deferred.resolve();
+ return strictEqual(this.tour._current, 1, "tour shows new state after resolving onShow promise");
+ });
+
+ test("Tour shouldn't start until the onStart promise is resolved", function() {
+ var deferred;
+ deferred = $.Deferred();
+ this.tour = new Tour({
+ onStart: function() {
+ return deferred;
+ }
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ this.tour.start();
+ strictEqual($(".popover").length, 0, "Tour does not start before onStart promise is resolved");
+ deferred.resolve();
+ return strictEqual($(".popover").length, 1, "Tour starts after onStart promise is resolved");
+ });
+
+ test("Reflex parameter should change the element cursor to pointer when the step is displayed", function() {
+ var $element;
+ $element = $("").appendTo("#qunit-fixture");
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $element,
+ reflex: true
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ strictEqual($element.css("cursor"), "auto", "Tour doesn't change the element cursor before displaying the step");
+ this.tour.start();
+ strictEqual($element.css("cursor"), "pointer", "Tour change the element cursor to pointer when the step is displayed");
+ this.tour.next();
+ return strictEqual($element.css("cursor"), "auto", "Tour reset the element cursor when the step is hidden");
+ });
+
+ test("Reflex parameter should change the element cursor to pointer when the step is displayed", function() {
+ var $element;
+ $element = $("").appendTo("#qunit-fixture");
+ this.tour = new Tour();
+ this.tour.addStep({
+ element: $element,
+ reflex: true
+ });
+ this.tour.addStep({
+ element: $("").appendTo("#qunit-fixture")
+ });
+ strictEqual($element.css("cursor"), "auto", "Tour doesn't change the element cursor before displaying the step");
+ this.tour.start();
+ strictEqual($element.css("cursor"), "pointer", "Tour change the element cursor to pointer when the step is displayed");
+ this.tour.next();
+ return strictEqual($element.css("cursor"), "auto", "Tour reset the element cursor when the step is hidden");
});
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- this.tour.start();
- strictEqual($(".popover").length, 0, "Tour does not start before onStart promise is resolved");
- deferred.resolve();
- return strictEqual($(".popover").length, 1, "Tour starts after onStart promise is resolved");
-});
-
-test("Reflex parameter should change the element cursor to pointer when the step is displayed", function() {
- var $element;
- $element = $("").appendTo("#qunit-fixture");
- this.tour = new Tour();
- this.tour.addStep({
- element: $element,
- reflex: true
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- strictEqual($element.css("cursor"), "auto", "Tour doesn't change the element cursor before displaying the step");
- this.tour.start();
- strictEqual($element.css("cursor"), "pointer", "Tour change the element cursor to pointer when the step is displayed");
- this.tour.next();
- return strictEqual($element.css("cursor"), "auto", "Tour reset the element cursor when the step is hidden");
-});
-
-test("Reflex parameter should change the element cursor to pointer when the step is displayed", function() {
- var $element;
- $element = $("").appendTo("#qunit-fixture");
- this.tour = new Tour();
- this.tour.addStep({
- element: $element,
- reflex: true
- });
- this.tour.addStep({
- element: $("").appendTo("#qunit-fixture")
- });
- strictEqual($element.css("cursor"), "auto", "Tour doesn't change the element cursor before displaying the step");
- this.tour.start();
- strictEqual($element.css("cursor"), "pointer", "Tour change the element cursor to pointer when the step is displayed");
- this.tour.next();
- return strictEqual($element.css("cursor"), "auto", "Tour reset the element cursor when the step is hidden");
-});
+
+}).call(this);