1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.panels.test.po; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.openqa.selenium.By; |
26 |
|
import org.openqa.selenium.Point; |
27 |
|
import org.openqa.selenium.WebDriver; |
28 |
|
import org.openqa.selenium.WebElement; |
29 |
|
import org.openqa.selenium.interactions.Actions; |
30 |
|
import org.openqa.selenium.support.FindBy; |
31 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
32 |
|
import org.xwiki.administration.test.po.AdministrationPage; |
33 |
|
import org.xwiki.test.ui.po.ViewPage; |
34 |
|
|
35 |
|
import static org.junit.Assert.assertTrue; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
@since |
43 |
|
@since |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (53) |
Complexity: 13 |
Complexity Density: 0.33 |
|
45 |
|
public class ApplicationsPanelAdministrationPage extends ViewPage |
46 |
|
{ |
47 |
|
@FindBy(id = "displayedPanels") |
48 |
|
private WebElement displayedPanels; |
49 |
|
|
50 |
|
@FindBy(id = "blacklistedPanels") |
51 |
|
private WebElement blacklistedPanels; |
52 |
|
|
53 |
|
@FindBy(id = "bt-revert") |
54 |
|
private WebElement revertButton; |
55 |
|
|
56 |
|
@FindBy(id = "bt-save") |
57 |
|
private WebElement saveButton; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
59 |
3 |
public static ApplicationsPanelAdministrationPage gotoPage()... |
60 |
|
{ |
61 |
3 |
AdministrationPage administrationPage = AdministrationPage.gotoPage(); |
62 |
3 |
assertTrue(administrationPage.hasSection("panels.applications")); |
63 |
3 |
administrationPage.clickSection("Applications", "Applications Panel"); |
64 |
3 |
return new ApplicationsPanelAdministrationPage(); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
14 |
public List<String> getApplicationsInBar()... |
68 |
|
{ |
69 |
14 |
return getApplicationsInPanel(displayedPanels); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
7 |
public List<String> getApplicationsNotInBar()... |
73 |
|
{ |
74 |
7 |
return getApplicationsInPanel(blacklistedPanels); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
77 |
21 |
private List<String> getApplicationsInPanel(WebElement panel)... |
78 |
|
{ |
79 |
21 |
List<String> results = new ArrayList<>(); |
80 |
21 |
for (WebElement elem : getDriver().findElementsWithoutWaiting(panel, |
81 |
|
By.xpath("div[contains(@class, 'panel-body')]/ul" |
82 |
|
+ "/li[contains(@class, 'draggableApp')]//span[contains(@class, 'application-label')]"))) { |
83 |
55 |
results.add(elem.getText()); |
84 |
|
} |
85 |
|
|
86 |
21 |
return results; |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
1 |
public void addApplicationInBar(String appName)... |
90 |
|
{ |
91 |
1 |
moveAppToPanel(appName, displayedPanels, blacklistedPanels); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
2 |
public void removeApplicationFromBar(String appName)... |
95 |
|
{ |
96 |
2 |
moveAppToPanel(appName, blacklistedPanels, displayedPanels); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
99 |
3 |
private void moveAppToPanel(String appName, WebElement panel, WebElement fromPanel)... |
100 |
|
{ |
101 |
3 |
By appSelector = By.linkText(appName); |
102 |
3 |
WebElement app = fromPanel.findElement(appSelector); |
103 |
3 |
WebElement destination = panel.findElement(By.tagName("ul")); |
104 |
3 |
new Actions(getDriver()).dragAndDrop(app, destination).perform(); |
105 |
|
|
106 |
3 |
getDriver().waitUntilCondition(webDriver -> |
107 |
|
getDriver().hasElementWithoutWaiting(panel, appSelector) |
108 |
|
&& !getDriver().hasElementWithoutWaiting(fromPanel, appSelector) |
109 |
|
); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
|
112 |
5 |
public void moveAppBefore(String appName, String appBeforeName)... |
113 |
|
{ |
114 |
5 |
if (appName.equals(appBeforeName)) { |
115 |
|
|
116 |
1 |
return; |
117 |
|
} |
118 |
|
|
119 |
4 |
WebElement app = displayedPanels.findElement(By.linkText(appName)); |
120 |
4 |
WebElement appBefore = displayedPanels.findElement(By.linkText(appBeforeName)); |
121 |
4 |
Point target = appBefore.getLocation(); |
122 |
4 |
Point source = app.getLocation(); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
4 |
Actions actions = new Actions(getDriver()); |
127 |
|
|
128 |
4 |
actions.clickAndHold(app); |
129 |
|
|
130 |
4 |
actions.moveByOffset(target.getX() - source.getX(), target.getY() - source.getY()); |
131 |
|
|
132 |
|
|
133 |
4 |
actions.moveByOffset(-5, -5); |
134 |
|
|
135 |
4 |
actions.perform(); |
136 |
|
|
137 |
|
|
138 |
4 |
getDriver().waitUntilCondition(new ExpectedCondition<Object>() |
139 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
140 |
4 |
@Override... |
141 |
|
public Object apply(WebDriver webDriver) |
142 |
|
{ |
143 |
4 |
Point newTarget = appBefore.getLocation(); |
144 |
4 |
Point newSource = app.getLocation(); |
145 |
4 |
return newTarget.getX() > newSource.getX() + 5 || newTarget.getY() > newSource.getY() + 5; |
146 |
|
} |
147 |
|
}); |
148 |
|
|
149 |
|
|
150 |
4 |
actions = new Actions(getDriver()); |
151 |
4 |
actions.release(); |
152 |
4 |
actions.perform(); |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
1 |
public void revert()... |
156 |
|
{ |
157 |
1 |
revertButton.click(); |
158 |
|
} |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
2 |
public void save()... |
161 |
|
{ |
162 |
2 |
saveButton.click(); |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
165 |
2 |
public boolean hasSuccessNotification()... |
166 |
|
{ |
167 |
2 |
WebElement notification = getDriver().findElement(By.className("xnotification-done")); |
168 |
2 |
return notification != null && "The configuration has been saved.".equals(notification.getText()); |
169 |
|
} |
170 |
|
} |