~wegtam/smederee

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

Add test for FormFieldError

Summary of changes
1 files added
  • modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldErrorTest.scala
diff -rN -u old-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldErrorTest.scala new-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldErrorTest.scala
--- old-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldErrorTest.scala	1970-01-01 00:00:00.000000000 +0000
+++ new-smederee/modules/hub/src/test/scala/de/smederee/hub/forms/FormFieldErrorTest.scala	2024-11-21 22:31:28.645547158 +0000
@@ -0,0 +1,34 @@
+/*
+ * 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.FormFieldError
+
+import munit.*
+
+import org.scalacheck.*
+import org.scalacheck.Prop.*
+
+final class FormFieldErrorTest extends ScalaCheckSuite {
+    private val genFormFieldError: Gen[FormFieldError] =
+        Gen.nonEmptyStringOf(Gen.alphaNumChar).map(FormFieldError.apply)
+
+    property("from must only allow non-empty strings and trim them") {
+        forAll { (formFieldError: String) =>
+            val expected = Option(formFieldError).map(_.trim).filter(_.nonEmpty)
+            assertEquals(FormFieldError.from(formFieldError).map(_.toString), expected)
+        }
+    }
+
+    property("FormFieldError must provide an automatic conversion to String") {
+        def acceptString(name: String): Int = name.length()
+
+        forAll(genFormFieldError) { (formField: FormFieldError) =>
+            assertEquals(acceptString(formField), formField.toString.length())
+        }
+    }
+}