1 package net.pterodactylus.sone.web.pages
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
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
14 * Unit test for [DismissNotificationPage].
16 class DismissNotificationPageTest: WebPageTest(::DismissNotificationPage) {
18 private val notification = mock<Notification>()
21 fun `page returns correct path`() {
22 assertThat(page.path, equalTo("dismissNotification.html"))
26 fun `page does not require login`() {
27 assertThat(page.requiresLogin(), equalTo(false))
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"))
37 fun `get request with invalid notification ID redirects to return page`() {
39 addHttpRequestPart("returnPage", "return.html")
40 verifyRedirect("return.html")
44 fun `get request with non-dismissible notification never dismisses the notification but redirects to return page`() {
46 addNotification("notification-id", notification)
47 addHttpRequestPart("notification", "notification-id")
48 addHttpRequestPart("returnPage", "return.html")
49 verifyRedirect("return.html") {
50 verify(notification, never()).dismiss()
55 fun `post request with dismissible notification dismisses the notification and redirects to return page`() {
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()