1 package net.pterodactylus.sone.web
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.sone.test.whenever
6 import net.pterodactylus.util.web.Method.POST
8 import org.mockito.Mockito.any
9 import org.mockito.Mockito.never
10 import org.mockito.Mockito.verify
13 * Unit test for [UnbookmarkPage].
15 class UnbookmarkPageTest : WebPageTest() {
17 private val page = UnbookmarkPage(template, webInterface)
19 override fun getPage() = page
22 fun `get request does not redirect`() {
23 page.handleRequest(freenetRequest, templateContext)
27 fun `get request with all-not-loaded parameter unloads all not loaded posts and redirects to bookmarks`() {
28 addHttpRequestParameter("post", "allNotLoaded")
29 val loadedPost1 = mock<Post>().apply { whenever(isLoaded).thenReturn(true) }
30 val loadedPost2 = mock<Post>().apply { whenever(isLoaded).thenReturn(true) }
31 val notLoadedPost1 = mock<Post>()
32 val notLoadedPost2 = mock<Post>()
33 whenever(core.bookmarkedPosts).thenReturn(setOf(loadedPost1, loadedPost2, notLoadedPost1, notLoadedPost2))
34 verifyRedirect("bookmarks.html") {
35 verify(core).unbookmarkPost(notLoadedPost1)
36 verify(core).unbookmarkPost(notLoadedPost2)
37 verify(core, never()).unbookmarkPost(loadedPost1)
38 verify(core, never()).unbookmarkPost(loadedPost2)
43 fun `post request does not unbookmark not-present post but redirects to return page`() {
45 addHttpRequestParameter("post", "post-id")
46 addHttpRequestParameter("returnPage", "return.html")
47 verifyRedirect("return.html") {
48 verify(core, never()).unbookmarkPost(any())
53 fun `post request unbookmarks present post and redirects to return page`() {
55 addHttpRequestParameter("post", "post-id")
56 addHttpRequestParameter("returnPage", "return.html")
57 val post = mock<Post>().apply { whenever(isLoaded).thenReturn(true) }
58 addPost("post-id", post)
59 verifyRedirect("return.html") {
60 verify(core).unbookmarkPost(post)