@@ -41,6 +41,12 @@ class SiteGeneratationTest:
4141 val found = d.select(selector).eachText.asScala
4242 assertEquals(niceMsg(s " Context does not match for ' $selector' " ), expected.toList, found.toList)
4343
44+ def assertAttr (selector : String , attr : String , expected : String * ) =
45+ assertFalse(niceMsg(" Selector not found" ), d.select(selector).isEmpty)
46+ val found = d.select(selector).eachAttr(attr).asScala
47+ assertEquals(niceMsg(s " Attribute $attr does not match for ' $selector' " ), expected.toList, found.toList)
48+
49+
4450 def withHtmlFile (path : Path )(op : DocumentContext => Unit ) = {
4551 assertTrue(s " File at $path does not exisits! " , Files .exists(path))
4652 val content = new String (Files .readAllBytes(path), Charset .defaultCharset())
@@ -51,21 +57,29 @@ class SiteGeneratationTest:
5157 @ Test
5258 def basicTest () = withGeneratedSite(testDocPath.resolve(" basic" )){ dest =>
5359
54- def checkFile (path : String )(title : String , header : String , parents : Seq [String ] = Nil ) =
55- withHtmlFile(dest.resolve(path)){ content =>
56- content.assertTextsIn(" .projectName" , projectName)
57- content.assertTextsIn(" .projectVersion" , projectVersion)
58- content.assertTextsIn(" h1" , header)
59- content.assertTextsIn(" title" , title)
60- content.assertTextsIn(" .breadcrumbs a" , (parents :+ title):_* )
61- }
60+ def checkFile (path : String )(
61+ title : String ,
62+ header : String ,
63+ parents : Seq [String ] = Nil ,
64+ checks : DocumentContext => Unit = _ => ()) =
65+ withHtmlFile(dest.resolve(path)){ content =>
66+ content.assertTextsIn(" .projectName" , projectName)
67+ content.assertTextsIn(" .projectVersion" , projectVersion)
68+ content.assertTextsIn(" h1" , header)
69+ content.assertTextsIn(" title" , title)
70+ content.assertTextsIn(" .breadcrumbs a" , (parents :+ title):_* )
71+ checks(content)
72+ }
6273
63- checkFile(" index.html" )(title = " Basic test" , header = " Header" , parents = Seq (projectName))
74+ def indexLinks (content : DocumentContext ) =
75+ content.assertAttr(" p a" ," href" , " docs/index.html" ," docs/index.html" )
76+
77+ checkFile(" index.html" )(title = " Basic test" , header = " Header" , parents = Seq (projectName), indexLinks)
6478 checkFile(" docs/Adoc.html" )(title = " Adoc" , header = " Header in Adoc" , parents = Seq (projectName))
6579 checkFile(" docs/Adoc.html" )(title = " Adoc" , header = " Header in Adoc" , parents = Seq (projectName))
6680 checkFile(" docs/dir/index.html" )(title = " A directory" , header = " A directory" , parents = Seq (projectName))
6781 checkFile(" docs/dir/nested.html" )(
6882 title = " Nested in a directory" , header = " Nested in a directory" , parents = Seq (projectName, " A directory" ))
6983
7084 checkFile(" docs/index.html" )(title = projectName, header = s " $projectName in header " )
71- }
85+ }
0 commit comments