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

File StaticListItemsEditor.java

 

Coverage histogram

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

Code metrics

0
22
9
1
158
63
9
0.41
2.44
9
1

Classes

Class Line # Actions
StaticListItemsEditor 34 22 0% 9 4
0.8709677587.1%
 

Contributing tests

This file is covered by 1 test. .

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 org.openqa.selenium.By;
23    import org.openqa.selenium.Keys;
24    import org.openqa.selenium.WebElement;
25    import org.openqa.selenium.interactions.Actions;
26    import org.xwiki.test.ui.po.BaseElement;
27   
28    /**
29    * Represents the static list items editor present on the configuration pane of a static list field.
30    *
31    * @version $Id: 4bef85b9e7364c4c4b6a5b6f74b61bfe4baa50b7 $
32    * @since 4.2M1
33    */
 
34    public class StaticListItemsEditor extends BaseElement
35    {
36    /**
37    * The element that wraps the editor.
38    */
39    private WebElement container;
40   
41    /**
42    * The text input used to specify the item value.
43    */
44    private WebElement valueInput;
45   
46    /**
47    * The text input used to specify the item label.
48    */
49    private WebElement labelInput;
50   
51    /**
52    * The button used to add a new list item.
53    */
54    private WebElement addButton;
55   
56    /**
57    * Creates a new instance.
58    *
59    * @param container the element that wraps the editor
60    */
 
61  1 toggle public StaticListItemsEditor(WebElement container)
62    {
63  1 this.container = container;
64   
65  1 By xpath = By.xpath(".//*[@class = 'xHint' and . = 'ID']/following-sibling::input[@type = 'text']");
66  1 valueInput = getDriver().findElementWithoutWaiting(container, xpath);
67   
68  1 xpath = By.xpath(".//*[@class = 'xHint' and . = 'Value']/following-sibling::input[@type = 'text']");
69  1 labelInput = getDriver().findElementWithoutWaiting(container, xpath);
70   
71  1 addButton = getDriver().findElementWithoutWaiting(container, By.className("add"));
72    }
73   
74    /**
75    * Removes the item with the specified value.
76    *
77    * @param value the value of the item to be removed
78    */
 
79  1 toggle public void remove(String value)
80    {
81  1 By xpath = By.xpath("ul/li/*[@title = '" + value + "']/following-sibling::*[@class = 'delete']");
82  1 getDriver().findElementWithoutWaiting(container, xpath).click();
83    }
84   
85    /**
86    * Adds a new item with the specified value and label.
87    *
88    * @param value item value
89    * @param label item label
90    */
 
91  2 toggle public void add(String value, String label)
92    {
93  2 valueInput.clear();
94  2 valueInput.sendKeys(value);
95  2 labelInput.clear();
96  2 labelInput.sendKeys(label);
97  2 addButton.click();
98    }
99   
100    /**
101    * @return the text input used to specify the item value
102    */
 
103  0 toggle public WebElement getValueInput()
104    {
105  0 return valueInput;
106    }
107   
108    /**
109    * @return the text input used to specify the item label
110    */
 
111  0 toggle public WebElement getLabelInput()
112    {
113  0 return labelInput;
114    }
115   
116    /**
117    * Changes item label.
118    *
119    * @param value item value
120    * @param newLabel the new item label
121    */
 
122  1 toggle public void setLabel(String value, String newLabel)
123    {
124  1 getItem(value).click();
125  1 labelInput.clear();
126  1 labelInput.sendKeys(newLabel + Keys.RETURN);
127    }
128   
129    /**
130    * Reorders list items.
131    *
132    * @param valueToMove the value of the item to be moved
133    * @param beforeValue the value of the reference item
134    */
 
135  1 toggle public void moveBefore(String valueToMove, String beforeValue)
136    {
137  1 new Actions(getDriver()).clickAndHold(getItem(valueToMove))
138    .moveToElement(getItem(beforeValue), 0, 0).release().perform();
139    }
140   
141    /**
142    * @param valueOrLabel the value of the label of a list item
143    * @return the first list item that has the specified value or label
144    */
 
145  3 toggle public WebElement getItem(String valueOrLabel)
146    {
147  3 By xpath = By.xpath("ul/li/*[@title = '" + valueOrLabel + "' or . = '" + valueOrLabel + "']");
148  3 return getDriver().findElementWithoutWaiting(container, xpath);
149    }
150   
151    /**
152    * @return the number of list items
153    */
 
154  1 toggle public int size()
155    {
156  1 return getDriver().findElementsWithoutWaiting(container, By.tagName("li")).size();
157    }
158    }