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

File StaticListClassFieldEditPane.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
37
11
1
176
95
17
0.46
3.36
11
1.55

Classes

Class Line # Actions
StaticListClassFieldEditPane 35 37 0% 17 7
0.8793103787.9%
 

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.appwithinminutes.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.openqa.selenium.support.ui.Select;
28   
29    /**
30    * Represents the pane used to edit a 'Static List' class field.
31    *
32    * @version $Id: 0aa55287b3b9d389c2321241efdf5cad00437e3d $
33    * @since 4.2M1
34    */
 
35    public class StaticListClassFieldEditPane extends ClassFieldEditPane
36    {
37    /**
38    * The element that wraps the input used to specify the field default value.
39    */
40    private WebElement defaultValueContainer;
41   
42    /**
43    * Creates a new instance.
44    *
45    * @param fieldName the name of the date field
46    */
 
47  3 toggle public StaticListClassFieldEditPane(String fieldName)
48    {
49  3 super(fieldName);
50   
51  3 defaultValueContainer = getContainer().findElement(By.xpath(".//dl[@class = 'field-viewer']/dd"));
52    }
53   
54    /**
55    * @return the list of available display types
56    */
 
57  6 toggle public Select getDisplayTypeSelect()
58    {
59  6 return new Select(getPropertyInput("displayType"));
60    }
61   
62    /**
63    * @return the input used to specify the size
64    */
 
65  3 toggle public WebElement getSizeInput()
66    {
67  3 return getPropertyInput("size");
68    }
69   
70    /**
71    * @return the check box used to enable multiple selection
72    */
 
73  6 toggle public WebElement getMultipleSelectionCheckBox()
74    {
75  6 return getPropertyInput("multiSelect");
76    }
77   
 
78  1 toggle @Override
79    public String getDefaultValue()
80    {
81  1 String displayType = getPreviewInputType();
82  1 if ("input".equals(displayType)) {
83  0 return super.getDefaultValue();
84    } else {
85  1 for (WebElement selectedItem : getSelectedItems()) {
86    // Return the first selected value.
87  1 return selectedItem.getAttribute("value");
88    }
89    }
90  0 return null;
91    }
92   
 
93  1 toggle @Override
94    public void setDefaultValue(String defaultValue)
95    {
96  1 if ("input".equals(getPreviewInputType())) {
97  0 super.setDefaultValue(defaultValue);
98    } else {
99    // Clear current selection.
100  1 for (WebElement selectedItem : getSelectedItems()) {
101  2 selectedItem.click();
102    }
103    // Select the specified item.
104  1 getItemByValue(defaultValue).click();
105    }
106    }
107   
108    /**
109    * Do not use this method when display type is input.
110    *
111    * @return the list items selected by default
112    */
 
113  2 toggle public List<String> getDefaultSelectedValues()
114    {
115  2 List<String> selectedValues = new ArrayList<String>();
116  2 for (WebElement selectedItem : getSelectedItems()) {
117  4 selectedValues.add(selectedItem.getAttribute("value"));
118    }
119  2 return selectedValues;
120    }
121   
122    /**
123    * @return the list of selected items
124    */
 
125  4 toggle protected List<WebElement> getSelectedItems()
126    {
127  4 By xpath = By.xpath(".//*[local-name() = 'option' or @type = 'radio' or @type = 'checkbox']");
128  4 List<WebElement> selectedItems = new ArrayList<WebElement>();
129  4 for (WebElement item : getDriver().findElementsWithoutWaiting(defaultValueContainer, xpath)) {
130  13 if (item.isSelected()) {
131  7 selectedItems.add(item);
132    }
133    }
134  4 return selectedItems;
135    }
136   
137    /**
138    * Do not used this method when display type is input.
139    *
140    * @param value the value of the list item to return
141    * @return returns the list item that has the given value
142    */
 
143  6 toggle public WebElement getItemByValue(String value)
144    {
145  6 By xpath = By.xpath(".//*[@value = '" + value + "']");
146  6 try {
147  6 return getDriver().findElementWithoutWaiting(defaultValueContainer, xpath);
148    } catch (Exception e) {
149  1 return null;
150    }
151    }
152   
153    /**
154    * @return the type of HTML input used to preview the list; possible returned values are specified by
155    * {@link #getDisplayTypeSelect()}
156    */
 
157  5 toggle public String getPreviewInputType()
158    {
159  5 By xpath = By.xpath(".//*[local-name() = 'select' or (local-name() = 'input' and not(@type = 'hidden'))]");
160  5 List<WebElement> inputs = getDriver().findElementsWithoutWaiting(defaultValueContainer, xpath);
161  5 if (inputs.size() > 0) {
162  5 WebElement input = inputs.get(0);
163  5 return "select".equalsIgnoreCase(input.getTagName()) ? "select" : input.getAttribute("type").toLowerCase();
164    }
165  0 return null;
166    }
167   
168    /**
169    * @return the static list items editor
170    */
 
171  1 toggle public StaticListItemsEditor getItemsEditor()
172    {
173  1 return new StaticListItemsEditor(getDriver().findElementWithoutWaiting(getContainer(),
174    By.className("staticListEditor")));
175    }
176    }