1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.tree.test.po; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.openqa.selenium.By; |
27 |
|
import org.openqa.selenium.JavascriptExecutor; |
28 |
|
import org.openqa.selenium.WebDriver; |
29 |
|
import org.openqa.selenium.WebElement; |
30 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
31 |
|
import org.xwiki.test.ui.po.BaseElement; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 60% |
Uncovered Elements: 18 (45) |
Complexity: 15 |
Complexity Density: 0.58 |
|
39 |
|
public class TreeElement extends BaseElement |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
private WebElement element; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@param |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
7 |
public TreeElement(WebElement element)... |
52 |
|
{ |
53 |
7 |
this.element = element; |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
@return |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
6 |
public TreeNodeElement getNode(String nodeId)... |
61 |
|
{ |
62 |
6 |
return new TreeNodeElement(this.element, By.id(nodeId)); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
@param |
67 |
|
@return |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
7 |
public boolean hasNode(String nodeId)... |
70 |
|
{ |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
7 |
return getDriver().findElementsWithoutWaiting(this.element, |
76 |
|
By.xpath(".//*[@id = '" + nodeId + "']")).size() > 0; |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
@param |
83 |
|
@return |
84 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
85 |
5 |
public TreeElement openTo(String nodeId)... |
86 |
|
{ |
87 |
5 |
if (getDriver() instanceof JavascriptExecutor) { |
88 |
5 |
((JavascriptExecutor) getDriver()).executeScript( |
89 |
|
"jQuery.jstree.reference(jQuery(arguments[0])).openTo(arguments[1])", this.element, nodeId); |
90 |
|
} |
91 |
5 |
waitForNodeSelected(nodeId); |
92 |
|
|
93 |
5 |
return this; |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
@return |
100 |
|
@since |
101 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
102 |
4 |
public TreeElement clearSelection()... |
103 |
|
{ |
104 |
4 |
if (getDriver() instanceof JavascriptExecutor) { |
105 |
4 |
((JavascriptExecutor) getDriver()).executeScript( |
106 |
|
"jQuery.jstree.reference(jQuery(arguments[0])).deselect_all()", this.element); |
107 |
|
} |
108 |
4 |
return this; |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@return |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
116 |
9 |
public TreeElement waitForIt()... |
117 |
|
{ |
118 |
|
|
119 |
|
|
120 |
9 |
getDriver().waitUntilElementIsVisible(this.element, By.cssSelector(".jstree-container-ul")); |
121 |
|
|
122 |
9 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
123 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
12 |
@Override... |
125 |
|
public Boolean apply(WebDriver driver) |
126 |
|
{ |
127 |
|
|
128 |
12 |
return !Boolean.valueOf(element.getAttribute("aria-busy")); |
129 |
|
} |
130 |
|
}); |
131 |
9 |
return this; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@param |
138 |
|
@return |
139 |
|
@since |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
141 |
6 |
public TreeElement waitForNodeSelected(String nodeId)... |
142 |
|
{ |
143 |
6 |
String selectedNodeXPath = String.format(".//*[@id = '%s' and @aria-selected = 'true']", nodeId); |
144 |
6 |
getDriver().waitUntilElementIsVisible(this.element, By.xpath(selectedNodeXPath)); |
145 |
6 |
return this; |
146 |
|
} |
147 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
0 |
protected WebElement getElement()... |
149 |
|
{ |
150 |
0 |
return this.element; |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
@return |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
156 |
0 |
public List<String> getSelectedNodeIDs()... |
157 |
|
{ |
158 |
0 |
if (getDriver() instanceof JavascriptExecutor) { |
159 |
0 |
List<String> selectedNodeIDs = |
160 |
|
(List<String>) ((JavascriptExecutor) getDriver()).executeScript( |
161 |
|
"return jQuery.jstree.reference(jQuery(arguments[0])).get_selected()", this.element); |
162 |
|
|
163 |
0 |
return selectedNodeIDs; |
164 |
|
} |
165 |
|
|
166 |
0 |
return new ArrayList<String>(); |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
172 |
0 |
public List<String> getNodeIDs()... |
173 |
|
{ |
174 |
0 |
if (getDriver() instanceof JavascriptExecutor) { |
175 |
0 |
String[] selectedNodeIDs = |
176 |
|
(String[]) ((JavascriptExecutor) getDriver()).executeScript( |
177 |
|
"return jQuery.jstree.reference(jQuery(arguments[0])).get_json('#', " |
178 |
|
+ "{flat:true, no_data:true, no_state:true})" + ".map(function(element) {return element.id});", |
179 |
|
this.element); |
180 |
|
|
181 |
0 |
return Arrays.asList(selectedNodeIDs); |
182 |
|
} |
183 |
|
|
184 |
0 |
return new ArrayList<String>(); |
185 |
|
} |
186 |
|
} |