Style changes for the Use cases.
[yaffs-website] / web / libraries / jquery.tocify.js-master / test / spec / tocifySpec.js
1 describe("Tocify jQuery Plugin", function () {
2
3     var toc;
4
5         beforeEach(function() {
6
7         loadFixtures("tocifyFixture.html");
8
9         toc = $("#toc").tocify({ context: ".documentation", selectors: "h1, h3, h4" });
10
11         });
12
13         describe("Generating the table of contents", function() {
14
15         it("should show all headers", function() {
16
17             expect($(".header")).toBeVisible();
18
19         });
20
21         it("should hide all subheaders", function() {
22
23             expect($(".sub-header")).toBeHidden();
24
25         });
26
27     });
28
29     describe("Table of Contents Event Handlers", function() {
30
31         it("should show all first-level child subheaders when a header class item is clicked", function() {
32
33             $(".header").first().click();
34
35             //expect($(".header").children(".subHeader")).toBeVisible();
36
37         });
38     
39     });
40
41     describe("Hash generation", function(){
42
43         it("Should add an index if there are duplicate values", function(){
44
45             loadFixtures("tocifyFixture.html");
46
47             // set all H1s to the same text
48             $("h1").text("The same value");
49
50             toc = $("#toc").tocify({ hashGenerator: "pretty", context: ".documentation", selectors: "h1, h3, h4" });
51
52             expect($("h1.getting-started-test-marker").eq(0).prev("div").eq(0).attr("name")).toBe("the-same-value3");
53
54         });
55
56         it("Should default to 'original'", function(){
57             expect(toc.data("tocify").options["hashGenerator"]).toBe("compact");
58         });
59
60         it("Should support the 'pretty' hashGenerator option", function(){
61
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");
65
66         });
67
68         it("Should fix double hyphens in the 'pretty' hashGenerator option", function(){
69
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");
74
75         });
76
77         it("Should support a function hashGenerator option", function(){
78
79             loadFixtures("tocifyFixture.html");
80             var args = [];
81
82             toc = $("#toc").tocify({ hashGenerator: function(text, element){
83
84                 // record this call
85                 args.push(arguments);
86
87                 // return a test value
88                 return text + "(TEST)";
89
90             }, context: ".documentation", selectors: "h1, h3, h4" });
91       
92             expect($("h1.getting-started-test-marker").eq(0).prev("div").eq(0).attr("name")).toBe($("h1.getting-started-test-marker").text() + "(TEST)");
93             
94             // check the correct arguments were passed to the function too
95
96             // text
97             expect(args[0][0], $("h1.getting-started-test-marker").text());
98
99             // element
100             expect(args[0][1].attr("class"), "getting-started-test-marker");
101
102         });
103
104     });
105
106 });