1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.administration.test.po

File LocationPicker.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
28
10
1
119
80
11
0.39
2.8
10
1.1

Classes

Class Line # Actions
LocationPicker 39 28 0% 11 8
0.880%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.administration.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.WebElement;
27    import org.xwiki.index.tree.test.po.DocumentPickerModal;
28    import org.xwiki.model.EntityType;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.test.ui.po.BaseElement;
31   
32    /**
33    * Represents the location picker.
34    *
35    * @version $Id: bbf1285e1c3cdceb3394f9c882b48085ac4edc03 $
36    * @since 8.4.3
37    * @since 9.0RC1
38    */
 
39    public class LocationPicker extends BaseElement
40    {
41    private String name;
42   
 
43  8 toggle public LocationPicker(String name)
44    {
45  8 this.name = name;
46    }
47   
 
48  2 toggle public LocationPicker add(String value)
49    {
50  2 EntityReference spaceReference = getUtil().resolveSpaceReference(value);
51  2 EntityReference wikiReference = spaceReference.extractReference(EntityType.WIKI);
52  2 if (wikiReference != null) {
53  2 spaceReference = spaceReference.removeParent(wikiReference);
54    }
55  2 EntityReference documentReference = new EntityReference("WebHome", EntityType.DOCUMENT, spaceReference);
56  2 String[] path =
57    documentReference.getReversedReferenceChain().stream().map(EntityReference::getName).toArray(String[]::new);
58  2 browse().selectDocument(path);
59  2 return waitToDisplayValue(value);
60    }
61   
 
62  0 toggle public LocationPicker remove(String value)
63    {
64  0 getRemoveButton(value).click();
65  0 return this;
66    }
67   
 
68  2 toggle public List<String> getValue()
69    {
70  2 List<String> values = new ArrayList<>();
71  2 for (WebElement path : getDriver()
72    .findElementsWithoutWaiting(By.cssSelector(".path input[name='" + this.name + "'][value]"))) {
73  0 values.add(path.getText());
74    }
75  2 return values;
76    }
77   
 
78  2 toggle public LocationPicker setValue(List<String> values)
79    {
80  2 clear();
81  2 for (String value : values) {
82  2 add(value);
83    }
84  2 return this;
85    }
86   
 
87  2 toggle public LocationPicker clear()
88    {
89  2 for (String value : getValue()) {
90  0 remove(value);
91    }
92  2 return this;
93    }
94   
 
95  2 toggle public DocumentPickerModal browse()
96    {
97  2 getAddButton().click();
98  2 return new DocumentPickerModal(By.cssSelector(".location-picker.modal")).waitForIt();
99    }
100   
 
101  2 toggle public WebElement getAddButton()
102    {
103  2 return getDriver()
104    .findElementWithoutWaiting(By.cssSelector(".paths input[name='" + this.name + "'] + a[href='#path-add']"));
105    }
106   
 
107  0 toggle public WebElement getRemoveButton(String value)
108    {
109  0 return getDriver().findElementWithoutWaiting(By.xpath("//*[@class = 'paths']//input[@name = '" + this.name
110    + "' and @value = '" + value + "']/preceding-sibling::a[@class = 'path-delete']"));
111    }
112   
 
113  2 toggle private LocationPicker waitToDisplayValue(String value)
114    {
115  2 getDriver().waitUntilElementIsVisible(By.xpath("//*[@class='path']/input[@name='" + this.name + "' and @value='"
116    + value + "']/following-sibling::*[@class='breadcrumb']/li[not(@class='loading')]"));
117  2 return this;
118    }
119    }