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() {
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
@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
assertThat(templateContext["images-per-page"], equalTo<Any>(4))
assertThat(templateContext["fcp-interface-active"], equalTo<Any>(true))
assertThat(templateContext["require-full-access"], equalTo<Any>(true))
- assertThat(templateContext["negative-trust"], equalTo<Any>(7))
- assertThat(templateContext["positive-trust"], equalTo<Any>(8))
assertThat(templateContext["post-cut-off-length"], equalTo<Any>(51))
assertThat(templateContext["posts-per-page"], equalTo<Any>(10))
- assertThat(templateContext["trust-comment"], equalTo<Any>("11"))
}
}
}
@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")
}
}
@Test
- fun `trust comment can be set`() {
- verifyThatPreferencesCanBeSet("trust-comment", "trust", "trust") { core.preferences.trustComment }
+ fun `page can be created by dependency injection`() {
+ assertThat(baseInjector.getInstance<OptionsPage>(), notNullValue())
}
@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 `page is annotated with correct menuname`() {
+ assertThat(page.menuName, equalTo("Options"))
}
@Test
- fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<OptionsPage>(), notNullValue())
+ fun `page is annotated with correct template path`() {
+ assertThat(page.templatePath, equalTo("/templates/options.html"))
}
}