projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
✨ Annotate EditProfilePage with MenuName
[Sone.git]
/
src
/
test
/
kotlin
/
net
/
pterodactylus
/
sone
/
web
/
pages
/
IndexPageTest.kt
diff --git
a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
index
6d87f3a
..
2a72bb3
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
@@
-5,14
+5,17
@@
import com.google.common.base.Predicate
import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.notify.PostVisibilityFilter
import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.notify.PostVisibilityFilter
+import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import net.pterodactylus.sone.utils.Pagination
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import net.pterodactylus.sone.utils.Pagination
-import net.pterodactylus.util.web.Method.GET
+import net.pterodactylus.sone.web.baseInjector
+import net.pterodactylus.sone.web.page.*
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.contains
import org.hamcrest.Matchers.emptyIterable
import org.hamcrest.Matchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.contains
import org.hamcrest.Matchers.emptyIterable
import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers
@@
-20,10
+23,11
@@
import org.mockito.ArgumentMatchers
/**
* Unit test for [IndexPage].
*/
/**
* Unit test for [IndexPage].
*/
-class IndexPageTest
: WebPageTest(
) {
+class IndexPageTest
: WebPageTest({ template, webInterface -> IndexPage(template, webInterface, postVisibilityFilter) }
) {
- private val postVisibilityFilter = mock<PostVisibilityFilter>()
- private val page = IndexPage(template, webInterface, postVisibilityFilter)
+ companion object {
+ private val postVisibilityFilter = mock<PostVisibilityFilter>()
+ }
@Test
fun `page returns correct path`() {
@Test
fun `page returns correct path`() {
@@
-38,7
+42,7
@@
class IndexPageTest : WebPageTest() {
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.Index.Title")).thenReturn("index page title")
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.Index.Title")).thenReturn("index page title")
- assertThat(page.getPageTitle(
freenet
Request), equalTo("index page title"))
+ assertThat(page.getPageTitle(
sone
Request), equalTo("index page title"))
}
@Before
}
@Before
@@
-65,7
+69,6
@@
class IndexPageTest : WebPageTest() {
fun `index page shows all posts of current sone`() {
val posts = listOf(createPost(3000), createPost(2000), createPost(1000))
whenever(currentSone.posts).thenReturn(posts)
fun `index page shows all posts of current sone`() {
val posts = listOf(createPost(3000), createPost(2000), createPost(1000))
whenever(currentSone.posts).thenReturn(posts)
- request("", GET)
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat(templateContext["posts"] as Iterable<Post>, contains(*posts.toTypedArray()))
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat(templateContext["posts"] as Iterable<Post>, contains(*posts.toTypedArray()))
@@
-79,7
+82,6
@@
class IndexPageTest : WebPageTest() {
val notFollowedPosts = listOf(createPost(2500, true), createPost(1500))
whenever(notFollowedSone.posts).thenReturn(notFollowedPosts)
addSone("notfollowed1", notFollowedSone)
val notFollowedPosts = listOf(createPost(2500, true), createPost(1500))
whenever(notFollowedSone.posts).thenReturn(notFollowedPosts)
addSone("notfollowed1", notFollowedSone)
- request("", GET)
whenever(core.getDirectedPosts("current")).thenReturn(listOf(notFollowedPosts[0]))
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
whenever(core.getDirectedPosts("current")).thenReturn(listOf(notFollowedPosts[0]))
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
@@
-97,7
+99,6
@@
class IndexPageTest : WebPageTest() {
whenever(followedSone.posts).thenReturn(followedPosts)
whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2"))
addSone("followed1", followedSone)
whenever(followedSone.posts).thenReturn(followedPosts)
whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2"))
addSone("followed1", followedSone)
- request("", GET)
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat(templateContext["posts"] as Iterable<Post>, contains(
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat(templateContext["posts"] as Iterable<Post>, contains(
@@
-115,7
+116,6
@@
class IndexPageTest : WebPageTest() {
whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2"))
whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn(Predicate<Post> { (it?.time ?: 10000) < 2500 })
addSone("followed1", followedSone)
whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2"))
whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn(Predicate<Post> { (it?.time ?: 10000) < 2500 })
addSone("followed1", followedSone)
- request("", GET)
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat(templateContext["posts"] as Iterable<Post>, contains(
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat(templateContext["posts"] as Iterable<Post>, contains(
@@
-127,7
+127,6
@@
class IndexPageTest : WebPageTest() {
fun `index page sets pagination correctly`() {
val posts = listOf(createPost(3000), createPost(2000), createPost(1000))
whenever(currentSone.posts).thenReturn(posts)
fun `index page sets pagination correctly`() {
val posts = listOf(createPost(3000), createPost(2000), createPost(1000))
whenever(currentSone.posts).thenReturn(posts)
- request("", GET)
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(
@@
-139,8
+138,7
@@
class IndexPageTest : WebPageTest() {
fun `index page sets page correctly`() {
val posts = listOf(createPost(3000), createPost(2000), createPost(1000))
whenever(currentSone.posts).thenReturn(posts)
fun `index page sets page correctly`() {
val posts = listOf(createPost(3000), createPost(2000), createPost(1000))
whenever(currentSone.posts).thenReturn(posts)
- request("", GET)
- core.preferences.postsPerPage = 1
+ core.preferences.newPostsPerPage = 1
addHttpRequestParameter("page", "2")
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
addHttpRequestParameter("page", "2")
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
@@
-149,8
+147,7
@@
class IndexPageTest : WebPageTest() {
@Test
fun `index page without posts sets correct pagination`() {
@Test
fun `index page without posts sets correct pagination`() {
- request("", GET)
- core.preferences.postsPerPage = 1
+ core.preferences.newPostsPerPage = 1
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
(templateContext["pagination"] as Pagination<Post>).let { pagination ->
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
(templateContext["pagination"] as Pagination<Post>).let { pagination ->
@@
-158,4
+155,14
@@
class IndexPageTest : WebPageTest() {
}
}
}
}
+ @Test
+ fun `page can be created by dependency injection`() {
+ assertThat(baseInjector.getInstance<IndexPage>(), notNullValue())
+ }
+
+ @Test
+ fun `page is annotated with correct menuname`() {
+ assertThat(page.menuName, equalTo("Index"))
+ }
+
}
}