♻️ Refactor WOT connector
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / AboutPageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.main.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.sone.web.page.*
7 import org.hamcrest.MatcherAssert.*
8 import org.hamcrest.Matchers.*
9 import org.junit.*
10
11 /**
12  * Unit test for [AboutPage].
13  */
14 class AboutPageTest : WebPageTest({ webInterface, loaders, templateRenderer -> AboutPage(webInterface, loaders, templateRenderer, PluginVersion(version), PluginYear(year), PluginHomepage(homepage)) }) {
15
16         companion object {
17                 private const val version = "0.1.2"
18                 private const val year = 1234
19                 private const val homepage = "home://page"
20         }
21
22         @Test
23         fun `page returns correct path`() {
24                 assertThat(page.path, equalTo("about.html"))
25         }
26
27         @Test
28         fun `page does not require login`() {
29                 assertThat(page.requiresLogin(), equalTo(false))
30         }
31
32         @Test
33         fun `page sets correct version in template context`() {
34                 page.processTemplate(freenetRequest, templateContext)
35                 assertThat(templateContext["version"], equalTo<Any>(version))
36         }
37
38         @Test
39         fun `page sets correct homepage in template context`() {
40                 page.processTemplate(freenetRequest, templateContext)
41                 assertThat(templateContext["homepage"], equalTo<Any>(homepage))
42         }
43
44         @Test
45         fun `page sets correct year in template context`() {
46                 page.processTemplate(freenetRequest, templateContext)
47                 assertThat(templateContext["year"], equalTo<Any>(year))
48         }
49
50         @Test
51         fun `about page can be created by dependency injection`() {
52                 val injector = baseInjector.createChildInjector(
53                                 PluginVersion::class.isProvidedByMock(),
54                                 PluginYear::class.isProvidedByMock(),
55                                 PluginHomepage::class.isProvidedByMock()
56                 )
57                 assertThat(injector.getInstance<AboutPage>(), notNullValue())
58         }
59
60         @Test
61         fun `page is annotated with correct menuname`() {
62                 assertThat(page.menuName, equalTo("About"))
63         }
64
65         @Test
66         fun `page is annotated with correct template path`() {
67                 assertThat(page.templatePath, equalTo("/templates/about.html"))
68         }
69
70 }