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() {
18 private val page = DismissNotificationPage(template, webInterface)
19 private val notification = mock<Notification>()
21 override fun getPage() = page
24 fun `page returns correct path`() {
25 assertThat(page.path, equalTo("dismissNotification.html"))
29 fun `page does not require login`() {
30 assertThat(page.requiresLogin(), equalTo(false))
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"))
40 fun `get request with invalid notification ID redirects to return page`() {
42 addHttpRequestPart("returnPage", "return.html")
43 verifyRedirect("return.html")
47 fun `get request with non-dismissible notification never dismisses the notification but redirects to return page`() {
49 addNotification("notification-id", notification)
50 addHttpRequestPart("notification", "notification-id")
51 addHttpRequestPart("returnPage", "return.html")
52 verifyRedirect("return.html") {
53 verify(notification, never()).dismiss()
58 fun `post request with dismissible notification dismisses the notification and redirects to return page`() {
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()