Add more tests for search page
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / DismissNotificationPageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.test.mock
4 import net.pterodactylus.sone.test.whenever
5 import net.pterodactylus.util.notify.Notification
6 import net.pterodactylus.util.web.Method.POST
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
9 import org.junit.Test
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [DismissNotificationPage].
15  */
16 class DismissNotificationPageTest: WebPageTest() {
17
18         private val page = DismissNotificationPage(template, webInterface)
19         private val notification = mock<Notification>()
20
21         override fun getPage() = page
22
23         @Test
24         fun `page returns correct path`() {
25                 assertThat(page.path, equalTo("dismissNotification.html"))
26         }
27
28         @Test
29         fun `page does not require login`() {
30                 assertThat(page.requiresLogin(), equalTo(false))
31         }
32
33         @Test
34         fun `page returns correct title`() {
35                 whenever(l10n.getString("Page.DismissNotification.Title")).thenReturn("dismiss notification page")
36                 assertThat(page.getPageTitle(freenetRequest), equalTo("dismiss notification page"))
37         }
38
39         @Test
40         fun `get request with invalid notification ID redirects to return page`() {
41                 setMethod(POST)
42                 addHttpRequestPart("returnPage", "return.html")
43                 verifyRedirect("return.html")
44         }
45
46         @Test
47         fun `get request with non-dismissible notification never dismisses the notification but redirects to return page`() {
48                 setMethod(POST)
49                 addNotification("notification-id", notification)
50                 addHttpRequestPart("notification", "notification-id")
51                 addHttpRequestPart("returnPage", "return.html")
52                 verifyRedirect("return.html") {
53                         verify(notification, never()).dismiss()
54                 }
55         }
56
57         @Test
58         fun `post request with dismissible notification dismisses the notification and redirects to return page`() {
59                 setMethod(POST)
60                 whenever(notification.isDismissable).thenReturn(true)
61                 addNotification("notification-id", notification)
62                 addHttpRequestPart("notification", "notification-id")
63                 addHttpRequestPart("returnPage", "return.html")
64                 verifyRedirect("return.html") {
65                         verify(notification).dismiss()
66                 }
67         }
68
69 }