X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetNotificationsAjaxPageTest.kt;h=8f67ecfbf3cd2101c14f1061e98974a0e9f4fa90;hp=f2206e30debef8dfcdcd8f0ce56ac00d0b3698f4;hb=8a0e0ee93d2f49762d87c4897a3a4de7273b3046;hpb=d58ef344b43543fdcfca13c07df87e194f004376 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt index f2206e3..8f67ecf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt @@ -3,8 +3,10 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.main.SonePlugin import net.pterodactylus.sone.test.argumentCaptor import net.pterodactylus.sone.test.get +import net.pterodactylus.sone.test.getInstance import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever +import net.pterodactylus.sone.web.baseInjector import net.pterodactylus.util.notify.Notification import net.pterodactylus.util.notify.TemplateNotification import net.pterodactylus.util.template.TemplateContext @@ -14,6 +16,7 @@ import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.containsInAnyOrder import org.hamcrest.Matchers.empty import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.notNullValue import org.junit.Test import org.mockito.ArgumentMatchers.any import org.mockito.Mockito.verify @@ -43,13 +46,13 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi @Test fun `notification hash is calculated correctly`() { testNotifications.forEach { addNotification(it) } - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() assertThat(json["notificationHash"]?.asInt(), equalTo(listOf(1, 0, 2).map(testNotifications::get).hashCode())) } @Test fun `options are included correctly`() { - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(true)) assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(true)) assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(true)) @@ -60,7 +63,7 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi currentSone.options.isShowNewSoneNotifications = false currentSone.options.isShowNewPostNotifications = false currentSone.options.isShowNewReplyNotifications = false - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(false)) assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(false)) assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(false)) @@ -69,14 +72,14 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi @Test fun `options are not included if user is not logged in`() { unsetCurrentSone() - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() assertThat(json["options"]?.toList(), empty()) } @Test fun `notifications are rendered correctly`() { testNotifications.forEach { addNotification(it) } - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() assertThat(json["notifications"]!!.toList().map { node -> listOf("id", "text", "createdTime", "lastUpdatedTime", "dismissable").map { it to node.get(it).asText() }.toMap() }, containsInAnyOrder( mapOf("id" to "n1", "createdTime" to "2000", "lastUpdatedTime" to "5000", "dismissable" to "true", "text" to "t1"), mapOf("id" to "n2", "createdTime" to "1000", "lastUpdatedTime" to "6000", "dismissable" to "false", "text" to "t2"), @@ -99,7 +102,7 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi } testNotifications.forEach { addNotification(it) } addNotification(templateNotification) - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() assertThat(json["notifications"]!!.last()["text"].asText(), equalTo("t4")) val templateContext = argumentCaptor() verify(templateNotification).render(templateContext.capture(), any()) @@ -115,4 +118,9 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi assertThat(templateContext.value["notification"], equalTo(templateNotification)) } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + }