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

File DocumentPickerModal.java

 

Coverage histogram

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

Code metrics

2
23
11
1
135
78
13
0.57
2.09
11
1.18

Classes

Class Line # Actions
DocumentPickerModal 36 23 0% 13 4
0.888888988.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.index.tree.test.po;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.StaleElementReferenceException;
24    import org.openqa.selenium.WebDriver;
25    import org.openqa.selenium.WebElement;
26    import org.openqa.selenium.support.ui.ExpectedCondition;
27    import org.xwiki.test.ui.po.BaseElement;
28    import org.xwiki.test.ui.po.DocumentPicker;
29   
30    /**
31    * Represents the modal opened when the user changes the location with the {@link DocumentPicker}.
32    *
33    * @version $Id: 7b162f1c2be6fe770084139fe2a88f4e33b7abea $
34    * @since 7.2M3
35    */
 
36    public class DocumentPickerModal extends BaseElement
37    {
38    private WebElement container;
39   
40    private DocumentTreeElement tree;
41   
 
42  2 toggle public DocumentPickerModal()
43    {
44  2 this(By.cssSelector(".location-picker .modal"));
45    }
46   
 
47  4 toggle public DocumentPickerModal(By selector)
48    {
49  4 this.container = getDriver().findElementWithoutWaiting(selector);
50   
51  4 this.waitForIt();
52    }
53   
 
54  11 toggle public DocumentTreeElement getTree()
55    {
56  11 if (this.tree == null) {
57  4 this.tree = new DocumentTreeElement(this.container.findElement(By.className("location-tree")));
58    }
59  11 return this.tree;
60    }
61   
 
62  0 toggle public void cancel()
63    {
64  0 this.container.findElement(By.className("btn-default")).click();
65  0 waitToClose();
66    }
67   
 
68  4 toggle public void select()
69    {
70  4 this.container.findElement(By.className("btn-primary")).click();
71  4 waitToClose();
72    }
73   
 
74  4 toggle public void selectDocument(String... path)
75    {
76  4 getTree().clearSelection().openToDocument(path);
77  4 select();
78    }
79   
 
80  6 toggle public DocumentPickerModal waitForIt()
81    {
82    // Wait for the modal fade animation.
83  6 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
84    {
 
85  8 toggle @Override
86    public Boolean apply(WebDriver driver)
87    {
88  8 try {
89  8 return container.getAttribute("class").endsWith(" in");
90    } catch (StaleElementReferenceException e) {
91    // The element was removed from DOM in the meantime
92  0 return false;
93    }
94    }
95    });
96   
97    // Wait for the document tree to load.
98  6 getTree().waitForIt();
99   
100  6 return this;
101    }
102   
103    /**
104    * The modal may have a fade out effect on close which means it may not disappear instantly. It's safer to wait for
105    * the modal to disappear when closed, before proceeding with next actions.
106    *
107    * @return this model
108    */
 
109  4 toggle public DocumentPickerModal waitToClose()
110    {
111  4 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
112    {
 
113  4 toggle @Override
114    public Boolean apply(WebDriver driver)
115    {
116  4 return !container.isDisplayed();
117    }
118    });
119  4 return this;
120    }
121   
122    /**
123    * Helper method to wait for the specified document to be selected. This is useful when you open the modal and the
124    * tree is expanded to the current selection.
125    *
126    * @param path the path used to locate the element to wait for
127    * @return this modal
128    * @since 7.2
129    */
 
130  1 toggle public DocumentPickerModal waitForDocumentSelected(String... path)
131    {
132  1 getTree().waitForDocumentSelected(path);
133  1 return this;
134    }
135    }