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

File ClassSheetPage.java

 

Coverage histogram

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

Code metrics

2
30
14
1
257
106
15
0.5
2.14
14
1.07

Classes

Class Line # Actions
ClassSheetPage 37 30 0% 15 0
1.0100%
 

Contributing tests

This file is covered by 6 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.xclass.test.po;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.WebElement;
24    import org.openqa.selenium.support.FindBy;
25    import org.xwiki.test.ui.po.DocumentPicker;
26    import org.xwiki.test.ui.po.InlinePage;
27    import org.xwiki.test.ui.po.LiveTableElement;
28    import org.xwiki.test.ui.po.ViewPage;
29    import org.xwiki.test.ui.po.editor.ClassEditPage;
30   
31    /**
32    * Represents the sheet used to display information about a XWiki class.
33    *
34    * @version $Id: 5d63ff867f0b13a17e0f3fe2990f131a8b49ac72 $
35    * @since 3.4M1
36    */
 
37    public class ClassSheetPage extends ViewPage
38    {
39    /**
40    * The link to view the class template.
41    */
42    @FindBy(partialLinkText = "View the template page")
43    private WebElement templateLink;
44   
45    /**
46    * The link to view the class sheet.
47    */
48    @FindBy(partialLinkText = "View the sheet page")
49    private WebElement sheetLink;
50   
51    /**
52    * The link to define the class. This is displayed only if the class doesn't have any properties.
53    */
54    @FindBy(xpath = "//*[contains(@class, 'warningmessage')]//a[. = 'class editor']")
55    private WebElement defineClassLink;
56   
57    /**
58    * The link to the class editor. This is displayed only if the class has properties.
59    */
60    @FindBy(linkText = "add or modify the class properties")
61    private WebElement editClassLink;
62   
63    /**
64    * The button used to create the class sheet.
65    */
66    @FindBy(xpath = "//input[@class = 'button' and @value = 'Create the sheet']")
67    private WebElement createSheetButton;
68   
69    /**
70    * The link used to bind the class to its sheet.
71    */
72    @FindBy(xpath = "//*[contains(@class, 'warningmessage')]//a[. = 'Bind the sheet to the class \u00BB']")
73    private WebElement bindSheetLink;
74   
75    /**
76    * The button used to create the class template.
77    */
78    @FindBy(xpath = "//input[@class = 'button' and @value = 'Create the template']")
79    private WebElement createTemplateButton;
80   
81    /**
82    * The link used to add an instance of the class to the template document.
83    */
84    @FindBy(xpath = "//*[contains(@class, 'warningmessage')]//a[contains(., ' object to the template \u00BB')]")
85    private WebElement addObjectToTemplateLink;
86   
87    /**
88    * The widget used to specify the class instance to create.
89    */
90    private DocumentPicker documentPicker;
91   
92    /**
93    * The button used to create a new document based on the class template.
94    */
95    @FindBy(xpath = "//input[@class = 'button' and @value = 'Create this page']")
96    private WebElement createDocumentButton;
97   
98    /**
99    * The live table that lists the existing class entries.
100    */
101    private LiveTableElement classEntriesLiveTable = new LiveTableElement("classEntries");
102   
103    /**
104    * Clicks on the template link and returns the template page
105    *
106    * @return the page that represents the class template
107    */
 
108  7 toggle public ViewPage clickTemplateLink()
109    {
110  7 templateLink.click();
111  7 return new ViewPage();
112    }
113   
114    /**
115    * Clicks on the link to view the class sheet.
116    *
117    * @return the page that represents the class sheet
118    */
 
119  1 toggle public ViewPage clickSheetLink()
120    {
121  1 sheetLink.click();
122  1 return new ViewPage();
123    }
124   
125    /**
126    * Clicks on the link to define the class. This link is visible only if the class has no properties yet.
127    *
128    * @return the class editor
129    */
 
130  1 toggle public ClassEditPage clickDefineClassLink()
131    {
132  1 defineClassLink.click();
133  1 return new ClassEditPage();
134    }
135   
136    /**
137    * Clicks on the link to edit the class. This link is visible only if the class has properties.
138    *
139    * @return the class editor
140    */
 
141  1 toggle public ClassEditPage clickEditClassLink()
142    {
143  1 editClassLink.click();
144  1 return new ClassEditPage();
145    }
146   
147    /**
148    * @param name the property name
149    * @param prettyName the property pretty name
150    * @param type the property type
151    * @return {@code true} if the sheet lists the specified property, {@code false} otherwise
152    */
 
153  2 toggle public boolean hasProperty(String name, String prettyName, String type)
154    {
155    // Pretty Name (Name: Type)
156  2 String xpath = String.format("//li[. = '%s (%s: %s)']", prettyName, name, type);
157  2 return getDriver().findElementsWithoutWaiting(By.xpath(xpath)).size() == 1;
158    }
159   
160    /**
161    * Clicks on the button to create a sheet for the class that is being displayed.
162    *
163    * @return the current page, after it is reloaded
164    */
 
165  1 toggle public ClassSheetPage clickCreateSheetButton()
166    {
167  1 createSheetButton.click();
168    // Create a new instance because the page is reloaded.
169  1 return new ClassSheetPage();
170    }
171   
172    /**
173    * Clicks on the link to bind the class to its sheet.
174    *
175    * @return the current page, after it is reloaded
176    */
 
177  1 toggle public ClassSheetPage clickBindSheetLink()
178    {
179  1 bindSheetLink.click();
180    // Create a new instance because the page is reloaded.
181  1 return new ClassSheetPage();
182    }
183   
184    /**
185    * Clicks on the button to create the class template.
186    *
187    * @return the current page, after it is reloaded
188    */
 
189  1 toggle public ClassSheetPage clickCreateTemplateButton()
190    {
191  1 createTemplateButton.click();
192  1 return new ClassSheetPage();
193    }
194   
195    /**
196    * Clicks on the link to add an instance of the class to the template document.
197    *
198    * @return the current page, after it is reloaded
199    */
 
200  1 toggle public ClassSheetPage clickAddObjectToTemplateLink()
201    {
202  1 addObjectToTemplateLink.click();
203  1 return new ClassSheetPage();
204    }
205   
 
206  5 toggle public DocumentPicker getNewPagePicker()
207    {
208  5 if (this.documentPicker == null) {
209  2 this.documentPicker = new DocumentPicker();
210    }
211  5 return this.documentPicker;
212    }
213   
214    /**
215    * Clicks the button to create a new document based on the class template.
216    *
217    * @return the in-line edit mode for the new document
218    */
 
219  2 toggle public InlinePage clickCreateDocumentButton()
220    {
221  2 createDocumentButton.click();
222  2 return new InlinePage();
223    }
224   
225    /**
226    * Creates a new document with the specified name, in the specified space, based on the class template.
227    *
228    * @param spaceName the name of the space where to create the new document
229    * @param pageName the name of the new document
230    * @return the in-line mode for the new document
231    */
 
232  2 toggle public InlinePage createNewDocument(String spaceName, String pageName)
233    {
234  2 getNewPagePicker().setParent(spaceName);
235  2 getNewPagePicker().setName(pageName);
236  2 return clickCreateDocumentButton();
237    }
238   
239    /**
240    * @param documentName the name of a document
241    * @return {@code true} if the specified document is listed as having an object of the class being viewed,
242    * {@code false} otherwise
243    */
 
244  1 toggle public boolean hasDocument(String documentName)
245    {
246  1 this.classEntriesLiveTable.filterColumn("xwiki-livetable-classEntries-filter-2", documentName);
247    // This can lead to false positives, but it should be fine if the passed document name is specific enough.
248  1 return this.classEntriesLiveTable.getRowCount() > 0;
249    }
250   
 
251  10 toggle @Override
252    public ClassSheetPage waitUntilPageIsLoaded()
253    {
254  10 this.classEntriesLiveTable.waitUntilReady();
255  10 return this;
256    }
257    }