Copilot commented on code in PR #15965:
URL: https://github.com/apache/grails-core/pull/15965#discussion_r3561825366
##########
grails-fields/src/test/groovy/grails/plugin/formfields/DefaultFieldTemplateSpec.groovy:
##########
@@ -46,54 +44,42 @@ class DefaultFieldTemplateSpec extends Specification
implements TagLibUnitTest<F
<%= widget %>
</div>'''
}
-
- static Jerry $(String html) {
- jerry(html).children()
- }
-
- void "default rendering"() {
- when:
- def output = tagLib.renderDefaultField(model)
- then:
- def root = $(output.toString())
- root.is('div.fieldcontain')
+ void "default rendering"() {
+ when:
+ String output = tagLib.renderDefaultField(model).toString()
+
+ then:
+ output.contains('<div class="fieldcontain">')
- and:
- def label = root.find('label')
- label.text() == 'label'
- label.attr('for') == 'property'
-
- and:
- label.next().is('input[name=property]')
- }
+ and:
+ output.contains('<label class="" for="property">label</label>')
+ output.indexOf('<label class="" for="property">label</label>') <
output.indexOf('<input name="property">')
+ }
- void "container marked as invalid"() {
- given:
- model.invalid = true
+ void "container marked as invalid"() {
+ given:
+ model.invalid = true
- when:
- def output = tagLib.renderDefaultField(model)
-
- then:
- $(output.toString()).hasClass('error')
- }
+ when:
+ String output = tagLib.renderDefaultField(model).toString()
- void "container marked as required"() {
- given:
- model.required = true
+ then:
+ output.contains('<div class="fieldcontain error">')
+ }
- when:
- def output = tagLib.renderDefaultField(model)
+ void "container marked as required"() {
+ given:
+ model.required = true
- then:
- def root = $(output.toString())
- root.hasClass('required')
-
- and:
- def indicator = root.find('label .required-indicator')
- indicator.size()
- indicator.text() == '*'
- }
+ when:
+ String output = tagLib.renderDefaultField(model).toString()
+
+ then:
+ output.contains('<div class="fieldcontain required">')
+
+ and:
+ output.contains('<span class="required-indicator">*</span>')
Review Comment:
Similar to the invalid case, these assertions currently require the exact
`class="fieldcontain required"` and the exact span markup. Regex-based checks
for required/indicator tokens are less brittle while still confirming the
rendered semantics.
##########
grails-fields/src/test/groovy/grails/plugin/formfields/DefaultFieldTemplateSpec.groovy:
##########
@@ -46,54 +44,42 @@ class DefaultFieldTemplateSpec extends Specification
implements TagLibUnitTest<F
<%= widget %>
</div>'''
}
-
- static Jerry $(String html) {
- jerry(html).children()
- }
-
- void "default rendering"() {
- when:
- def output = tagLib.renderDefaultField(model)
- then:
- def root = $(output.toString())
- root.is('div.fieldcontain')
+ void "default rendering"() {
+ when:
+ String output = tagLib.renderDefaultField(model).toString()
+
+ then:
+ output.contains('<div class="fieldcontain">')
- and:
- def label = root.find('label')
- label.text() == 'label'
- label.attr('for') == 'property'
-
- and:
- label.next().is('input[name=property]')
- }
+ and:
+ output.contains('<label class="" for="property">label</label>')
+ output.indexOf('<label class="" for="property">label</label>') <
output.indexOf('<input name="property">')
Review Comment:
The new assertions in this test are more strict than the previous DOM-based
checks (they now require an exact `<label class="" ...>` serialization). This
can create unnecessary brittleness if the MarkupBuilder output changes in
non-semantic ways (e.g., omitting an empty class attribute or reordering
attributes). Prefer regex-based assertions that validate the important
semantics (label text + for-attribute, and that the label appears before the
input) without depending on the exact attribute list/order.
##########
grails-fields/src/test/groovy/grails/plugin/formfields/DefaultFieldTemplateSpec.groovy:
##########
@@ -46,54 +44,42 @@ class DefaultFieldTemplateSpec extends Specification
implements TagLibUnitTest<F
<%= widget %>
</div>'''
}
-
- static Jerry $(String html) {
- jerry(html).children()
- }
-
- void "default rendering"() {
- when:
- def output = tagLib.renderDefaultField(model)
- then:
- def root = $(output.toString())
- root.is('div.fieldcontain')
+ void "default rendering"() {
+ when:
+ String output = tagLib.renderDefaultField(model).toString()
+
+ then:
+ output.contains('<div class="fieldcontain">')
- and:
- def label = root.find('label')
- label.text() == 'label'
- label.attr('for') == 'property'
-
- and:
- label.next().is('input[name=property]')
- }
+ and:
+ output.contains('<label class="" for="property">label</label>')
+ output.indexOf('<label class="" for="property">label</label>') <
output.indexOf('<input name="property">')
+ }
- void "container marked as invalid"() {
- given:
- model.invalid = true
+ void "container marked as invalid"() {
+ given:
+ model.invalid = true
- when:
- def output = tagLib.renderDefaultField(model)
-
- then:
- $(output.toString()).hasClass('error')
- }
+ when:
+ String output = tagLib.renderDefaultField(model).toString()
- void "container marked as required"() {
- given:
- model.required = true
+ then:
+ output.contains('<div class="fieldcontain error">')
Review Comment:
This assertion depends on the exact class string `"fieldcontain error"`. The
previous test only verified that the container had the `error` class
(order-insensitive). Using a regex that checks for both `fieldcontain` and
`error` as class tokens keeps the test focused on behavior and avoids coupling
to class ordering.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]