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

File ApplicationsPanelAdministrationPage.java

 

Coverage histogram

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

Code metrics

2
39
12
1
170
109
13
0.33
3.25
12
1.08

Classes

Class Line # Actions
ApplicationsPanelAdministrationPage 45 39 0% 13 0
1.0100%
 

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.panels.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.Point;
27    import org.openqa.selenium.WebDriver;
28    import org.openqa.selenium.WebElement;
29    import org.openqa.selenium.interactions.Actions;
30    import org.openqa.selenium.support.FindBy;
31    import org.openqa.selenium.support.ui.ExpectedCondition;
32    import org.xwiki.administration.test.po.AdministrationPage;
33    import org.xwiki.test.ui.po.ViewPage;
34   
35    import static org.junit.Assert.assertTrue;
36   
37    /**
38    * Represents the applications panel administration page (PanelsCode.ApplicationsPanelConfiguration).
39    *
40    * @version $Id: 74e21d00b10d83bd30afe52e74bfb63877b3f1da $
41    * @since 7.1M1
42    * @since 7.0.1
43    * @since 6.4.4
44    */
 
45    public class ApplicationsPanelAdministrationPage extends ViewPage
46    {
47    @FindBy(id = "displayedPanels")
48    private WebElement displayedPanels;
49   
50    @FindBy(id = "blacklistedPanels")
51    private WebElement blacklistedPanels;
52   
53    @FindBy(id = "bt-revert")
54    private WebElement revertButton;
55   
56    @FindBy(id = "bt-save")
57    private WebElement saveButton;
58   
 
59  3 toggle public static ApplicationsPanelAdministrationPage gotoPage()
60    {
61  3 AdministrationPage administrationPage = AdministrationPage.gotoPage();
62  3 assertTrue(administrationPage.hasSection("panels.applications"));
63  3 administrationPage.clickSection("Applications", "Applications Panel");
64  3 return new ApplicationsPanelAdministrationPage();
65    }
66   
 
67  14 toggle public List<String> getApplicationsInBar()
68    {
69  14 return getApplicationsInPanel(displayedPanels);
70    }
71   
 
72  7 toggle public List<String> getApplicationsNotInBar()
73    {
74  7 return getApplicationsInPanel(blacklistedPanels);
75    }
76   
 
77  21 toggle private List<String> getApplicationsInPanel(WebElement panel)
78    {
79  21 List<String> results = new ArrayList<>();
80  21 for (WebElement elem : getDriver().findElementsWithoutWaiting(panel,
81    By.xpath("div[contains(@class, 'panel-body')]/ul"
82    + "/li[contains(@class, 'draggableApp')]//span[contains(@class, 'application-label')]"))) {
83  55 results.add(elem.getText());
84    }
85   
86  21 return results;
87    }
88   
 
89  1 toggle public void addApplicationInBar(String appName)
90    {
91  1 moveAppToPanel(appName, displayedPanels, blacklistedPanels);
92    }
93   
 
94  2 toggle public void removeApplicationFromBar(String appName)
95    {
96  2 moveAppToPanel(appName, blacklistedPanels, displayedPanels);
97    }
98   
 
99  3 toggle private void moveAppToPanel(String appName, WebElement panel, WebElement fromPanel)
100    {
101  3 By appSelector = By.linkText(appName);
102  3 WebElement app = fromPanel.findElement(appSelector);
103  3 WebElement destination = panel.findElement(By.tagName("ul"));
104  3 new Actions(getDriver()).dragAndDrop(app, destination).perform();
105   
106  3 getDriver().waitUntilCondition(webDriver ->
107    getDriver().hasElementWithoutWaiting(panel, appSelector)
108    && !getDriver().hasElementWithoutWaiting(fromPanel, appSelector)
109    );
110    }
111   
 
112  5 toggle public void moveAppBefore(String appName, String appBeforeName)
113    {
114  5 if (appName.equals(appBeforeName)) {
115    // do nothing
116  1 return;
117    }
118   
119  4 WebElement app = displayedPanels.findElement(By.linkText(appName));
120  4 WebElement appBefore = displayedPanels.findElement(By.linkText(appBeforeName));
121  4 Point target = appBefore.getLocation();
122  4 Point source = app.getLocation();
123   
124    // The drag & drop of the "sortable" plugin of "jquery-ui" is very sensitive so we need to script the
125    // moves of the mouse precisely if we don't want to have flickers.
126  4 Actions actions = new Actions(getDriver());
127    // First we hold the app
128  4 actions.clickAndHold(app);
129    // Then we move into the position of the targeted app so jquery-ui can register we want to take its place.
130  4 actions.moveByOffset(target.getX() - source.getX(), target.getY() - source.getY());
131    // Now we do a little move on top left so jquery-ui understand we want to be *before* the other app and
132    // put a blank place instead of the other app.
133  4 actions.moveByOffset(-5, -5);
134    // Do it
135  4 actions.perform();
136   
137    // Before releasing the click, check that jquery-ui has moved the other app to let the place free.
138  4 getDriver().waitUntilCondition(new ExpectedCondition<Object>()
139    {
 
140  4 toggle @Override
141    public Object apply(WebDriver webDriver)
142    {
143  4 Point newTarget = appBefore.getLocation();
144  4 Point newSource = app.getLocation();
145  4 return newTarget.getX() > newSource.getX() + 5 || newTarget.getY() > newSource.getY() + 5;
146    }
147    });
148   
149    // Now we can release the selection
150  4 actions = new Actions(getDriver());
151  4 actions.release();
152  4 actions.perform();
153    }
154   
 
155  1 toggle public void revert()
156    {
157  1 revertButton.click();
158    }
159   
 
160  2 toggle public void save()
161    {
162  2 saveButton.click();
163    }
164   
 
165  2 toggle public boolean hasSuccessNotification()
166    {
167  2 WebElement notification = getDriver().findElement(By.className("xnotification-done"));
168  2 return notification != null && "The configuration has been saved.".equals(notification.getText());
169    }
170    }