X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FOptionsPageTest.kt;h=853b4fb1b0df53d1157e0b5dab320112f697e028;hp=dc738740a5fd6b0cbfe4a29fb72273f873efeeed;hb=a76956e389fcfe6282ad4ca7156bbf76327bb0c0;hpb=29673a06876521c18d299c777a61846aed851aaa 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 dc73874..853b4fb 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -1,42 +1,35 @@ package net.pterodactylus.sone.web.pages -import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions -import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent.FOLLOWED -import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent.TRUSTED +import net.pterodactylus.sone.data.SoneOptions.* +import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent.* +import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.* 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.whenever -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.nullValue -import org.junit.Before -import org.junit.Test +import net.pterodactylus.sone.test.* +import net.pterodactylus.sone.web.* +import net.pterodactylus.sone.web.page.* +import net.pterodactylus.util.web.Method.* +import org.hamcrest.MatcherAssert.* +import org.hamcrest.Matchers.* +import org.junit.* /** * Unit test for [OptionsPage]. */ -class OptionsPageTest: WebPageTest() { - - private val page = OptionsPage(template, webInterface) - - override fun getPage() = page +class OptionsPageTest: WebPageTest(::OptionsPage) { @Before fun setupPreferences() { - core.preferences.insertionDelay = 1 - core.preferences.charactersPerPost = 50 - core.preferences.fcpFullAccessRequired = WRITING - core.preferences.imagesPerPage = 4 - core.preferences.isFcpInterfaceActive = true - core.preferences.isRequireFullAccess = true - core.preferences.negativeTrust = 7 - core.preferences.positiveTrust = 8 - core.preferences.postCutOffLength = 51 - core.preferences.postsPerPage = 10 - core.preferences.trustComment = "11" + core.preferences.newInsertionDelay = 1 + core.preferences.newCharactersPerPost = 50 + core.preferences.newFcpFullAccessRequired = WRITING + core.preferences.newImagesPerPage = 4 + core.preferences.newFcpInterfaceActive = true + core.preferences.newRequireFullAccess = true + core.preferences.newNegativeTrust = 7 + core.preferences.newPositiveTrust = 8 + core.preferences.newPostCutOffLength = 51 + core.preferences.newPostsPerPage = 10 + core.preferences.newTrustComment = "11" } @Before @@ -65,7 +58,7 @@ class OptionsPageTest: WebPageTest() { @Test fun `page returns correct title`() { addTranslation("Page.Options.Title", "options page title") - assertThat(page.getPageTitle(freenetRequest), equalTo("options page title")) + assertThat(page.getPageTitle(soneRequest), equalTo("options page title")) } @Test @@ -110,7 +103,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 +115,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 +182,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)) } @@ -246,22 +265,22 @@ class OptionsPageTest: WebPageTest() { @Test fun `fcp interface can be set to true`() { - verifyThatPreferencesCanBeSet("fcp-interface-active", "checked", true) { core.preferences.isFcpInterfaceActive } + verifyThatPreferencesCanBeSet("fcp-interface-active", "checked", true) { core.preferences.fcpInterfaceActive } } @Test fun `fcp interface can be set to false`() { - verifyThatPreferencesCanBeSet("fcp-interface-active", null, false) { core.preferences.isFcpInterfaceActive } + verifyThatPreferencesCanBeSet("fcp-interface-active", null, false) { core.preferences.fcpInterfaceActive } } @Test fun `require full access can be set to true`() { - verifyThatPreferencesCanBeSet("require-full-access", "checked", true) { core.preferences.isRequireFullAccess } + verifyThatPreferencesCanBeSet("require-full-access", "checked", true) { core.preferences.requireFullAccess } } @Test fun `require full access can be set to false`() { - verifyThatPreferencesCanBeSet("require-full-access", null, false) { core.preferences.isRequireFullAccess } + verifyThatPreferencesCanBeSet("require-full-access", null, false) { core.preferences.requireFullAccess } } @Test @@ -354,4 +373,19 @@ 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()) + } + + @Test + fun `page is annotated with correct menuname`() { + assertThat(page.menuName, equalTo("Options")) + } + + @Test + fun `page is annotated with correct template path`() { + assertThat(page.templatePath, equalTo("/templates/options.html")) + } + }