|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | + |
| 3 | +<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" |
| 4 | + xmlns:functx="http://www.functx.com" |
| 5 | + xmlns="http://www.w3.org/1999/xhtml" |
| 6 | + xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/" |
| 7 | + xmlns:h="http://www.w3.org/1999/xhtml" |
| 8 | + xmlns:e="http://github.com/oreillymedia/epubrenderer" |
| 9 | + stylesheet="../htmlbook.xsl"> |
| 10 | + |
| 11 | + <x:param name="autogenerate-toc" select="0"/> |
| 12 | + <x:param name="toc-placeholder-overwrite-contents" select="0"/> |
| 13 | + |
| 14 | + <x:scenario label="When *empty* TOC nav element is matched"> |
| 15 | + <x:context select="(//h:nav)[1]"> |
| 16 | + <body> |
| 17 | + <nav data-type="toc"/> |
| 18 | + <section id="chapter" data-type="chapter"> |
| 19 | + <h1>This chapter head should be in TOC</h1> |
| 20 | + <p>Go TOC!</p> |
| 21 | + </section> |
| 22 | + </body> |
| 23 | + </x:context> |
| 24 | + |
| 25 | + <x:scenario label="And autogenerate-toc param is *disabled*"> |
| 26 | + <x:context> |
| 27 | + <x:param name="autogenerate-toc" select="0"/> |
| 28 | + </x:context> |
| 29 | + <x:expect label="TOC content *should not* be generated (nav should stay empty)"> |
| 30 | + <nav data-type="toc" id="..."/> |
| 31 | + </x:expect> |
| 32 | + </x:scenario> |
| 33 | + |
| 34 | + <x:scenario label="And autogenerate-toc param is *enabled*"> |
| 35 | + <x:context> |
| 36 | + <x:param name="autogenerate-toc" select="1"/> |
| 37 | + </x:context> |
| 38 | + <x:expect label="TOC content should be generated" |
| 39 | + test="count(h:nav[.//h:li[contains(., 'This chapter head should be in TOC')]]) = 1"/> |
| 40 | + </x:scenario> |
| 41 | + |
| 42 | + </x:scenario> |
| 43 | + |
| 44 | + <x:scenario label="When *nonempty* TOC nav element is matched"> |
| 45 | + <x:context select="(//h:nav)[1]"> |
| 46 | + <body> |
| 47 | + <nav data-type="toc"> |
| 48 | + <h1>Manual TOC</h1> |
| 49 | + <ol> |
| 50 | + <li>Entry 1</li> |
| 51 | + <li>Entry 2</li> |
| 52 | + <li>Entry 3</li> |
| 53 | + </ol> |
| 54 | + </nav> |
| 55 | + <section data-type="chapter"> |
| 56 | + <h1>This chapter head should be in TOC</h1> |
| 57 | + <p>Go TOC!</p> |
| 58 | + </section> |
| 59 | + </body> |
| 60 | + </x:context> |
| 61 | + |
| 62 | + <x:scenario label="And autogenerate-toc param is *disabled*"> |
| 63 | + <x:context> |
| 64 | + <x:param name="autogenerate-toc" select="0"/> |
| 65 | + </x:context> |
| 66 | + <!-- Same as in context above, plus autogenerated id --> |
| 67 | + <x:expect label="TOC content *should not* be generated (nav content left as is)"> |
| 68 | + <nav id="..." data-type="toc"> |
| 69 | + <h1>Manual TOC</h1> |
| 70 | + <ol> |
| 71 | + <li>Entry 1</li> |
| 72 | + <li>Entry 2</li> |
| 73 | + <li>Entry 3</li> |
| 74 | + </ol> |
| 75 | + </nav> |
| 76 | + </x:expect> |
| 77 | + </x:scenario> |
| 78 | + |
| 79 | + <x:scenario label="And autogenerate-toc param is *enabled*, but toc-placeholder-overwrite-contents is *disabled*"> |
| 80 | + <x:context> |
| 81 | + <x:param name="autogenerate-toc" select="1"/> |
| 82 | + <x:param name="toc-placeholder-overwrite-contents" select="0"/> |
| 83 | + </x:context> |
| 84 | + <!-- Same as in context above, plus autogenerated id --> |
| 85 | + <x:expect label="TOC content *should not* be generated (nav content left as is)"> |
| 86 | + <nav id="..." data-type="toc"> |
| 87 | + <h1>Manual TOC</h1> |
| 88 | + <ol> |
| 89 | + <li>Entry 1</li> |
| 90 | + <li>Entry 2</li> |
| 91 | + <li>Entry 3</li> |
| 92 | + </ol> |
| 93 | + </nav> |
| 94 | + </x:expect> |
| 95 | + </x:scenario> |
| 96 | + |
| 97 | + <x:scenario label="And autogenerate-toc param is *enabled*, and toc-placeholder-overwrite-contents is *enabled*"> |
| 98 | + <x:context> |
| 99 | + <x:param name="autogenerate-toc" select="1"/> |
| 100 | + <x:param name="toc-placeholder-overwrite-contents" select="1"/> |
| 101 | + </x:context> |
| 102 | + <x:expect label="TOC content *should* be generated (nav content overwritten)" |
| 103 | + test="count(h:nav[.//h:li[contains(., 'This chapter head should be in TOC')]]) = 1 and |
| 104 | + not(exists(h:nav//h:h1[contains(., 'Manual TOC')]))"/> |
| 105 | + </x:scenario> |
| 106 | + </x:scenario> |
| 107 | + |
| 108 | + <x:scenario label="When there are multiple empty TOC nav elements"> |
| 109 | + <x:context select="//h:nav"> |
| 110 | + <body> |
| 111 | + <nav data-type="toc"/> |
| 112 | + <nav data-type="toc"/> |
| 113 | + </body> |
| 114 | + <section data-type="chapter"> |
| 115 | + <h1>This chapter head should be in TOC</h1> |
| 116 | + <p>Go TOC!</p> |
| 117 | + </section> |
| 118 | + <x:param name="autogenerate-toc" select="1"/> |
| 119 | + </x:context> |
| 120 | + <x:expect label="Process them all the same way" |
| 121 | + test="deep-equal(//h:nav[@data-type='toc'][1]/node(), //h:nav[@data-type='toc'][2]/node())"/> |
| 122 | + </x:scenario> |
| 123 | + |
| 124 | + <x:scenario label="When a TOC is generated with a scope specified"> |
| 125 | + <x:context href="skeleton.html" select="(//h:nav[@data-type='toc'])[1]"> |
| 126 | + <x:param name="autogenerate-toc" select="1"/> |
| 127 | + <x:param name="scope" select="(document('../skeleton.html')//h:section[@data-type='sect1'])[1]"/> |
| 128 | + </x:context> |
| 129 | + <x:expect label="Root of TOC list should be the scope root"> |
| 130 | + <nav data-type="toc" id="..."> |
| 131 | + <ol> |
| 132 | + <li data-type="sect1">...</li> |
| 133 | + </ol> |
| 134 | + </nav> |
| 135 | + </x:expect> |
| 136 | + </x:scenario> |
| 137 | + |
| 138 | + <x:scenario label="When a standard book-level section (chapter) is matched in tocgen mode"> |
| 139 | + <x:context href="skeleton.html" select="(//h:section[@data-type='chapter'])[1]" mode="tocgen"/> |
| 140 | + <x:expect label="An entry 'li' should be generated"> |
| 141 | + <li data-type="chapter"><a href="...">...</a>...</li> |
| 142 | + </x:expect> |
| 143 | + </x:scenario> |
| 144 | + |
| 145 | + <x:scenario label="When a standard book-level section (part) is matched in tocgen mode"> |
| 146 | + <x:context href="skeleton.html" select="(//h:div[@data-type='part'])[1]" mode="tocgen"/> |
| 147 | + <x:expect label="An entry 'li' should be generated"> |
| 148 | + <li data-type="part"><a href="...">...</a>...</li> |
| 149 | + </x:expect> |
| 150 | + </x:scenario> |
| 151 | + |
| 152 | + <x:scenario label="When a subsection within the toc.section.depth is matched in tocgen mode"> |
| 153 | + <x:context href="skeleton.html" select="(//h:section[@data-type='sect1'])[1]" mode="tocgen"> |
| 154 | + <x:param name="toc.section.depth" select="1"/> |
| 155 | + </x:context> |
| 156 | + <x:expect label="An entry 'li' should be generated"> |
| 157 | + <li data-type="sect1"><a href="...">...</a></li> |
| 158 | + </x:expect> |
| 159 | + </x:scenario> |
| 160 | + |
| 161 | + <x:scenario label="When a subsection at greater depth than the toc.section.depth is matched in tocgen mode"> |
| 162 | + <x:context href="skeleton.html" select="(//h:section[@data-type='sect2'])[1]" mode="tocgen"> |
| 163 | + <x:param name="toc.section.depth" select="1"/> |
| 164 | + </x:context> |
| 165 | + <x:expect label="An entry 'li' *should not* be generated" select="()"/> |
| 166 | + </x:scenario> |
| 167 | + |
| 168 | + <x:scenario label="When a nonsection is matched in tocgen mode"> |
| 169 | + <x:context href="skeleton.html" select="(//h:p)[1]" mode="tocgen"/> |
| 170 | + <x:expect label="An entry 'li' *should not* be generated" select="()"/> |
| 171 | + </x:scenario> |
| 172 | + |
| 173 | + <x:scenario label="When toc-title is called for English-language content (default)"> |
| 174 | + <x:call template="toc-title"/> |
| 175 | + <x:expect label="it should return the proper TOC title">Table of Contents</x:expect> |
| 176 | + </x:scenario> |
| 177 | + |
| 178 | + <x:pending> |
| 179 | + <x:scenario label="When toc-title is called for non-English-language content"> |
| 180 | + <!-- For this test, would need to further parameterize get-localization-value so that you could grab a different localization for the test --> |
| 181 | + <x:call template="toc-title"/> |
| 182 | + <x:expect label="it should return the proper TOC title"/> |
| 183 | + </x:scenario> |
| 184 | + </x:pending> |
| 185 | +</x:description> |
0 commit comments