1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.data.PostReply
5 import net.pterodactylus.sone.data.Sone
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.util.web.Method.POST
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
11 import org.mockito.Mockito.verify
14 * Unit test for [MarkAsKnownPage].
16 class MarkAsKnownPageTest: WebPageTest(::MarkAsKnownPage) {
19 fun `page returns correct path`() {
20 assertThat(page.path, equalTo("markAsKnown.html"))
24 fun `page does not require login`() {
25 assertThat(page.requiresLogin(), equalTo(false))
29 fun `page returns correct title`() {
30 addTranslation("Page.MarkAsKnown.Title", "mark as known page title")
31 assertThat(page.getPageTitle(freenetRequest), equalTo("mark as known page title"))
35 fun `posts can be marked as known`() {
37 addHttpRequestPart("returnPage", "return.html")
38 addHttpRequestPart("type", "post")
39 addHttpRequestPart("id", "post1 post2 post3")
40 val posts = listOf(mock<Post>(), mock<Post>())
41 addPost("post1", posts[0])
42 addPost("post3", posts[1])
43 verifyRedirect("return.html") {
44 verify(core).markPostKnown(posts[0])
45 verify(core).markPostKnown(posts[1])
50 fun `replies can be marked as known`() {
52 addHttpRequestPart("returnPage", "return.html")
53 addHttpRequestPart("type", "reply")
54 addHttpRequestPart("id", "reply1 reply2 reply3")
55 val replies = listOf(mock<PostReply>(), mock<PostReply>())
56 addPostReply("reply1", replies[0])
57 addPostReply("reply3", replies[1])
58 verifyRedirect("return.html") {
59 verify(core).markReplyKnown(replies[0])
60 verify(core).markReplyKnown(replies[1])
65 fun `sones can be marked as known`() {
67 addHttpRequestPart("returnPage", "return.html")
68 addHttpRequestPart("type", "sone")
69 addHttpRequestPart("id", "sone1 sone2 sone3")
70 val sones = listOf(mock<Sone>(), mock<Sone>())
71 addSone("sone1", sones[0])
72 addSone("sone3", sones[1])
73 verifyRedirect("return.html") {
74 verify(core).markSoneKnown(sones[0])
75 verify(core).markSoneKnown(sones[1])
80 fun `different type redirects to invalid page`() {
82 addHttpRequestPart("type", "foo")
83 verifyRedirect("invalid.html")