1 describe("Tocify jQuery Plugin", function () {
5 beforeEach(function() {
7 loadFixtures("tocifyFixture.html");
9 toc = $("#toc").tocify({ context: ".documentation", selectors: "h1, h3, h4" });
13 describe("Generating the table of contents", function() {
15 it("should show all headers", function() {
17 expect($(".header")).toBeVisible();
21 it("should hide all subheaders", function() {
23 expect($(".sub-header")).toBeHidden();
29 describe("Table of Contents Event Handlers", function() {
31 it("should show all first-level child subheaders when a header class item is clicked", function() {
33 $(".header").first().click();
35 //expect($(".header").children(".subHeader")).toBeVisible();
41 describe("Hash generation", function(){
43 it("Should add an index if there are duplicate values", function(){
45 loadFixtures("tocifyFixture.html");
47 // set all H1s to the same text
48 $("h1").text("The same value");
50 toc = $("#toc").tocify({ hashGenerator: "pretty", context: ".documentation", selectors: "h1, h3, h4" });
52 expect($("h1.getting-started-test-marker").eq(0).prev("div").eq(0).attr("name")).toBe("the-same-value3");
56 it("Should default to 'original'", function(){
57 expect(toc.data("tocify").options["hashGenerator"]).toBe("compact");
60 it("Should support the 'pretty' hashGenerator option", function(){
62 loadFixtures("tocifyFixture.html");
63 toc = $("#toc").tocify({ hashGenerator: "pretty", context: ".documentation", selectors: "h1, h3, h4" });
64 expect($("h1.getting-started-test-marker").eq(0).prev("div").eq(0).attr("name")).toBe("getting-started");
68 it("Should fix double hyphens in the 'pretty' hashGenerator option", function(){
70 loadFixtures("tocifyFixture.html");
71 $("h1.getting-started-test-marker").text("Getting started")
72 toc = $("#toc").tocify({ hashGenerator: "pretty", context: ".documentation", selectors: "h1, h3, h4" });
73 expect($("h1.getting-started-test-marker").eq(0).prev("div").eq(0).attr("name")).toBe("getting-started");
77 it("Should support a function hashGenerator option", function(){
79 loadFixtures("tocifyFixture.html");
82 toc = $("#toc").tocify({ hashGenerator: function(text, element){
87 // return a test value
88 return text + "(TEST)";
90 }, context: ".documentation", selectors: "h1, h3, h4" });
92 expect($("h1.getting-started-test-marker").eq(0).prev("div").eq(0).attr("name")).toBe($("h1.getting-started-test-marker").text() + "(TEST)");
94 // check the correct arguments were passed to the function too
97 expect(args[0][0], $("h1.getting-started-test-marker").text());
100 expect(args[0][1].attr("class"), "getting-started-test-marker");