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

File ApplicationHomeEditPage.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
33
15
1
218
103
16
0.48
2.2
15
1.07

Classes

Class Line # Actions
ApplicationHomeEditPage 41 33 0% 16 3
0.9494%
 

Contributing tests

This file is covered by 12 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.List;
23   
24    import org.openqa.selenium.By;
25    import org.openqa.selenium.Keys;
26    import org.openqa.selenium.WebElement;
27    import org.openqa.selenium.interactions.Actions;
28    import org.openqa.selenium.support.FindBy;
29    import org.openqa.selenium.support.ui.Select;
30    import org.xwiki.test.ui.po.ViewPage;
31    import org.xwiki.test.ui.po.editor.wysiwyg.EditorElement;
32    import org.xwiki.test.ui.po.editor.wysiwyg.RichTextAreaElement;
33   
34    /**
35    * Represents the actions available when editing the application home page. This is also the forth step of the App
36    * Within Minutes wizard, in which the presentation of the application home page is customized.
37    *
38    * @version $Id: 4fe15b8ba14914873f4de959af31e729a35c2fa8 $
39    * @since 4.2M1
40    */
 
41    public class ApplicationHomeEditPage extends ApplicationEditPage
42    {
43    @FindBy(id = "availableColumns")
44    private WebElement availableColumns;
45   
46    @FindBy(xpath = "//div[@class = 'columnPicker']/input[@type = 'image' and @alt = 'Add']")
47    private WebElement addColumnButton;
48   
49    @FindBy(id = "applicationIcon")
50    private WebElement applicationIconInput;
51   
52    /**
53    * The WYSIWYG editor used to input the application description.
54    */
55    private final EditorElement descriptionEditor = new EditorElement("AppWithinMinutes.LiveTableClass_0_description");
56   
57    /**
58    * Clicks on the Previous Step button.
59    *
60    * @return the page that represents the previous step of the App Within Minutes wizard
61    */
 
62  0 toggle public ApplicationTemplateProviderEditPage clickPreviousStep()
63    {
64  0 previousStepButton.click();
65  0 return new ApplicationTemplateProviderEditPage();
66    }
67   
68    /**
69    * Clicks on the Finish button.
70    *
71    * @return the page that represents the application home page
72    */
 
73  9 toggle public ApplicationHomePage clickFinish()
74    {
75  9 nextStepButton.click();
76  9 return new ApplicationHomePage();
77    }
78   
 
79  7 toggle @SuppressWarnings("unchecked")
80    @Override
81    protected <T extends ViewPage> T createViewPage()
82    {
83  7 return (T) new ApplicationHomePage();
84    }
85   
86    /**
87    * Sets the application description.
88    *
89    * @param description the new application description
90    */
 
91  5 toggle public void setDescription(String description)
92    {
93  5 descriptionEditor.waitToLoad();
94  5 RichTextAreaElement descriptionTextArea = descriptionEditor.getRichTextArea();
95  5 descriptionTextArea.clear();
96  5 descriptionTextArea.sendKeys(description);
97    }
98   
99    /**
100    * Sets the application icon.
101    *
102    * @param icon the icon to set
103    */
 
104  1 toggle public void setIcon(String icon)
105    {
106  1 applicationIconInput.clear();
107  1 applicationIconInput.sendKeys(icon);
108    // Send 'escape' to close the icon picker after having filled the input.
109  1 applicationIconInput.sendKeys(Keys.ESCAPE);
110    }
111   
112    /**
113    * @return the application icon
114    */
 
115  1 toggle public String getIcon()
116    {
117  1 return applicationIconInput.getAttribute("value");
118    }
119   
120    /**
121    * Adds a new live table column.
122    *
123    * @param columnLabel the label of the live table column to be added
124    */
 
125  6 toggle public void addLiveTableColumn(String columnLabel)
126    {
127  6 Select select = new Select(availableColumns);
128  6 select.selectByVisibleText(columnLabel);
129  6 addColumnButton.click();
130    }
131   
132    /**
133    * Removes the live table column with the specified label.
134    *
135    * @param columnLabel the label of the live table column to be removed
136    */
 
137  3 toggle public void removeLiveTableColumn(String columnLabel)
138    {
139  3 WebElement column = getLiveTableColumn(columnLabel);
140    // FIXME: This doesn't trigger the :hover CSS pseudo class. The click still works because the delete X (text) is
141    // not really hidden: it is displayed with white color (the page background-color).
142  3 new Actions(getDriver()).moveToElement(column).perform();
143  3 column.findElement(By.className("delete")).click();
144    }
145   
146    /**
147    * Reorders the live table columns by moving one column before another.
148    *
149    * @param columnToMove the label of the live table column to be moved
150    * @param beforeColumn the label of the reference column
151    */
 
152  2 toggle public void moveLiveTableColumnBefore(String columnToMove, String beforeColumn)
153    {
154  2 new Actions(getDriver()).clickAndHold(getLiveTableColumn(columnToMove))
155    .moveToElement(getLiveTableColumn(beforeColumn), 0, 0).release().perform();
156    }
157   
158    /**
159    * @param columnLabel the label of a live table column
160    * @return the element that represents the specified live table column
161    */
 
162  10 toggle private WebElement getLiveTableColumn(String columnLabel)
163    {
164  10 String escapedColumnLabel = columnLabel.replace("\\", "\\\\").replace("'", "\\'");
165  10 String xpath = "//ul[@class = 'hList']/li[starts-with(., '" + escapedColumnLabel + "')]";
166  10 return getDriver().findElementWithoutWaiting(getForm(), By.xpath(xpath));
167    }
168   
169    /**
170    * @param columnLabel the label of the live table column to check for
171    * @return {@code true} if the specified column was selected (i.e. included in the live table), {@code false}
172    * otherwise
173    */
 
174  5 toggle public boolean hasLiveTableColumn(String columnLabel)
175    {
176  5 String escapedColumnLabel = columnLabel.replace("\\", "\\\\").replace("'", "\\'");
177  5 String xpath = "//ul[@class = 'hList']/li[starts-with(., '" + escapedColumnLabel + "')]";
178  5 return getDriver().findElementsWithoutWaiting(getForm(), By.xpath(xpath)).size() > 0;
179    }
180   
181    /**
182    * @param columnLabel the label of a live table column
183    * @return {@code true} if the specified column is displayed as deprecated in the list of selected live table
184    * columns, {@code false} otherwise
185    */
 
186  3 toggle public boolean isLiveTableColumnDeprecated(String columnLabel)
187    {
188  3 return "deprecated".equals(getLiveTableColumn(columnLabel).getAttribute("class"));
189    }
190   
191    /**
192    * Removes all deprecated columns or simply hides the warning message based on the given boolean value.
193    *
194    * @param yes {@code true} to remove all deprecated columns, {@code false} to just hide the warning message
195    */
 
196  2 toggle public void removeAllDeprecatedLiveTableColumns(boolean yes)
197    {
198  2 WebElement warningMessage = getDriver().findElementWithoutWaiting(getForm(), By.className("warningmessage"));
199  2 getDriver().findElementWithoutWaiting(warningMessage, By.linkText(yes ? "Yes" : "No")).click();
200    }
201   
202    /**
203    * @return {@code true} if the warning message about deprecated live table columns is displayed, {@code false}
204    * otherwise
205    */
 
206  5 toggle public boolean isDeprecatedLiveTableColumnsWarningDisplayed()
207    {
208  5 List<WebElement> warnings = getDriver().findElementsWithoutWaiting(getForm(), By.className("warningmessage"));
209  5 return warnings.size() == 1 && warnings.get(0).isDisplayed();
210    }
211   
 
212  16 toggle @Override
213    public ApplicationHomeEditPage waitUntilPageIsLoaded()
214    {
215  16 descriptionEditor.waitToLoad();
216  16 return this;
217    }
218    }