You are viewing a plain text version of this content. The canonical link for it is here.
Posted to geb-notifications@groovy.apache.org by jo...@apache.org on 2024/12/05 20:38:24 UTC

(groovy-geb) branch master updated (86ad0fcd -> c7d34ba7)

This is an automated email from the ASF dual-hosted git repository.

jonnybot pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy-geb.git


    from 86ad0fcd minor refactor: clarify rat exclusions
     new df7d7091 #194 - Reformat any date time values passed to the DateTimeLocalInput module into a format that will be accepted by Chrome
     new c7d34ba7 Remove warning, rename method, tidy formatting

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 gradle/codenarc/rulesets.groovy                    |  3 +++
 .../groovy/geb/module/DateTimeLocalInput.groovy    | 31 +++++++++++++++++++---
 .../geb/module/DateTimeLocalInputSpec.groovy       | 13 +++++----
 3 files changed, 39 insertions(+), 8 deletions(-)


(groovy-geb) 01/02: #194 - Reformat any date time values passed to the DateTimeLocalInput module into a format that will be accepted by Chrome

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jonnybot pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy-geb.git

commit df7d70914b2fce8b6ab72fab822d31b75c205c95
Author: Adam Pounder <35...@users.noreply.gitlab.com>
AuthorDate: Thu Oct 24 13:13:13 2024 +0100

    #194 - Reformat any date time values passed to the DateTimeLocalInput module into a format that will be accepted by Chrome
---
 .../groovy/geb/module/DateTimeLocalInput.groovy    | 31 ++++++++++++++++++++--
 .../geb/module/DateTimeLocalInputSpec.groovy       | 13 +++++----
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy b/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy
index 92c7f46f..cef76fff 100644
--- a/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy
+++ b/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy
@@ -15,18 +15,36 @@
  */
 package geb.module
 
+import groovy.util.logging.Slf4j
+
 import java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
+import java.time.format.DateTimeFormatterBuilder
+
+import static java.time.temporal.ChronoField.*
 
+@Slf4j
 class DateTimeLocalInput extends AbstractInput {
 
+    private static final DateTimeFormatter DATE_TIME_FORMAT = new DateTimeFormatterBuilder()
+            .append(DateTimeFormatter.ISO_LOCAL_DATE)
+            .appendLiteral('T')
+            .appendValue(HOUR_OF_DAY, 2)
+            .appendLiteral(':')
+            .appendValue(MINUTE_OF_HOUR, 2)
+            .appendLiteral(':')
+            .appendValue(SECOND_OF_MINUTE, 2)
+            .appendFraction(MILLI_OF_SECOND, 0, 3, true)
+            .toFormatter()
+    
     final String inputType = 'datetime-local'
 
     void setDateTime(LocalDateTime dateTime) {
-        value(dateTime.toString())
+        value(reformat(dateTime))
     }
 
     void setDateTime(String iso8601FormattedDateTime) {
-        value(iso8601FormattedDateTime)
+        setDateTime(LocalDateTime.parse(iso8601FormattedDateTime))
     }
 
     LocalDateTime getDateTime() {
@@ -39,4 +57,13 @@ class DateTimeLocalInput extends AbstractInput {
         super.isTypeValid(type) || type == "text"
     }
 
+    private static String reformat(LocalDateTime localDateTime) {
+        String inputValue = localDateTime.format(DATE_TIME_FORMAT)
+        if(localDateTime.toString() != inputValue) {
+            log.warn("The datetime value {} was truncated to {} as it was being used to set the value of a <input type=\"datetime-local\" />",
+                    localDateTime, 
+                    inputValue)
+        }
+        return inputValue
+    }
 }
diff --git a/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy b/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy
index 2c4c6447..7a0d17fa 100644
--- a/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy
+++ b/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy
@@ -18,13 +18,12 @@ package geb.module
 import geb.test.GebSpecWithCallbackServer
 import geb.test.browsers.Chrome
 import geb.test.browsers.RequiresRealBrowser
-import spock.lang.Ignore
 
 import java.time.LocalDateTime
+import java.time.temporal.ChronoUnit
 
 @Chrome
 @RequiresRealBrowser // maybe due to https://sourceforge.net/p/htmlunit/bugs/1923/
-@Ignore("https://github.com/geb/geb/issues/188")
 class DateTimeLocalInputSpec extends GebSpecWithCallbackServer {
 
     def setup() {
@@ -47,7 +46,7 @@ class DateTimeLocalInputSpec extends GebSpecWithCallbackServer {
         input.dateTime = dateTime
 
         then:
-        input.dateTime == dateTime
+        input.dateTime == truncated(dateTime)
 
         where:
         dateTime = LocalDateTime.now()
@@ -58,7 +57,7 @@ class DateTimeLocalInputSpec extends GebSpecWithCallbackServer {
         input.dateTime = dateTime.toString()
 
         then:
-        input.dateTime == dateTime
+        input.dateTime == truncated(dateTime)
 
         where:
         dateTime = LocalDateTime.now()
@@ -72,10 +71,14 @@ class DateTimeLocalInputSpec extends GebSpecWithCallbackServer {
         input.dateTime = dateTime.plusDays(1)
 
         then:
-        input.dateTime == dateTime.plusDays(1)
+        input.dateTime == truncated(dateTime.plusDays(1))
 
         where:
         dateTime = LocalDateTime.now()
     }
+    
+    private static LocalDateTime truncated(LocalDateTime ldt) {
+        return ldt.truncatedTo(ChronoUnit.MILLIS)
+    }
 
 }


(groovy-geb) 02/02: Remove warning, rename method, tidy formatting

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jonnybot pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy-geb.git

commit c7d34ba71a7554ce2808c9d7e9355ce66d547057
Author: Adam Pounder <35...@users.noreply.gitlab.com>
AuthorDate: Sun Nov 17 10:55:37 2024 +0000

    Remove warning, rename method, tidy formatting
---
 gradle/codenarc/rulesets.groovy                    |  3 +++
 .../groovy/geb/module/DateTimeLocalInput.groovy    | 24 ++++++++++------------
 .../geb/module/DateTimeLocalInputSpec.groovy       |  2 +-
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/gradle/codenarc/rulesets.groovy b/gradle/codenarc/rulesets.groovy
index cc1f2396..0d1342f9 100644
--- a/gradle/codenarc/rulesets.groovy
+++ b/gradle/codenarc/rulesets.groovy
@@ -167,6 +167,9 @@ ruleset {
         UnnecessarySemicolon {
             doNotApplyToFileNames = 'PageOrientedSpec.groovy, StrongTypingSpec.groovy'
         }
+        UnnecessaryReturnKeyword {
+            enabled = false
+        }
     }
     ruleset('rulesets/unused.xml')
 }
\ No newline at end of file
diff --git a/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy b/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy
index cef76fff..6ffb92dd 100644
--- a/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy
+++ b/module/geb-core/src/main/groovy/geb/module/DateTimeLocalInput.groovy
@@ -26,6 +26,7 @@ import static java.time.temporal.ChronoField.*
 @Slf4j
 class DateTimeLocalInput extends AbstractInput {
 
+    /* codenarc-disable */
     private static final DateTimeFormatter DATE_TIME_FORMAT = new DateTimeFormatterBuilder()
             .append(DateTimeFormatter.ISO_LOCAL_DATE)
             .appendLiteral('T')
@@ -36,15 +37,22 @@ class DateTimeLocalInput extends AbstractInput {
             .appendValue(SECOND_OF_MINUTE, 2)
             .appendFraction(MILLI_OF_SECOND, 0, 3, true)
             .toFormatter()
-    
+    /* codenarc-enable */
+
     final String inputType = 'datetime-local'
 
     void setDateTime(LocalDateTime dateTime) {
-        value(reformat(dateTime))
+        value(formatForBrowser(dateTime))
+    }
+
+    // codenarc-disable StaticMethodsBeforeInstanceMethods
+    static String formatForBrowser(LocalDateTime localDateTime) {
+        return localDateTime.format(DATE_TIME_FORMAT)
     }
+    // codenarc-enable
 
     void setDateTime(String iso8601FormattedDateTime) {
-        setDateTime(LocalDateTime.parse(iso8601FormattedDateTime))
+        dateTime = LocalDateTime.parse(iso8601FormattedDateTime)
     }
 
     LocalDateTime getDateTime() {
@@ -56,14 +64,4 @@ class DateTimeLocalInput extends AbstractInput {
     protected boolean isTypeValid(String type) {
         super.isTypeValid(type) || type == "text"
     }
-
-    private static String reformat(LocalDateTime localDateTime) {
-        String inputValue = localDateTime.format(DATE_TIME_FORMAT)
-        if(localDateTime.toString() != inputValue) {
-            log.warn("The datetime value {} was truncated to {} as it was being used to set the value of a <input type=\"datetime-local\" />",
-                    localDateTime, 
-                    inputValue)
-        }
-        return inputValue
-    }
 }
diff --git a/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy b/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy
index 7a0d17fa..a297c9aa 100644
--- a/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy
+++ b/module/geb-core/src/test/groovy/geb/module/DateTimeLocalInputSpec.groovy
@@ -76,7 +76,7 @@ class DateTimeLocalInputSpec extends GebSpecWithCallbackServer {
         where:
         dateTime = LocalDateTime.now()
     }
-    
+
     private static LocalDateTime truncated(LocalDateTime ldt) {
         return ldt.truncatedTo(ChronoUnit.MILLIS)
     }