| 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; |
| 21 |
|
|
| 22 |
|
import org.apache.commons.lang3.StringUtils; |
| 23 |
|
import org.junit.Assert; |
| 24 |
|
import org.junit.Before; |
| 25 |
|
import org.junit.Rule; |
| 26 |
|
import org.junit.Test; |
| 27 |
|
import org.openqa.selenium.By; |
| 28 |
|
import org.openqa.selenium.TimeoutException; |
| 29 |
|
import org.openqa.selenium.WebDriver; |
| 30 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
| 31 |
|
import org.openqa.selenium.support.ui.WebDriverWait; |
| 32 |
|
import org.xwiki.test.po.xe.HomePage; |
| 33 |
|
import org.xwiki.test.ui.po.FormElement; |
| 34 |
|
import org.xwiki.test.ui.po.ViewPage; |
| 35 |
|
import org.xwiki.test.ui.po.editor.ObjectEditPage; |
| 36 |
|
import org.xwiki.test.ui.po.editor.WikiEditPage; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@version |
| 42 |
|
@since |
| 43 |
|
|
| |
|
| 94.1% |
Uncovered Elements: 2 (34) |
Complexity: 6 |
Complexity Density: 0.2 |
|
| 44 |
|
public class SkinxTest extends AbstractTest |
| 45 |
|
{ |
| 46 |
|
@Rule |
| 47 |
|
public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil()); |
| 48 |
|
|
| 49 |
|
private static final String SCRIPT = "window.document.title = 'script active';"; |
| 50 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 51 |
1 |
@Before... |
| 52 |
|
public void setUp() throws Exception |
| 53 |
|
{ |
| 54 |
1 |
getUtil().rest().deletePage("Test", "SkinxTest"); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| |
|
| 92.6% |
Uncovered Elements: 2 (27) |
Complexity: 3 |
Complexity Density: 0.11 |
1PASS
|
|
| 58 |
1 |
@Test... |
| 59 |
|
public void testJavascriptExtension() |
| 60 |
|
{ |
| 61 |
|
|
| 62 |
1 |
WikiEditPage wep = WikiEditPage.gotoPage("Test", "SkinxTest"); |
| 63 |
1 |
wep.setContent("this is the content"); |
| 64 |
1 |
ViewPage vp = wep.clickSaveAndView(); |
| 65 |
|
|
| 66 |
|
|
| 67 |
1 |
ObjectEditPage oep = vp.editObjects(); |
| 68 |
1 |
FormElement objectForm = oep.addObject("XWiki.JavaScriptExtension"); |
| 69 |
1 |
objectForm.setFieldValue(By.id("XWiki.JavaScriptExtension_0_code"), SCRIPT); |
| 70 |
1 |
objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("always"); |
| 71 |
1 |
oep.clickSaveAndView(); |
| 72 |
1 |
waitForScriptResult(); |
| 73 |
1 |
HomePage.gotoPage(); |
| 74 |
1 |
waitForScriptResult(); |
| 75 |
|
|
| 76 |
1 |
oep = ObjectEditPage.gotoPage("Test", "SkinxTest"); |
| 77 |
1 |
objectForm = oep.getObjectsOfClass("XWiki.JavaScriptExtension").get(0); |
| 78 |
1 |
objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("currentPage"); |
| 79 |
1 |
oep.clickSaveAndView(); |
| 80 |
1 |
waitForScriptResult(); |
| 81 |
1 |
HomePage.gotoPage(); |
| 82 |
1 |
try { |
| 83 |
1 |
waitForScriptResult(); |
| 84 |
0 |
Assert.fail("The JSX should be active only on the current page."); |
| 85 |
|
} catch (TimeoutException e) { |
| 86 |
|
} |
| 87 |
|
|
| 88 |
1 |
oep = ObjectEditPage.gotoPage("Test", "SkinxTest"); |
| 89 |
1 |
objectForm = oep.getObjectsOfClass("XWiki.JavaScriptExtension").get(0); |
| 90 |
1 |
objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("onDemand"); |
| 91 |
1 |
oep.clickSaveAndView(); |
| 92 |
1 |
try { |
| 93 |
1 |
waitForScriptResult(); |
| 94 |
0 |
Assert.fail("The JSX should be active only on demand."); |
| 95 |
|
} catch (TimeoutException e) { |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 103 |
5 |
private void waitForScriptResult()... |
| 104 |
|
{ |
| 105 |
5 |
new WebDriverWait(getDriver(), getDriver().getTimeout()).until(new ExpectedCondition<Boolean>() |
| 106 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
45 |
@Override... |
| 108 |
|
public Boolean apply(WebDriver driver) |
| 109 |
|
{ |
| 110 |
45 |
return StringUtils.equals("script active", driver.getTitle()); |
| 111 |
|
} |
| 112 |
|
}); |
| 113 |
|
} |
| 114 |
|
} |