Commit 875b1fdc authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Improve testsuite for GuideToc.

Add tests for --guides-toc-level=1, 2, 3.
parent fde61a89
Loading
Loading
Loading
Loading
+106 −56
Original line number Diff line number Diff line
@@ -4,9 +4,24 @@ require "jsduck/guide_toc"
describe JsDuck::GuideToc do

  def inject(html)
    JsDuck::GuideToc.inject(html, "myguide", 2)
    JsDuck::GuideToc.inject(html, "myguide", max_level)
  end

  describe "With max_level=1" do
    let(:max_level) { 2 }

    it "adds no toc section even when many H1 headings" do
      inject(<<-EOHTML).should_not =~ /<div class='toc'>/
        <h1>Chapter A</h2>
        <h1>Chapter B</h2>
        <h1>Chapter C</h2>
      EOHTML
    end
  end

  describe "With max_level=2" do
    let(:max_level) { 2 }

    it "adds no toc section when no headings" do
      inject("blah").should_not =~ /<div class='toc'>/
    end
@@ -75,5 +90,40 @@ describe JsDuck::GuideToc do
        <h5>Another Chapter</h5>
      EOHTML
    end
  end

  describe "With max_level=3" do
    let(:max_level) { 3 }

    it "adds TOC when one H2 heading and one H3 heading" do
      inject(<<-EOHTML).should =~ /<div class='toc'>/
        <h2>Chapter A</h2>
        <h3>Chapter A.A</h3>
      EOHTML
    end

    it "adds TOC when two H3 headings" do
      inject(<<-EOHTML).should =~ /<div class='toc'>/
        <h3>Chapter A.A</h3>
        <h3>Chapter A.B</h3>
      EOHTML
    end

    it "links H3 heading from TOC" do
      inject(<<-EOHTML).should =~ /<a href='#!\/guide\/myguide-section-h3-chapter'>/
        <h2>My Chapter</h2>
        <h3>H3 Chapter</h3>
      EOHTML
    end

    it "doesn't include any other headings besides H2 and H3 to TOC" do
      inject(<<-EOHTML).should_not =~ /<a href='#!\/guide\/myguide-section-my-chapter'>/
        <h2>Foo</h2>
        <h3>Bar</h3>
        <h4>My Chapter</h4>
        <h5>Another Chapter</h5>
      EOHTML
    end
  end

end