~wegtam/smederee

Showing details for patch cda9c272513bbcd8ca8e75a2fc5af4b545121ef3.
2024-10-24 (Thu), 9:10 AM - Jens Grassel - cda9c272513bbcd8ca8e75a2fc5af4b545121ef3

Add test for FormField

Summary of changes
1 files added
  • modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldTest.scala
diff -rN -u old-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldTest.scala new-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldTest.scala
--- old-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldTest.scala	1970-01-01 00:00:00.000000000 +0000
+++ new-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldTest.scala	2024-11-21 22:49:37.682257925 +0000
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2022 Contributors as noted in the AUTHORS.md file
+ *
+ * Licensed under the EUPL
+ */
+
+package de.smederee.hub.forms
+
+import de.smederee.hub.forms.types.FormField
+
+import munit.*
+
+import org.scalacheck.*
+import org.scalacheck.Prop.*
+
+final class FormFieldTest extends ScalaCheckSuite {
+    private val genFormField: Gen[FormField] = Gen.nonEmptyStringOf(Gen.alphaNumChar).map(FormField.apply)
+
+    property("from must only allow non-empty strings and trim them") {
+        forAll { (formFieldName: String) =>
+            val expected = Option(formFieldName).map(_.trim).filter(_.nonEmpty)
+            assertEquals(FormField.from(formFieldName).map(_.toString), expected)
+        }
+    }
+
+    property("FormField must provide an automatic conversion to String") {
+        def acceptString(name: String): Int = name.length()
+
+        forAll(genFormField) { (formField: FormField) =>
+            assertEquals(acceptString(formField), formField.toString.length())
+        }
+    }
+}