Add test for delete profile field ajax 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(::DismissNotificationPage) {
17
18         private val notification = mock<Notification>()
19
20         @Test
21         fun `page returns correct path`() {
22                 assertThat(page.path, equalTo("dismissNotification.html"))
23         }
24
25         @Test
26         fun `page does not require login`() {
27                 assertThat(page.requiresLogin(), equalTo(false))
28         }
29
30         @Test
31         fun `page returns correct title`() {
32                 whenever(l10n.getString("Page.DismissNotification.Title")).thenReturn("dismiss notification page")
33                 assertThat(page.getPageTitle(freenetRequest), equalTo("dismiss notification page"))
34         }
35
36         @Test
37         fun `get request with invalid notification ID redirects to return page`() {
38                 setMethod(POST)
39                 addHttpRequestPart("returnPage", "return.html")
40                 verifyRedirect("return.html")
41         }
42
43         @Test
44         fun `get request with non-dismissible notification never dismisses the notification but redirects to return page`() {
45                 setMethod(POST)
46                 addNotification("notification-id", notification)
47                 addHttpRequestPart("notification", "notification-id")
48                 addHttpRequestPart("returnPage", "return.html")
49                 verifyRedirect("return.html") {
50                         verify(notification, never()).dismiss()
51                 }
52         }
53
54         @Test
55         fun `post request with dismissible notification dismisses the notification and redirects to return page`() {
56                 setMethod(POST)
57                 whenever(notification.isDismissable).thenReturn(true)
58                 addNotification("notification-id", notification)
59                 addHttpRequestPart("notification", "notification-id")
60                 addHttpRequestPart("returnPage", "return.html")
61                 verifyRedirect("return.html") {
62                         verify(notification).dismiss()
63                 }
64         }
65
66 }