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=d679e85f89e91276143d5e40cb694fd505c98746;hp=a9dba9ec2e369490591c384eef01e7e160164538;hb=7a2061d9f8ae6508ffbbac724630ff5696592f0d;hpb=fc8e9ea5c978d2f5a00894e093364ae62f18934b 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 a9dba9e..d679e85 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -1,27 +1,21 @@ 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.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 +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(::OptionsPage) { +class OptionsPageTest : WebPageTest(::OptionsPage) { @Before fun setupPreferences() { @@ -31,11 +25,9 @@ class OptionsPageTest: WebPageTest(::OptionsPage) { 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" + core.preferences.newStrictFiltering = true } @Before @@ -64,7 +56,7 @@ class OptionsPageTest: WebPageTest(::OptionsPage) { @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 @@ -83,11 +75,9 @@ class OptionsPageTest: WebPageTest(::OptionsPage) { assertThat(templateContext["images-per-page"], equalTo(4)) assertThat(templateContext["fcp-interface-active"], equalTo(true)) assertThat(templateContext["require-full-access"], equalTo(true)) - assertThat(templateContext["negative-trust"], equalTo(7)) - assertThat(templateContext["positive-trust"], equalTo(8)) assertThat(templateContext["post-cut-off-length"], equalTo(51)) assertThat(templateContext["posts-per-page"], equalTo(10)) - assertThat(templateContext["trust-comment"], equalTo("11")) + assertThat(templateContext["strict-filtering"], equalTo(true)) } } @@ -290,56 +280,6 @@ class OptionsPageTest: WebPageTest(::OptionsPage) { } @Test - fun `negative trust can not be set to -101`() { - verifyThatWrongValueForPreferenceIsDetected("negative-trust", "-101") - } - - @Test - fun `negative trust can be set to -100`() { - verifyThatPreferencesCanBeSet("negative-trust", "-100", -100) { core.preferences.negativeTrust } - } - - @Test - fun `negative trust can be set to 100`() { - verifyThatPreferencesCanBeSet("negative-trust", "100", 100) { core.preferences.negativeTrust } - } - - @Test - fun `negative trust can not be set to 101`() { - verifyThatWrongValueForPreferenceIsDetected("negative-trust", "101") - } - - @Test - fun `negative trust is set to default on invalid value`() { - verifyThatPreferencesCanBeSet("negative-trust", "invalid", -25) { core.preferences.negativeTrust } - } - - @Test - fun `positive trust can not be set to -1`() { - verifyThatWrongValueForPreferenceIsDetected("positive-trust", "-1") - } - - @Test - fun `positive trust can be set to 0`() { - verifyThatPreferencesCanBeSet("positive-trust", "0", 0) { core.preferences.positiveTrust } - } - - @Test - fun `positive trust can be set to 100`() { - verifyThatPreferencesCanBeSet("positive-trust", "100", 100) { core.preferences.positiveTrust } - } - - @Test - fun `positive trust can not be set to 101`() { - verifyThatWrongValueForPreferenceIsDetected("positive-trust", "101") - } - - @Test - fun `positive trust is set to default on invalid value`() { - verifyThatPreferencesCanBeSet("positive-trust", "invalid", 75) { core.preferences.positiveTrust } - } - - @Test fun `post cut off length can not be set to -49`() { verifyThatWrongValueForPreferenceIsDetected("post-cut-off-length", "-49") } @@ -370,18 +310,28 @@ class OptionsPageTest: WebPageTest(::OptionsPage) { } @Test - fun `trust comment can be set`() { - verifyThatPreferencesCanBeSet("trust-comment", "trust", "trust") { core.preferences.trustComment } + fun `strict filtering can be set to true`() { + verifyThatPreferencesCanBeSet("strict-filtering", "checked", true) { core.preferences.strictFiltering } } @Test - fun `trust comment is set to default when set to empty value`() { - verifyThatPreferencesCanBeSet("trust-comment", "", "Set from Sone Web Interface") { core.preferences.trustComment } + fun `strict filtering can be set to false`() { + verifyThatPreferencesCanBeSet("strict-filtering", null, false) { core.preferences.strictFiltering } } @Test fun `page can be created by dependency injection`() { - assertThat(baseInjector.getInstance(), notNullValue()) + 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")) } }