X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FOptionsPageTest.kt;h=94ae905d5459b845535c98ef4ae8b99012093a8b;hb=a198aa2adc1f157fdf40a872654f02e096f9041d;hp=c7b3423078569aa359d21327a9976ef594b75347;hpb=4e822a612bedf423ec395f55da13cfb68975f2ef;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt index c7b3423..94ae905 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -6,11 +6,14 @@ import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent.TRUSTED import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.ALWAYS import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING +import net.pterodactylus.sone.test.getInstance import net.pterodactylus.sone.test.whenever +import net.pterodactylus.sone.web.baseInjector import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.hasItem +import org.hamcrest.Matchers.notNullValue import org.hamcrest.Matchers.nullValue import org.junit.Before import org.junit.Test @@ -18,11 +21,7 @@ import org.junit.Test /** * Unit test for [OptionsPage]. */ -class OptionsPageTest : WebPageTest() { - - private val page = OptionsPage(template, webInterface) - - override fun getPage() = page +class OptionsPageTest: WebPageTest(::OptionsPage) { @Before fun setupPreferences() { @@ -54,7 +53,7 @@ class OptionsPageTest : WebPageTest() { @Test fun `page returns correct path`() { - assertThat(page.path, equalTo("options.html")) + assertThat(page.path, equalTo("options.html")) } @Test @@ -64,7 +63,7 @@ class OptionsPageTest : WebPageTest() { @Test fun `page returns correct title`() { - addTranslation("Page.Options.Title", "options page title") + addTranslation("Page.Options.Title", "options page title") assertThat(page.getPageTitle(freenetRequest), equalTo("options page title")) } @@ -110,7 +109,7 @@ class OptionsPageTest : WebPageTest() { setMethod(POST) addHttpRequestPart("show-custom-avatars", "ALWAYS") addHttpRequestPart("load-linked-images", "ALWAYS") - addHttpRequestPart(option, setValue.toString()) + setValue?.also { addHttpRequestPart(option, it.toString()) } verifyRedirect("options.html") { assertThat(getter(), equalTo(expectedValue)) } @@ -122,26 +121,52 @@ class OptionsPageTest : WebPageTest() { } @Test + fun `auto-follow option can be unset`() { + verifyThatOptionCanBeSet("auto-follow", null, false) { currentSone.options.isAutoFollow } + } + + @Test fun `show new sone notification option can be set`() { verifyThatOptionCanBeSet("show-notification-new-sones", "checked", true) { currentSone.options.isShowNewSoneNotifications } } @Test + fun `show new sone notification option can be unset`() { + verifyThatOptionCanBeSet("" + + "", null, false) { currentSone.options.isShowNewSoneNotifications } + } + + @Test fun `show new post notification option can be set`() { verifyThatOptionCanBeSet("show-notification-new-posts", "checked", true) { currentSone.options.isShowNewPostNotifications } } @Test + fun `show new post notification option can be unset`() { + verifyThatOptionCanBeSet("show-notification-new-posts", null, false) { currentSone.options.isShowNewPostNotifications } + } + + @Test fun `show new reply notification option can be set`() { verifyThatOptionCanBeSet("show-notification-new-replies", "checked", true) { currentSone.options.isShowNewReplyNotifications } } @Test + fun `show new reply notification option can be unset`() { + verifyThatOptionCanBeSet("show-notification-new-replies", null, false) { currentSone.options.isShowNewReplyNotifications } + } + + @Test fun `enable sone insert notifications option can be set`() { verifyThatOptionCanBeSet("enable-sone-insert-notifications", "checked", true) { currentSone.options.isSoneInsertNotificationEnabled } } @Test + fun `enable sone insert notifications option can be unset`() { + verifyThatOptionCanBeSet("enable-sone-insert-notifications", null, false) { currentSone.options.isSoneInsertNotificationEnabled } + } + + @Test fun `load linked images option can be set`() { verifyThatOptionCanBeSet("load-linked-images", "TRUSTED", TRUSTED) { currentSone.options.loadLinkedImages } } @@ -163,7 +188,7 @@ class OptionsPageTest : WebPageTest() { private fun verifyThatPreferencesCanBeSet(name: String, setValue: String?, expectedValue: T, getter: () -> T) { unsetCurrentSone() setMethod(POST) - addHttpRequestPart(name, setValue) + setValue?.also { addHttpRequestPart(name, it) } verifyRedirect("options.html") { assertThat(getter(), equalTo(expectedValue)) } @@ -354,4 +379,9 @@ class OptionsPageTest : WebPageTest() { verifyThatPreferencesCanBeSet("trust-comment", "", "Set from Sone Web Interface") { core.preferences.trustComment } } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + }