Move web pages to their own package
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / LogoutPageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.test.whenever
4 import net.pterodactylus.sone.web.pages.LogoutPage
5 import net.pterodactylus.sone.web.pages.WebPageTest
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.junit.Test
9 import org.mockito.Mockito.verify
10
11 /**
12  * Unit test for [LogoutPage].
13  */
14 class LogoutPageTest : WebPageTest() {
15
16         private val page = LogoutPage(template, webInterface)
17
18         override fun getPage() = page
19
20         @Test
21         fun `page unsets current sone and redirects to index`() {
22                 verifyRedirect("index.html") {
23                         verify(webInterface).setCurrentSone(toadletContext, null)
24                 }
25         }
26
27         @Test
28         fun `page is not enabled if sone requires full access and request does not have full access`() {
29                 core.preferences.isRequireFullAccess = true
30                 assertThat(page.isEnabled(toadletContext), equalTo(false))
31         }
32
33         @Test
34         fun `page is disabled if no sone is logged in`() {
35                 unsetCurrentSone()
36                 assertThat(page.isEnabled(toadletContext), equalTo(false))
37         }
38
39         @Test
40         fun `page is disabled if sone is logged in but there is only one sone`() {
41                 whenever(core.localSones).thenReturn(listOf(currentSone))
42                 assertThat(page.isEnabled(toadletContext), equalTo(false))
43         }
44
45         @Test
46         fun `page is enabled if sone is logged in and there is more than one sone`() {
47                 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
48                 assertThat(page.isEnabled(toadletContext), equalTo(true))
49         }
50
51         @Test
52         fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() {
53                 core.preferences.isRequireFullAccess = true
54                 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
55                 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
56                 assertThat(page.isEnabled(toadletContext), equalTo(true))
57         }
58
59 }