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