1+ package dotty .dokka
2+ package site
3+
4+ import java .nio .file .Files
5+ import java .nio .file .Path
6+ import java .nio .file .Paths
7+ import org .junit .Test
8+ import org .junit .Assert ._
9+ import org .jsoup .Jsoup
10+ import org .jsoup .nodes .Document
11+ import java .nio .charset .Charset
12+
13+
14+ class SiteGeneratationTest :
15+ val projectName = " Test Project Name"
16+ val projectTitle = " Test Project Title"
17+ val projectVersion = " 1.0.1-M1"
18+
19+ private def withGeneratedSite (base : Path )(op : Path => Unit ) =
20+ val dest = Files .createTempDirectory(" test-doc" )
21+ try
22+ val args = Args (
23+ name = projectName,
24+ tastyRoots = Nil ,
25+ classpath = System .getProperty(" java.class.path" ),
26+ output = dest.toFile,
27+ docsRoot = Some (base.toAbsolutePath.toString),
28+ projectVersion = Some (projectVersion),
29+ projectTitle = Some (projectTitle)
30+ )
31+ Main .main(args)
32+ op(dest)
33+
34+ finally println(dest.toFile) // IO.delete(dest.toFile)
35+
36+ val testDocPath = Paths .get(BuildInfo .testDocumentationRoot)
37+
38+ class DocumentContext (d : Document , path : Path ):
39+ import collection .JavaConverters ._
40+
41+ def niceMsg (msg : String ) = s " $msg in $path (body): \n ${d.html()}: \n "
42+
43+ def assertTextsIn (selector : String , expected : String * ) =
44+ assertFalse(niceMsg(" Selector not found" ), d.select(selector).isEmpty)
45+ val found = d.select(selector).eachText.asScala
46+ assertEquals(niceMsg(s " Context does not match for ' $selector' " ), expected.toList, found.toList)
47+
48+ def withHtmlFile (path : Path )(op : DocumentContext => Unit ) = {
49+ assertTrue(s " File at $path does not exisits! " , Files .exists(path))
50+ val content = new String (Files .readAllBytes(path), Charset .defaultCharset())
51+ val document = Jsoup .parse(content)
52+ op(DocumentContext (document, path))
53+ }
54+
55+ @ Test
56+ def basicTest () = withGeneratedSite(testDocPath.resolve(" basic" )){ dest =>
57+
58+ def checkFile (path : String )(title : String , header : String , parents : Seq [String ] = Nil ) =
59+ withHtmlFile(dest.resolve(path)){ content =>
60+ content.assertTextsIn(" .projectName" , projectName)
61+ content.assertTextsIn(" .projectVersion" , projectVersion)
62+ content.assertTextsIn(" h1" , header)
63+ content.assertTextsIn(" title" , title)
64+ content.assertTextsIn(" .breadcrumbs a" , (parents :+ title):_* )
65+ }
66+
67+ checkFile(" index.html" )(title = " Basic test" , header = " Header" )
68+ checkFile(" docs/Adoc.html" )(title = " Adoc" , header = " Header in Adoc" , parents = Seq (projectTitle))
69+ checkFile(" docs/Adoc.html" )(title = " Adoc" , header = " Header in Adoc" , parents = Seq (projectTitle))
70+ checkFile(" docs/dir/index.html" )(title = " A directory" , header = " A directory" , parents = Seq (projectTitle))
71+ checkFile(" docs/dir/nested.html" )(
72+ title = " Nested in a directory" , header = " Nested in a directory" , parents = Seq (projectTitle, " A directory" ))
73+
74+ checkFile(" docs/index.html" )(title = projectTitle, header = s " $projectTitle in header " )
75+ }
0 commit comments