1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.annotation.test.po; |
21 |
|
|
22 |
|
import org.openqa.selenium.By; |
23 |
|
import org.openqa.selenium.JavascriptExecutor; |
24 |
|
import org.openqa.selenium.Keys; |
25 |
|
import org.openqa.selenium.WebElement; |
26 |
|
import org.xwiki.test.ui.po.BaseElement; |
27 |
|
import org.xwiki.test.ui.po.ViewPage; |
28 |
|
|
29 |
|
|
30 |
|
@since |
31 |
|
@version |
32 |
|
|
|
|
| 84.2% |
Uncovered Elements: 12 (76) |
Complexity: 16 |
Complexity Density: 0.27 |
|
33 |
|
public class AnnotatableViewPage extends BaseElement |
34 |
|
{ |
35 |
|
private static final String XWIKI_ANNOTATION_ADD_SUCCESS = "Annotation has been successfully added"; |
36 |
|
|
37 |
|
private static final String XWIKI_ANNOTATION_DELETE_SUCCESS = "Annotation deleted"; |
38 |
|
|
39 |
|
private static final String XWIKI_SYNTAX_1_WARNING = |
40 |
|
"Annotations are not available for pages in XWiki/1.0 syntax."; |
41 |
|
|
42 |
|
private AnnotationsPane annotationsPane; |
43 |
|
|
44 |
|
private AnnotationsWindow annotationsWindow; |
45 |
|
|
46 |
|
private AnnotationsLabel annotationsLabel; |
47 |
|
|
48 |
|
private StringBuilder script; |
49 |
|
|
50 |
|
private ViewPage viewPage; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 1 |
Complexity Density: 0.03 |
|
52 |
2 |
public AnnotatableViewPage(ViewPage viewPage)... |
53 |
|
{ |
54 |
2 |
this.viewPage = viewPage; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
2 |
script = new StringBuilder(); |
62 |
2 |
script.append("function findString (str) {\n"); |
63 |
2 |
script.append(" var strFound;\n"); |
64 |
2 |
script.append(" if (window.find) {\n"); |
65 |
2 |
script.append(" if (parseInt(navigator.appVersion)<4) return;\n"); |
66 |
2 |
script.append(" // CODE FOR BROWSERS THAT SUPPORT window.find\n"); |
67 |
2 |
script.append(" strFound = self.find(str);\n"); |
68 |
2 |
script.append(" if (strFound && self.getSelection && !self.getSelection().anchorNode) {\n"); |
69 |
2 |
script.append(" strFound = self.find(str);\n"); |
70 |
2 |
script.append(" }\n"); |
71 |
2 |
script.append(" if (!strFound) {\n"); |
72 |
2 |
script.append(" strFound = self.find(str,0,1);\n"); |
73 |
2 |
script.append(" while (self.find(str,0,1)) continue;\n"); |
74 |
2 |
script.append(" }\n"); |
75 |
2 |
script.append(" } else if (navigator.appName.indexOf(\"Microsoft\")!=-1) {\n"); |
76 |
2 |
script.append(" // EXPLORER-SPECIFIC CODE\n"); |
77 |
2 |
script.append(" if (TRange != null) {\n"); |
78 |
2 |
script.append(" TRange.collapse(false);\n"); |
79 |
2 |
script.append(" strFound = TRange.findText(str);\n"); |
80 |
2 |
script.append(" if (strFound) TRange.select();\n"); |
81 |
2 |
script.append(" }\n"); |
82 |
2 |
script.append(" if (TRange == null || strFound == 0) {\n"); |
83 |
2 |
script.append(" TRange = self.document.body.createTextRange();\n"); |
84 |
2 |
script.append(" strFound = TRange.findText(str);\n"); |
85 |
2 |
script.append(" if (strFound) TRange.select();\n"); |
86 |
2 |
script.append(" }\n"); |
87 |
2 |
script.append(" } else if (navigator.appName == \"Opera\") {\n"); |
88 |
2 |
script.append(" alert ('Opera browsers not supported, sorry...');\n"); |
89 |
2 |
script.append(" return;\n"); |
90 |
2 |
script.append(" }\n"); |
91 |
2 |
script.append(" if (!strFound) \n"); |
92 |
2 |
script.append(" return;\n"); |
93 |
2 |
script.append("}\n"); |
94 |
2 |
((JavascriptExecutor) getDriver()).executeScript(script.toString()); |
95 |
|
|
96 |
2 |
annotationsPane = new AnnotationsPane(); |
97 |
2 |
annotationsWindow = new AnnotationsWindow(); |
98 |
2 |
annotationsLabel = new AnnotationsLabel(); |
99 |
|
|
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
public ViewPage getWrappedViewPage()... |
103 |
|
{ |
104 |
0 |
return this.viewPage; |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
107 |
4 |
public void addAnnotation(String annotatedText, String annotationText)... |
108 |
|
{ |
109 |
4 |
selectText(annotatedText); |
110 |
4 |
simulateCTRL_M(); |
111 |
4 |
annotationsWindow.addAnnotation(annotationText); |
112 |
|
|
113 |
4 |
waitForNotificationSuccessMessage(XWIKI_ANNOTATION_ADD_SUCCESS); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
116 |
4 |
public void deleteAnnotationByID(String id)... |
117 |
|
{ |
118 |
4 |
annotationsLabel.deleteAnnotationById(id); |
119 |
4 |
waitForNotificationSuccessMessage(XWIKI_ANNOTATION_DELETE_SUCCESS); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
4 |
public void deleteAnnotationByText(String annotatedText)... |
123 |
|
{ |
124 |
4 |
deleteAnnotationByID(this.annotationsLabel.getAnnotationIdByText(annotatedText)); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
4 |
public String getAnnotationContentByText(String searchText)... |
128 |
|
{ |
129 |
4 |
return annotationsLabel.getAnnotationContentByText(searchText); |
130 |
|
} |
131 |
|
|
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
2 |
public void showAnnotationsPane()... |
134 |
|
{ |
135 |
2 |
annotationsPane.showAnnotationsPane(); |
136 |
|
} |
137 |
|
|
138 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
0 |
public void hideAnnotationsPane()... |
140 |
|
{ |
141 |
0 |
annotationsPane.hideAnnotationsPane(); |
142 |
|
} |
143 |
|
|
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0 |
public void clickShowAnnotations()... |
146 |
|
{ |
147 |
0 |
annotationsPane.clickShowAnnotations(); |
148 |
|
} |
149 |
|
|
150 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
0 |
public void clickHideAnnotations()... |
152 |
|
{ |
153 |
0 |
annotationsPane.clickHideAnnotations(); |
154 |
|
} |
155 |
|
|
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0 |
public boolean checkIfClickbuttonExists()... |
158 |
|
{ |
159 |
0 |
return annotationsPane.checkIfShowAnnotationsCheckboxExists(); |
160 |
|
} |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
162 |
5 |
public void simulateCTRL_M()... |
163 |
|
{ |
164 |
5 |
WebElement body = getDriver().findElement(By.id("body")); |
165 |
5 |
body.sendKeys(Keys.chord(Keys.CONTROL, "m")); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
@param |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
4 |
public void selectText(String annotationWord)... |
172 |
|
{ |
173 |
4 |
((JavascriptExecutor) getDriver()).executeScript(script + "findString('" + annotationWord + "');"); |
174 |
|
} |
175 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
176 |
1 |
public boolean checkIfAnnotationsAreDisabled()... |
177 |
|
{ |
178 |
1 |
if (getDriver().findElementsWithoutWaiting(By.id("annotationsdisplay")).size() > 0) |
179 |
0 |
return false; |
180 |
|
else |
181 |
1 |
return true; |
182 |
|
} |
183 |
|
|
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
185 |
1 |
public void waitforAnnotationWarningNotification()... |
186 |
|
{ |
187 |
1 |
waitForNotificationWarningMessage(XWIKI_SYNTAX_1_WARNING); |
188 |
|
} |
189 |
|
} |