Skip to content

Commit def0253

Browse files
committed
[JENKINS-74967] Add test and changelog entry
1 parent 012cd21 commit def0253

File tree

4 files changed

+289
-0
lines changed

4 files changed

+289
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- Upgrade node requirement from 18.18.0 to 22.14.0
3030
- JENKINS-74963: Spinning animation is not removed due to exception, select element is not found by plug-in
3131
(duplicated issues: JENKINS-73919)
32+
- JENKINS-74967: Active choice parameter filter throws JavaScript error for parameter change event in browser console
3233

3334
## Version 2.8.6 (2024/11/23)
3435

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014-2023 Ioannis Moutsatsos, Bruno P. Kinoshita
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.biouno.unochoice.issue74967;
25+
26+
import org.biouno.unochoice.BaseUiTest;
27+
import org.junit.jupiter.api.Test;
28+
import org.jvnet.hudson.test.Issue;
29+
import org.jvnet.hudson.test.recipes.LocalData;
30+
import org.openqa.selenium.By;
31+
import org.openqa.selenium.WebElement;
32+
import org.openqa.selenium.support.ui.ExpectedConditions;
33+
import org.openqa.selenium.support.ui.Select;
34+
35+
import java.util.List;
36+
37+
import static org.junit.jupiter.api.Assertions.assertEquals;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
39+
40+
/**
41+
* In JENKINS-74967 a JS exception when the user entered anything in the filter field.
42+
* The JavaScript code is not very well-designed (mea-culpa) so it is not easy to test
43+
* it. For that reason, the config.xml attached in this issue was used here to write a
44+
* complete e2e test (i.e. yes, we are killing the ant with an elephant).
45+
*/
46+
@Issue("JENKINS-74967")
47+
class TestFilter extends BaseUiTest {
48+
49+
/**
50+
* Tests that the page loads with paramA=AAA, filter empty, and paramB showing AAA-1, AAA-2, and AAA-3.
51+
* Then, it enters the filter text BB, paramA is updated to BBB (matches filter), which cascades to
52+
* changing paramB to BBB-1, BBB-2, BBB-3.
53+
*
54+
* @throws Exception resolving the test web pages
55+
*/
56+
@Test
57+
@LocalData("test")
58+
void test() throws Exception {
59+
driver.get(j.getURL().toString() + "job/test/build");
60+
61+
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".jenkins-spinner")));
62+
63+
WebElement paramA = findSelect("paramA");
64+
assertTrue(paramA.isDisplayed());
65+
assertTrue(paramA.isEnabled());
66+
assertEquals("AAA", new Select(paramA).getFirstSelectedOption().getText());
67+
68+
List<WebElement> paramB = findRadios("paramB");
69+
for (int i = 0; i < paramB.size(); i++) {
70+
WebElement param = paramB.get(i);
71+
assertTrue(param.isDisplayed());
72+
assertTrue(param.isEnabled());
73+
assertEquals("AAA-" + (i + 1), param.getDomAttribute("value"));
74+
}
75+
76+
WebElement filterElement = driver.findElement(By.cssSelector("div.active-choice[name='parameter'] > input.uno_choice_filter"));
77+
filterElement.sendKeys("BB");
78+
79+
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".jenkins-spinner")));
80+
81+
paramA = findSelect("paramA");
82+
assertTrue(paramA.isDisplayed());
83+
assertTrue(paramA.isEnabled());
84+
assertEquals("BBB", new Select(paramA).getFirstSelectedOption().getText());
85+
86+
paramB = findRadios("paramB");
87+
for (int i = 0; i < paramB.size(); i++) {
88+
WebElement param = paramB.get(i);
89+
assertTrue(param.isDisplayed());
90+
assertTrue(param.isEnabled());
91+
assertEquals("BBB-" + (i + 1), param.getDomAttribute("value"));
92+
}
93+
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014-2025 Ioannis Moutsatsos, Bruno P. Kinoshita
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
/**
26+
* See JENKINS-74967.
27+
*
28+
* @since 2.8.7
29+
*/
30+
package org.biouno.unochoice.issue74967;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version='1.1' encoding='UTF-8'?>
2+
<flow-definition plugin="[email protected]_0c6f3a_4b_4">
3+
<actions>
4+
<org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction plugin="[email protected]_a_660950e">
5+
<jobPropertyDescriptors>
6+
<string>hudson.model.ParametersDefinitionProperty</string>
7+
</jobPropertyDescriptors>
8+
</org.jenkinsci.plugins.workflow.multibranch.JobPropertyTrackerAction>
9+
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="[email protected]_d93"/>
10+
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="[email protected]_d93">
11+
<jobProperties/>
12+
<triggers/>
13+
<parameters/>
14+
<options/>
15+
</org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
16+
</actions>
17+
<description></description>
18+
<keepDependencies>false</keepDependencies>
19+
<properties>
20+
<hudson.model.ParametersDefinitionProperty>
21+
<parameterDefinitions>
22+
<org.biouno.unochoice.ChoiceParameter plugin="[email protected]">
23+
<name>paramA</name>
24+
<description>Choose opion</description>
25+
<randomName>choice-parameter-26751749888928</randomName>
26+
<visibleItemCount>1</visibleItemCount>
27+
<script class="org.biouno.unochoice.model.GroovyScript">
28+
<secureScript plugin="[email protected]_98a_4e95b_2d">
29+
<script>return [&quot;AAA&quot;,&quot;BBB&quot;,&quot;CCC&quot;]</script>
30+
<sandbox>true</sandbox>
31+
<classpath/>
32+
</secureScript>
33+
<secureFallbackScript plugin="[email protected]_98a_4e95b_2d">
34+
<script>return[&quot;ERROR paramA&quot;]</script>
35+
<sandbox>true</sandbox>
36+
<classpath/>
37+
</secureFallbackScript>
38+
</script>
39+
<choiceType>PT_SINGLE_SELECT</choiceType>
40+
<filterable>true</filterable>
41+
<filterLength>1</filterLength>
42+
</org.biouno.unochoice.ChoiceParameter>
43+
<org.biouno.unochoice.CascadeChoiceParameter plugin="[email protected]">
44+
<name>paramB</name>
45+
<description>chose related option</description>
46+
<randomName>choice-parameter-26751750130750</randomName>
47+
<visibleItemCount>1</visibleItemCount>
48+
<script class="org.biouno.unochoice.model.GroovyScript">
49+
<secureScript plugin="[email protected]_98a_4e95b_2d">
50+
<script>
51+
if (paramA.equals(&quot;AAA&quot;)) {
52+
return [&quot;AAA-1&quot;,&quot;AAA-2&quot;,&quot;AAA-3&quot;]
53+
}
54+
else if (paramA.equals(&quot;BBB&quot;)) {
55+
return [&quot;BBB-1&quot;,&quot;BBB-2&quot;,&quot;BBB-3&quot;]
56+
}
57+
else if (paramA.equals(&quot;CCC&quot;)) {
58+
return [&quot;CCC-1&quot;,&quot;CCC-2&quot;,&quot;CCC-3&quot;]
59+
}
60+
else {
61+
return [&quot;UNK&quot;]
62+
}
63+
</script>
64+
<sandbox>true</sandbox>
65+
<classpath/>
66+
</secureScript>
67+
<secureFallbackScript plugin="[email protected]_98a_4e95b_2d">
68+
<script>return[&quot;ERROR paramB&quot;]</script>
69+
<sandbox>true</sandbox>
70+
<classpath/>
71+
</secureFallbackScript>
72+
</script>
73+
<parameters class="linked-hash-map"/>
74+
<referencedParameters>paramA</referencedParameters>
75+
<choiceType>PT_RADIO</choiceType>
76+
<filterable>false</filterable>
77+
<filterLength>1</filterLength>
78+
</org.biouno.unochoice.CascadeChoiceParameter>
79+
</parameterDefinitions>
80+
</hudson.model.ParametersDefinitionProperty>
81+
</properties>
82+
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="[email protected]_30">
83+
<script>#!groovy
84+
85+
properties([
86+
parameters([
87+
[
88+
$class: &apos;ChoiceParameter&apos;,
89+
choiceType: &apos;PT_SINGLE_SELECT&apos;,
90+
description: &apos;Choose opion&apos;,
91+
filterLength: 1,
92+
filterable: true,
93+
name: &apos;paramA&apos;,
94+
script: [
95+
$class: &apos;GroovyScript&apos;,
96+
script: [
97+
classpath: [],
98+
sandbox: true,
99+
script: &apos;return [&quot;AAA&quot;,&quot;BBB&quot;,&quot;CCC&quot;]&apos;
100+
],
101+
fallbackScript: [
102+
classpath: [],
103+
sandbox: true,
104+
script: &apos;return[&quot;ERROR paramA&quot;]&apos;
105+
]
106+
]
107+
],
108+
[
109+
$class: &apos;CascadeChoiceParameter&apos;,
110+
choiceType: &apos;PT_RADIO&apos;,
111+
description: &apos;chose related option&apos;,
112+
filterLength: 1,
113+
filterable: false,
114+
name: &apos;paramB&apos;,
115+
referencedParameters: &apos;paramA&apos;,
116+
script: [
117+
$class: &apos;GroovyScript&apos;,
118+
script: [
119+
classpath: [],
120+
sandbox: true,
121+
script: &apos;&apos;&apos;
122+
if (paramA.equals(&quot;AAA&quot;)) {
123+
return [&quot;AAA-1&quot;,&quot;AAA-2&quot;,&quot;AAA-3&quot;]
124+
}
125+
else if (paramA.equals(&quot;BBB&quot;)) {
126+
return [&quot;BBB-1&quot;,&quot;BBB-2&quot;,&quot;BBB-3&quot;]
127+
}
128+
else if (paramA.equals(&quot;CCC&quot;)) {
129+
return [&quot;CCC-1&quot;,&quot;CCC-2&quot;,&quot;CCC-3&quot;]
130+
}
131+
else {
132+
return [&quot;UNK&quot;]
133+
}
134+
&apos;&apos;&apos;
135+
],
136+
fallbackScript: [
137+
classpath: [],
138+
sandbox: true,
139+
script: &apos;return[&quot;ERROR paramB&quot;]&apos;
140+
]
141+
]
142+
]
143+
])
144+
])
145+
146+
pipeline {
147+
agent any
148+
149+
stages {
150+
stage(&apos;Params&apos;) {
151+
steps {
152+
echo &quot;paramA: ${params.paramA}&quot;
153+
echo &quot;paramB: ${params.paramB}&quot;
154+
}
155+
}
156+
}
157+
}
158+
</script>
159+
<sandbox>true</sandbox>
160+
</definition>
161+
<triggers/>
162+
<disabled>false</disabled>
163+
</flow-definition>

0 commit comments

Comments
 (0)