| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.watchlist.test.po; |
| 21 |
|
|
| 22 |
|
import java.util.List; |
| 23 |
|
|
| 24 |
|
import org.openqa.selenium.By; |
| 25 |
|
import org.openqa.selenium.WebDriver; |
| 26 |
|
import org.openqa.selenium.WebElement; |
| 27 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
| 28 |
|
import org.xwiki.test.ui.po.BaseElement; |
| 29 |
|
import org.xwiki.test.ui.po.LiveTableElement; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@version |
| 35 |
|
@since |
| 36 |
|
|
| |
|
| 93.8% |
Uncovered Elements: 2 (32) |
Complexity: 9 |
Complexity Density: 0.45 |
|
| 37 |
|
public class WatchlistMacro extends BaseElement |
| 38 |
|
{ |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
private static final String WATCHLIST_REMOVE_BUTTON_PATTERN_CSS |
| 45 |
|
= "tbody#mywatchlist-0-display>tr>td>a[href$='?xpage=watch&do=%s&reference=%s']"; |
| 46 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 47 |
33 |
public LiveTableElement getWatchList() {... |
| 48 |
33 |
LiveTableElement liveTableElement = new LiveTableElement("mywatchlist-0"); |
| 49 |
33 |
liveTableElement.waitUntilReady(); |
| 50 |
|
|
| 51 |
33 |
return liveTableElement; |
| 52 |
|
} |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 54 |
20 |
public boolean isWatched(String space, String page) {... |
| 55 |
|
|
| 56 |
20 |
getWatchList(); |
| 57 |
|
|
| 58 |
20 |
return !getDriver().findElementsWithoutWaiting(removeLink(space, page)).isEmpty(); |
| 59 |
|
} |
| 60 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
5 |
public boolean isWatched(String space) {... |
| 62 |
5 |
return this.isWatched(space, null); |
| 63 |
|
} |
| 64 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
3 |
public boolean isWikiWatched() {... |
| 66 |
3 |
return this.isWatched(null, null); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
|
| |
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 70 |
|
private class ExpectNoRemoveLinks implements ExpectedCondition<Boolean> |
| 71 |
|
{ |
| 72 |
|
private final String page; |
| 73 |
|
private final String space; |
| 74 |
|
private List<WebElement> links = null; |
| 75 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 76 |
8 |
ExpectNoRemoveLinks(String space, String page) {... |
| 77 |
8 |
this.space = space; |
| 78 |
8 |
this.page = page; |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 81 |
13 |
@Override... |
| 82 |
|
public Boolean apply(WebDriver input) { |
| 83 |
13 |
getWatchList(); |
| 84 |
13 |
links = getDriver().findElements(removeLink(space, page)); |
| 85 |
13 |
return links.isEmpty(); |
| 86 |
|
} |
| 87 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 88 |
4 |
public List<WebElement> getLinks() {... |
| 89 |
4 |
if (links == null) { |
| 90 |
4 |
apply(getDriver()); |
| 91 |
|
} |
| 92 |
4 |
return links; |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
@param |
| 100 |
|
|
| 101 |
|
@param |
| 102 |
|
|
| 103 |
|
@return |
| 104 |
|
|
| |
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 105 |
4 |
public boolean unWatch(String space, String page) {... |
| 106 |
4 |
List<WebElement> links = new ExpectNoRemoveLinks(space, page).getLinks(); |
| 107 |
4 |
if (links.isEmpty()) { |
| 108 |
0 |
return false; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
4 |
links.get(0).click(); |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
4 |
getDriver().waitUntilCondition(new ExpectNoRemoveLinks(space, page)); |
| 117 |
|
|
| 118 |
4 |
return true; |
| 119 |
|
} |
| 120 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 121 |
33 |
private By removeLink(String space, String page) {... |
| 122 |
33 |
By removeLink; |
| 123 |
33 |
if (space == null) { |
| 124 |
6 |
removeLink = By.cssSelector(String.format(WATCHLIST_REMOVE_BUTTON_PATTERN_CSS, "removewiki", "xwiki")); |
| 125 |
27 |
} else if (page == null) { |
| 126 |
8 |
removeLink = By.cssSelector(String.format(WATCHLIST_REMOVE_BUTTON_PATTERN_CSS, "removespace", "xwiki%3A" + space)); |
| 127 |
|
} else { |
| 128 |
19 |
removeLink = By.cssSelector(String.format(WATCHLIST_REMOVE_BUTTON_PATTERN_CSS, "removedocument", "xwiki%3A" + space + '.' + page)); |
| 129 |
|
} |
| 130 |
33 |
return removeLink; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
} |