| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.test.wysiwyg; |
| 21 |
|
|
| 22 |
|
import org.junit.Test; |
| 23 |
|
import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase; |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
@version |
| 29 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (187) |
Complexity: 15 |
Complexity Density: 0.09 |
|
| 30 |
|
public class AlignmentTest extends AbstractWysiwygTestCase |
| 31 |
|
{ |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
public static final String TOOLBAR_BUTTON_ALIGN_LEFT_TITLE = "Align Left"; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
public static final String TOOLBAR_BUTTON_ALIGN_CENTER_TITLE = "Centered"; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
public static final String TOOLBAR_BUTTON_ALIGN_RIGHT_TITLE = "Align Right"; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
public static final String TOOLBAR_BUTTON_ALIGN_FULL_TITLE = "Justified"; |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 55 |
1 |
@Test... |
| 56 |
|
public void testAlignBody() |
| 57 |
|
{ |
| 58 |
1 |
clickAlignCenterButton(); |
| 59 |
1 |
typeText("a"); |
| 60 |
1 |
switchToSource(); |
| 61 |
1 |
assertSourceText("(% style=\"text-align: center;\" %)\na"); |
| 62 |
|
|
| 63 |
1 |
setSourceText(""); |
| 64 |
1 |
switchToWysiwyg(); |
| 65 |
|
|
| 66 |
1 |
typeText("a"); |
| 67 |
|
|
| 68 |
1 |
waitForToggleButton(TOOLBAR_BUTTON_ALIGN_RIGHT_TITLE, true); |
| 69 |
1 |
clickAlignRightButton(); |
| 70 |
1 |
typeText("b"); |
| 71 |
1 |
switchToSource(); |
| 72 |
1 |
assertSourceText("(% style=\"text-align: right;\" %)\nab"); |
| 73 |
|
|
| 74 |
1 |
setSourceText(""); |
| 75 |
1 |
switchToWysiwyg(); |
| 76 |
|
|
| 77 |
1 |
typeText("abc"); |
| 78 |
1 |
select("document.body.firstChild", 1, "document.body.firstChild", 2); |
| 79 |
|
|
| 80 |
1 |
waitForToggleButton(TOOLBAR_BUTTON_ALIGN_FULL_TITLE, true); |
| 81 |
1 |
clickAlignFullButton(); |
| 82 |
1 |
typeText("x"); |
| 83 |
1 |
switchToSource(); |
| 84 |
1 |
assertSourceText("(% style=\"text-align: justify;\" %)\naxc"); |
| 85 |
|
|
| 86 |
1 |
setSourceText(""); |
| 87 |
1 |
switchToWysiwyg(); |
| 88 |
|
|
| 89 |
1 |
typeText("a"); |
| 90 |
1 |
typeShiftEnter(); |
| 91 |
1 |
typeText("b"); |
| 92 |
1 |
selectNode("document.body.childNodes[2]"); |
| 93 |
|
|
| 94 |
1 |
waitForToggleButton(TOOLBAR_BUTTON_ALIGN_LEFT_TITLE, true); |
| 95 |
1 |
clickAlignLeftButton(); |
| 96 |
1 |
typeText("x"); |
| 97 |
1 |
switchToSource(); |
| 98 |
1 |
assertSourceText("(% style=\"text-align: left;\" %)\na\nx"); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 104 |
1 |
@Test... |
| 105 |
|
public void testAlignParagraph() |
| 106 |
|
{ |
| 107 |
|
|
| 108 |
1 |
applyStyleTitle1(); |
| 109 |
1 |
applyStylePlainText(); |
| 110 |
|
|
| 111 |
|
|
| 112 |
1 |
waitForPushButton(TOOLBAR_BUTTON_UNDO_TITLE, true); |
| 113 |
|
|
| 114 |
1 |
boolean defaultAlignFull = isToggleButtonDown(TOOLBAR_BUTTON_ALIGN_FULL_TITLE); |
| 115 |
|
|
| 116 |
|
|
| 117 |
1 |
clickAlignCenterButton(); |
| 118 |
1 |
typeText("a"); |
| 119 |
1 |
waitForAlignCenterDetected(true); |
| 120 |
1 |
switchToSource(); |
| 121 |
1 |
assertSourceText("(% style=\"text-align: center;\" %)\na"); |
| 122 |
|
|
| 123 |
|
|
| 124 |
1 |
switchToWysiwyg(); |
| 125 |
1 |
waitForAlignCenterDetected(true); |
| 126 |
|
|
| 127 |
1 |
typeShiftEnter(); |
| 128 |
1 |
typeText("b"); |
| 129 |
1 |
clickAlignRightButton(); |
| 130 |
1 |
waitForAlignRightDetected(true); |
| 131 |
1 |
switchToSource(); |
| 132 |
1 |
assertSourceText("(% style=\"text-align: right;\" %)\na\nb"); |
| 133 |
|
|
| 134 |
|
|
| 135 |
1 |
switchToWysiwyg(); |
| 136 |
1 |
waitForAlignRightDetected(true); |
| 137 |
|
|
| 138 |
1 |
selectNode("document.body.firstChild.childNodes[2]"); |
| 139 |
1 |
clickAlignFullButton(); |
| 140 |
1 |
typeText("c"); |
| 141 |
1 |
waitForAlignFullDetected(true); |
| 142 |
1 |
switchToSource(); |
| 143 |
1 |
assertSourceText("(% style=\"text-align: justify;\" %)\na\nc"); |
| 144 |
|
|
| 145 |
|
|
| 146 |
1 |
switchToWysiwyg(); |
| 147 |
1 |
waitForAlignFullDetected(true); |
| 148 |
|
|
| 149 |
|
|
| 150 |
1 |
clickAlignFullButton(); |
| 151 |
|
|
| 152 |
1 |
waitForAlignFullDetected(defaultAlignFull); |
| 153 |
1 |
switchToSource(); |
| 154 |
1 |
assertSourceText("a\nc"); |
| 155 |
1 |
switchToWysiwyg(); |
| 156 |
|
|
| 157 |
1 |
typeText("x"); |
| 158 |
1 |
clickAlignLeftButton(); |
| 159 |
1 |
waitForAlignLeftDetected(true); |
| 160 |
1 |
switchToSource(); |
| 161 |
1 |
assertSourceText("(% style=\"text-align: left;\" %)\na\ncx"); |
| 162 |
|
|
| 163 |
|
|
| 164 |
1 |
switchToWysiwyg(); |
| 165 |
1 |
waitForAlignLeftDetected(true); |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
| 171 |
1 |
@Test... |
| 172 |
|
public void testAlignTableCell() |
| 173 |
|
{ |
| 174 |
1 |
switchToSource(); |
| 175 |
1 |
setSourceText("|=a|=b\n|c|d"); |
| 176 |
1 |
switchToWysiwyg(); |
| 177 |
1 |
clickAlignRightButton(); |
| 178 |
1 |
waitForAlignRightDetected(true); |
| 179 |
1 |
switchToSource(); |
| 180 |
1 |
assertSourceText("|=(% style=\"text-align: right;\" %)a|=b\n|c|d"); |
| 181 |
|
|
| 182 |
|
|
| 183 |
1 |
switchToWysiwyg(); |
| 184 |
1 |
waitForAlignRightDetected(true); |
| 185 |
|
|
| 186 |
1 |
typeTextThenEnter("x"); |
| 187 |
1 |
clickAlignFullButton(); |
| 188 |
1 |
waitForAlignFullDetected(true); |
| 189 |
1 |
switchToSource(); |
| 190 |
1 |
assertSourceText("|=(% style=\"text-align: justify;\" %)x\na|=b\n|c|d"); |
| 191 |
1 |
switchToWysiwyg(); |
| 192 |
|
|
| 193 |
1 |
selectNodeContents("document.body.getElementsByTagName('td')[0]"); |
| 194 |
1 |
clickAlignCenterButton(); |
| 195 |
1 |
waitForAlignCenterDetected(true); |
| 196 |
1 |
switchToSource(); |
| 197 |
1 |
assertSourceText("|=(% style=\"text-align: justify;\" %)x\na|=b\n|(% style=\"text-align: center;\" %)c|d"); |
| 198 |
1 |
switchToWysiwyg(); |
| 199 |
|
|
| 200 |
1 |
selectNodeContents("document.body.getElementsByTagName('td')[0]"); |
| 201 |
1 |
waitForAlignCenterDetected(true); |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 207 |
1 |
@Test... |
| 208 |
|
public void testAlignParagraphs() |
| 209 |
|
{ |
| 210 |
1 |
switchToSource(); |
| 211 |
1 |
setSourceText("ab\n\ncd"); |
| 212 |
1 |
switchToWysiwyg(); |
| 213 |
|
|
| 214 |
1 |
moveCaret("document.body.getElementsByTagName('p')[0].firstChild", 1); |
| 215 |
1 |
clickAlignCenterButton(); |
| 216 |
1 |
waitForAlignCenterDetected(true); |
| 217 |
|
|
| 218 |
1 |
select("document.body.getElementsByTagName('p')[0].firstChild", 1, |
| 219 |
|
"document.body.getElementsByTagName('p')[1].firstChild", 1); |
| 220 |
1 |
waitForAlignCenterDetected(false); |
| 221 |
1 |
clickAlignRightButton(); |
| 222 |
1 |
waitForAlignRightDetected(true); |
| 223 |
1 |
switchToSource(); |
| 224 |
1 |
assertSourceText("(% style=\"text-align: right;\" %)\nab\n\n(% style=\"text-align: right;\" %)\ncd"); |
| 225 |
|
|
| 226 |
|
|
| 227 |
1 |
switchToWysiwyg(); |
| 228 |
1 |
waitForAlignRightDetected(true); |
| 229 |
|
|
| 230 |
|
|
| 231 |
1 |
select("document.body.getElementsByTagName('p')[0].firstChild", 1, |
| 232 |
|
"document.body.getElementsByTagName('p')[1].firstChild", 1); |
| 233 |
1 |
clickAlignRightButton(); |
| 234 |
1 |
waitForAlignRightDetected(false); |
| 235 |
1 |
switchToSource(); |
| 236 |
1 |
assertSourceText("ab\n\ncd"); |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 242 |
1 |
@Test... |
| 243 |
|
public void testAlignTableCells() |
| 244 |
|
{ |
| 245 |
1 |
switchToSource(); |
| 246 |
1 |
setSourceText("|ab|cd"); |
| 247 |
1 |
switchToWysiwyg(); |
| 248 |
|
|
| 249 |
1 |
moveCaret("document.body.getElementsByTagName('td')[1].firstChild", 2); |
| 250 |
1 |
clickAlignRightButton(); |
| 251 |
1 |
waitForAlignRightDetected(true); |
| 252 |
|
|
| 253 |
1 |
select("document.body.getElementsByTagName('td')[0].firstChild", 0, |
| 254 |
|
"document.body.getElementsByTagName('td')[1].firstChild", 1); |
| 255 |
1 |
waitForAlignRightDetected(false); |
| 256 |
1 |
clickAlignCenterButton(); |
| 257 |
1 |
waitForAlignCenterDetected(true); |
| 258 |
1 |
switchToSource(); |
| 259 |
1 |
assertSourceText("|(% style=\"text-align: center;\" %)ab|(% style=\"text-align: center;\" %)cd"); |
| 260 |
|
|
| 261 |
|
|
| 262 |
1 |
switchToWysiwyg(); |
| 263 |
1 |
waitForAlignCenterDetected(true); |
| 264 |
|
|
| 265 |
|
|
| 266 |
1 |
select("document.body.getElementsByTagName('td')[0].firstChild", 1, |
| 267 |
|
"document.body.getElementsByTagName('td')[1].firstChild", 2); |
| 268 |
1 |
clickAlignCenterButton(); |
| 269 |
1 |
waitForAlignCenterDetected(false); |
| 270 |
1 |
switchToSource(); |
| 271 |
1 |
assertSourceText("|ab|cd"); |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
| 277 |
1 |
@Test... |
| 278 |
|
public void testSelectAndAlignParagraphAndTableCell() |
| 279 |
|
{ |
| 280 |
1 |
switchToSource(); |
| 281 |
1 |
setSourceText("ab\nxy\n\n|cd\n12|ef"); |
| 282 |
1 |
switchToWysiwyg(); |
| 283 |
|
|
| 284 |
|
|
| 285 |
1 |
clickAlignRightButton(); |
| 286 |
1 |
waitForAlignRightDetected(true); |
| 287 |
|
|
| 288 |
|
|
| 289 |
1 |
select("document.body.getElementsByTagName('p')[0].lastChild", 2, |
| 290 |
|
"document.body.getElementsByTagName('td')[0].firstChild", 0); |
| 291 |
1 |
waitForAlignRightDetected(false); |
| 292 |
1 |
clickAlignFullButton(); |
| 293 |
1 |
waitForAlignFullDetected(true); |
| 294 |
1 |
switchToSource(); |
| 295 |
1 |
assertSourceText("(% style=\"text-align: justify;\" %)\nab\nxy\n\n|(% style=\"text-align: justify;\" %)cd\n12|ef"); |
| 296 |
|
|
| 297 |
|
|
| 298 |
1 |
switchToWysiwyg(); |
| 299 |
1 |
waitForAlignFullDetected(true); |
| 300 |
|
|
| 301 |
|
|
| 302 |
1 |
select("document.body.getElementsByTagName('p')[0].firstChild", 1, |
| 303 |
|
"document.body.getElementsByTagName('td')[0].lastChild", 0); |
| 304 |
1 |
clickAlignFullButton(); |
| 305 |
1 |
waitForAlignFullDetected(false); |
| 306 |
1 |
switchToSource(); |
| 307 |
1 |
assertSourceText("ab\nxy\n\n|cd\n12|ef"); |
| 308 |
|
} |
| 309 |
|
|
| 310 |
|
|
| 311 |
|
|
| 312 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 313 |
1 |
@Test... |
| 314 |
|
public void testAlignParagraphInsideTableCell() |
| 315 |
|
{ |
| 316 |
1 |
switchToSource(); |
| 317 |
1 |
setSourceText("|(((ab\n\ncd)))|ef"); |
| 318 |
1 |
switchToWysiwyg(); |
| 319 |
|
|
| 320 |
|
|
| 321 |
1 |
moveCaret("document.body.getElementsByTagName('p')[0].firstChild", 2); |
| 322 |
1 |
clickAlignRightButton(); |
| 323 |
1 |
waitForAlignRightDetected(true); |
| 324 |
1 |
switchToSource(); |
| 325 |
1 |
assertSourceText("|(((\n(% style=\"text-align: right;\" %)\nab\n\ncd\n)))|ef"); |
| 326 |
|
|
| 327 |
|
|
| 328 |
1 |
switchToWysiwyg(); |
| 329 |
1 |
waitForAlignRightDetected(true); |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
|
| 333 |
|
|
| 334 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 335 |
2 |
protected void clickAlignLeftButton()... |
| 336 |
|
{ |
| 337 |
2 |
pushToolBarButton(TOOLBAR_BUTTON_ALIGN_LEFT_TITLE); |
| 338 |
|
} |
| 339 |
|
|
| 340 |
|
|
| 341 |
|
|
| 342 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 343 |
6 |
protected void clickAlignCenterButton()... |
| 344 |
|
{ |
| 345 |
6 |
pushToolBarButton(TOOLBAR_BUTTON_ALIGN_CENTER_TITLE); |
| 346 |
|
} |
| 347 |
|
|
| 348 |
|
|
| 349 |
|
|
| 350 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 351 |
8 |
protected void clickAlignRightButton()... |
| 352 |
|
{ |
| 353 |
8 |
pushToolBarButton(TOOLBAR_BUTTON_ALIGN_RIGHT_TITLE); |
| 354 |
|
} |
| 355 |
|
|
| 356 |
|
|
| 357 |
|
|
| 358 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 359 |
6 |
protected void clickAlignFullButton()... |
| 360 |
|
{ |
| 361 |
6 |
pushToolBarButton(TOOLBAR_BUTTON_ALIGN_FULL_TITLE); |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
|
| 365 |
|
|
| 366 |
|
|
| 367 |
|
@param |
| 368 |
|
|
| 369 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 370 |
2 |
protected void waitForAlignLeftDetected(boolean detected)... |
| 371 |
|
{ |
| 372 |
2 |
triggerToolbarUpdate(); |
| 373 |
2 |
waitForToggleButtonState(TOOLBAR_BUTTON_ALIGN_LEFT_TITLE, detected); |
| 374 |
|
} |
| 375 |
|
|
| 376 |
|
|
| 377 |
|
|
| 378 |
|
|
| 379 |
|
@param |
| 380 |
|
|
| 381 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 382 |
9 |
protected void waitForAlignCenterDetected(boolean detected)... |
| 383 |
|
{ |
| 384 |
9 |
triggerToolbarUpdate(); |
| 385 |
9 |
waitForToggleButtonState(TOOLBAR_BUTTON_ALIGN_CENTER_TITLE, detected); |
| 386 |
|
} |
| 387 |
|
|
| 388 |
|
|
| 389 |
|
|
| 390 |
|
|
| 391 |
|
@param |
| 392 |
|
|
| 393 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 394 |
13 |
protected void waitForAlignRightDetected(boolean detected)... |
| 395 |
|
{ |
| 396 |
13 |
triggerToolbarUpdate(); |
| 397 |
13 |
waitForToggleButtonState(TOOLBAR_BUTTON_ALIGN_RIGHT_TITLE, detected); |
| 398 |
|
} |
| 399 |
|
|
| 400 |
|
|
| 401 |
|
|
| 402 |
|
|
| 403 |
|
@param |
| 404 |
|
|
| 405 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 406 |
7 |
protected void waitForAlignFullDetected(boolean detected)... |
| 407 |
|
{ |
| 408 |
7 |
triggerToolbarUpdate(); |
| 409 |
7 |
waitForToggleButtonState(TOOLBAR_BUTTON_ALIGN_FULL_TITLE, detected); |
| 410 |
|
} |
| 411 |
|
} |