1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui.po; |
21 |
|
|
22 |
|
import org.openqa.selenium.By; |
23 |
|
import org.openqa.selenium.WebElement; |
24 |
|
import org.openqa.selenium.support.FindBy; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
@version |
30 |
|
@since |
31 |
|
|
32 |
|
|
|
|
| 52% |
Uncovered Elements: 24 (50) |
Complexity: 13 |
Complexity Density: 0.38 |
|
33 |
|
public class EditRightsPane extends BaseElement |
34 |
|
{ |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
36 |
|
public enum Right |
37 |
|
{ |
38 |
|
VIEW, |
39 |
|
COMMENT, |
40 |
|
EDIT, |
41 |
|
DELETE, |
42 |
|
ADMIN, |
43 |
|
REGISTER, |
44 |
|
PROGRAM; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
3 |
int getColumnIndex()... |
47 |
|
{ |
48 |
3 |
return this.ordinal() + 2; |
49 |
|
} |
50 |
|
} |
51 |
|
|
52 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.67 |
|
53 |
|
public enum State |
54 |
|
{ |
55 |
|
NONE("/xwiki/resources/js/xwiki/usersandgroups/img/none.png"), |
56 |
|
ALLOW("/xwiki/resources/js/xwiki/usersandgroups/img/allow.png"), |
57 |
|
DENY("/xwiki/resources/js/xwiki/usersandgroups/img/deny1.png"); |
58 |
|
|
59 |
|
String imageURL; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
3 |
State(String imageURL)... |
62 |
|
{ |
63 |
3 |
this.imageURL = imageURL; |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
1 |
State getNextState()... |
67 |
|
{ |
68 |
1 |
return values()[(ordinal() + 1) % values().length]; |
69 |
|
} |
70 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
71 |
3 |
static State getButtonState(WebElement button)... |
72 |
|
{ |
73 |
3 |
for (State s : values()) { |
74 |
4 |
if ((button.getAttribute("src").endsWith(s.imageURL))) { |
75 |
3 |
return s; |
76 |
|
} |
77 |
|
} |
78 |
0 |
return NONE; |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
|
private LiveTableElement rightsTable; |
83 |
|
|
84 |
|
@FindBy(id = "uorgu") |
85 |
|
private WebElement showUsersField; |
86 |
|
|
87 |
|
@FindBy(id = "uorgg") |
88 |
|
private WebElement showGroupsField; |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
90 |
1 |
public void switchToUsers()... |
91 |
|
{ |
92 |
1 |
this.showUsersField.click(); |
93 |
1 |
getRightsTable().waitUntilReady(); |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
96 |
0 |
public void switchToGroups()... |
97 |
|
{ |
98 |
0 |
this.showGroupsField.click(); |
99 |
0 |
getRightsTable().waitUntilReady(); |
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
102 |
0 |
public State getGuestRight(Right right)... |
103 |
|
{ |
104 |
0 |
final By iconLocator = By.xpath("//tr[@id='unregistered']/td[" + right.getColumnIndex() + "]/img"); |
105 |
0 |
final WebElement icon = getDriver().findElement(iconLocator); |
106 |
0 |
return State.getButtonState(icon); |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
109 |
2 |
public State getRight(String entityName, Right right)... |
110 |
|
{ |
111 |
2 |
final By iconLocator = |
112 |
|
By.xpath("//*[@id='usersandgroupstable-display']//td[@class='username']/a[contains(@href, '" + entityName |
113 |
|
+ "')]/../../td[" + right.getColumnIndex() + "]/img"); |
114 |
2 |
final WebElement icon = getDriver().findElement(iconLocator); |
115 |
2 |
return State.getButtonState(icon); |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
118 |
0 |
public void clickGuestRight(Right right)... |
119 |
|
{ |
120 |
0 |
try { |
121 |
0 |
getDriver().executeJavascript( |
122 |
|
"window.__oldConfirm = window.confirm; window.confirm = function() { return true; };"); |
123 |
0 |
final By buttonLocator = By.xpath("*//tr[@id='unregistered']/td[" + right.getColumnIndex() + "]/img"); |
124 |
0 |
final WebElement button = getDriver().findElement(buttonLocator); |
125 |
0 |
State currentState = State.getButtonState(button); |
126 |
0 |
button.click(); |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
0 |
getDriver().waitUntilElementEndsWithAttributeValue(buttonLocator, "src", |
131 |
|
currentState.getNextState().imageURL); |
132 |
|
} finally { |
133 |
0 |
getDriver().executeJavascript("window.confirm = window.__oldConfirm;"); |
134 |
|
} |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
@param |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
143 |
1 |
public void clickRight(String entityName, Right right)... |
144 |
|
{ |
145 |
1 |
try { |
146 |
1 |
getDriver().executeJavascript( |
147 |
|
"window.__oldConfirm = window.confirm; window.confirm = function() { return true; };"); |
148 |
1 |
final By buttonLocator = |
149 |
|
By.xpath("//*[@id='usersandgroupstable-display']//td[@class='username']/a[contains(@href, '" |
150 |
|
+ entityName + "')]/../../td[" + right.getColumnIndex() + "]/img"); |
151 |
1 |
final WebElement button = getDriver().findElement(buttonLocator); |
152 |
1 |
State currentState = State.getButtonState(button).getNextState(); |
153 |
1 |
button.click(); |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
1 |
getDriver().waitUntilElementEndsWithAttributeValue(buttonLocator, "src", currentState.imageURL); |
158 |
|
} finally { |
159 |
1 |
getDriver().executeJavascript("window.confirm = window.__oldConfirm;"); |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
@param |
167 |
|
@param |
168 |
|
@param |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
170 |
1 |
public void setRight(String entityName, Right right, State wantedState)... |
171 |
|
{ |
172 |
2 |
while (getRight(entityName, right) != wantedState) { |
173 |
1 |
clickRight(entityName, right); |
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
@param |
181 |
|
@param |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
183 |
0 |
public void setGuestRight(Right right, State wantedState)... |
184 |
|
{ |
185 |
0 |
while (getGuestRight(right) != wantedState) { |
186 |
0 |
clickGuestRight(right); |
187 |
|
} |
188 |
|
} |
189 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
0 |
public String getURL(String space, String page)... |
191 |
|
{ |
192 |
0 |
return getUtil().getURL(space, page, "edit", "editor=rights"); |
193 |
|
} |
194 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
195 |
1 |
public LiveTableElement getRightsTable()... |
196 |
|
{ |
197 |
1 |
if (this.rightsTable == null) { |
198 |
1 |
this.rightsTable = new LiveTableElement("usersandgroupstable"); |
199 |
|
} |
200 |
1 |
return this.rightsTable; |
201 |
|
} |
202 |
|
} |