X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FNotificationHandlerModuleTest.kt;h=11e728d55aa0c85e060cbfdcef182577c7abb397;hb=4038d16030a1cb6bb48da2967ee2c9ec9b4aaeb0;hp=76926fbac66d3d2aecc9377746ea69cecd42f5a8;hpb=eb828bec5212bba8b9745f45defdc47711968ce6;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt index 76926fb..11e728d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt @@ -23,6 +23,7 @@ import com.google.inject.name.Names.* import net.pterodactylus.sone.core.* import net.pterodactylus.sone.core.event.* import net.pterodactylus.sone.data.* +import net.pterodactylus.sone.data.Post.* import net.pterodactylus.sone.data.impl.* import net.pterodactylus.sone.main.* import net.pterodactylus.sone.notify.* @@ -51,18 +52,13 @@ class NotificationHandlerModuleTest { ) @Test - fun `module can create notification handler`() { - assertThat(injector.getInstance(), notNullValue()) - } - - @Test fun `notification handler is created as singleton`() { injector.verifySingletonInstance() } @Test - fun `module can create mark-post-known-during-first-start handler`() { - assertThat(injector.getInstance(), notNullValue()) + fun `mark-post-known-during-first-start handler is created as singleton`() { + injector.verifySingletonInstance() } @Test @@ -77,11 +73,6 @@ class NotificationHandlerModuleTest { } @Test - fun `module can create sone-locked-on-startup handler`() { - assertThat(injector.getInstance(), notNullValue()) - } - - @Test fun `sone-locked-on-startup handler is created as singleton`() { injector.verifySingletonInstance() } @@ -114,11 +105,6 @@ class NotificationHandlerModuleTest { } @Test - fun `new-sone handler can be created`() { - assertThat(injector.getInstance(), notNullValue()) - } - - @Test fun `new-sone handler is created as singleton`() { injector.verifySingletonInstance() } @@ -142,4 +128,118 @@ class NotificationHandlerModuleTest { assertThat(injector.getInstance>(named("newSone")).isDismissable, equalTo(false)) } + @Test + fun `new-remote-post handler is created as singleton`() { + injector.verifySingletonInstance() + } + + @Test + fun `new-remote-post notification is created as singleton`() { + injector.verifySingletonInstance>(named("newRemotePost")) + } + + @Test + fun `new-remote-post notification has correct ID`() { + assertThat(injector.getInstance>(named("newRemotePost")).id, equalTo("new-post-notification")) + } + + @Test + fun `new-remote-post notification is not dismissable`() { + assertThat(injector.getInstance>(named("newRemotePost")).isDismissable, equalTo(false)) + } + + @Test + fun `new-remote-post notification has correct key and template`() { + loaders.templates += "/templates/notify/newPostNotification.html" to "<% posts>".asTemplate() + val notification = injector.getInstance>(named("newRemotePost")) + val posts = listOf(EmptyPost("post1"), EmptyPost("post2")) + posts.forEach(notification::add) + assertThat(notification.render(), equalTo(posts.toString())) + } + + @Test + fun `sone-locked notification is created as singleton`() { + injector.verifySingletonInstance>(named("soneLocked")) + } + + @Test + fun `sone-locked notification is dismissable`() { + assertThat(injector.getInstance>(named("soneLocked")).isDismissable, equalTo(true)) + } + + @Test + fun `sone-locked notification has correct ID`() { + assertThat(injector.getInstance>(named("soneLocked")).id, equalTo("sones-locked-notification")) + } + + @Test + fun `sone-locked notification has correct key and template`() { + loaders.templates += "/templates/notify/lockedSonesNotification.html" to "<% sones>".asTemplate() + val notification = injector.getInstance>(named("soneLocked")) + val sones = listOf(IdOnlySone("sone1"), IdOnlySone("sone2")) + sones.forEach(notification::add) + assertThat(notification.render(), equalTo(sones.toString())) + } + + @Test + fun `sone-locked handler is created as singleton`() { + injector.verifySingletonInstance() + } + + @Test + fun `local-post notification is not dismissable`() { + assertThat(injector.getInstance>(named("localPost")).isDismissable, equalTo(false)) + } + + @Test + fun `local-post notification has correct ID`() { + assertThat(injector.getInstance>(named("localPost")).id, equalTo("local-post-notification")) + } + + @Test + fun `local-post notification has correct key and template`() { + loaders.templates += "/templates/notify/newPostNotification.html" to "<% posts>".asTemplate() + val notification = injector.getInstance>(named("localPost")) + val posts = listOf(EmptyPost("post1"), EmptyPost("post2")) + posts.forEach(notification::add) + assertThat(notification.render(), equalTo(posts.toString())) + } + + @Test + fun `local-post notification is created as singleton`() { + injector.verifySingletonInstance>(named("localPost")) + } + + @Test + fun `local-post handler is created as singleton`() { + injector.verifySingletonInstance() + } + + @Test + fun `new-version notification is created as singleton`() { + injector.verifySingletonInstance(named("newVersion")) + } + + @Test + fun `new-version notification has correct ID`() { + assertThat(injector.getInstance(named("newVersion")).id, equalTo("new-version-notification")) + } + + @Test + fun `new-version notification is dismissable`() { + assertThat(injector.getInstance(named("newVersion")).isDismissable, equalTo(true)) + } + + @Test + fun `new-version notification loads correct template`() { + loaders.templates += "/templates/notify/newVersionNotification.html" to "1".asTemplate() + val notification = injector.getInstance(named("newVersion")) + assertThat(notification.render(), equalTo("1")) + } + + @Test + fun `new-version handler is created as singleton`() { + injector.verifySingletonInstance() + } + }