Skip to content
Permalink
Browse files

[JENKINS-36894] Refactor tests and Add tests for shortcuts in rebuild…

… pages.
  • Loading branch information
ikedam committed Aug 7, 2016
1 parent 0028b9f commit d0b69aa58f035f29399b0ec69da9788d21d9f6ab
@@ -41,7 +41,7 @@ drawParameterBody(f, valueIt, axes, project, build, layouter);

private void drawParameterBody(Namespace f,MatrixCombinationsParameterValue valueIt,AxisList axes,MatrixProject project,MatrixBuild build,Layouter layouter) {
f.entry(title: valueIt.getName(), description: it.getDescription()) {
div(name: "parameter") {
div(name: "parameter", class: "matrix-combinations-parameter") {
input(type: "hidden", name: "name", value: valueIt.getName())
nsProject.matrix(it: build, layouter: layouter) {
drawTableBall(p, project.axes, valueIt, project, build, layouter);
@@ -60,16 +60,20 @@ private void drawTableBall(Combination combination,AxisList axes,MatrixCombinati
if (!layouter.x || !layouter.y) {
text(combination.toString(layouter.z))
}
f.checkbox(checked: "true",onclick:"return false;", onkeydown:"return false;", name: "values",id: String.format("checkbox%s-%s", matrixValue.getName(), combination.toString('-' as char, '-' as char)));
input(type: "hidden", name: "confs", value: combination.toString());
span(class: "combination", "data-combination": combination.toIndex(axes)) {
f.checkbox(checked: true, name: "values", readonly: true);
input(type: "hidden", name: "confs", value: combination.toString());
}
}

} else {
img(src: "${imagesURL}/24x24/grey.gif");
if (!layouter.x || !layouter.y) {
text(combination.toString(layouter.z))
}
f.checkbox(checked: "false",onclick:"return false;", onkeydown:"return false;", name: "values",id: String.format("checkbox%s-%s", matrixValue.getName(), combination.toString('-' as char, '-' as char)));
input(type: "hidden", name: "confs", value: combination.toString());
span(class: "combination", "data-combination": combination.toIndex(axes)) {
f.checkbox(checked: false, name: "values", readonly: true);
input(type: "hidden", name: "confs", value: combination.toString());
}
}
}
@@ -24,10 +24,19 @@

package hudson.plugins.matrix_configuration_parameter;

import static org.junit.Assert.assertEquals;

import org.apache.commons.httpclient.HttpStatus;
import org.jvnet.hudson.test.JenkinsRule;

import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import hudson.matrix.AxisList;
import hudson.matrix.Combination;

/**
*
@@ -65,4 +74,43 @@ public void printContentIfNecessary(WebResponse webResponse) {
}
};
}

public void checkCombination(HtmlPage page, boolean checked, AxisList axes, String... values) throws Exception {
checkCombination(page, 0, checked, axes, values);
}

public void checkCombination(HtmlPage page, int index, boolean checked, AxisList axes, String... values) throws Exception {
page.<HtmlElement>selectNodes("//*[@class='matrix-combinations-parameter']").get(index)
.<HtmlCheckBoxInput>selectNodes(String.format(
"//*[@data-combination='%s']//input[@type='checkbox']",
new Combination(axes, values).toIndex(axes)
)).get(0).setChecked(checked);
}

public void clickShortcut(HtmlPage page, String name) throws Exception {
clickShortcut(page, 0, name);
}

public void clickShortcut(HtmlPage page, int index, String name) throws Exception {
page.<HtmlElement>selectNodes("//*[@class='matrix-combinations-parameter']").get(index)
.<HtmlAnchor>selectNodes(String.format(
"//a[@data-shortcut-id='%s']",
name
)).get(0).click();
}

public void assertCombinationChecked(HtmlPage page, boolean checked, AxisList axes, String... values) throws Exception {
assertCombinationChecked(page, 0, checked, axes, values);
}

public void assertCombinationChecked(HtmlPage page, int index, boolean checked, AxisList axes, String... values) throws Exception {
assertEquals(
checked,
page.<HtmlElement>selectNodes("//*[@class='matrix-combinations-parameter']").get(index)
.<HtmlCheckBoxInput>selectNodes(String.format(
"//*[@data-combination='%s']//input[@type='checkbox']",
new Combination(axes, values).toIndex(axes)
)).get(0).isChecked()
);
}
}

0 comments on commit d0b69aa

Please sign in to comment.
You can’t perform that action at this time.