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

File DocumentDiffSummary.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

0
30
21
1
183
119
21
0.7
1.43
21
1

Classes

Class Line # Actions
DocumentDiffSummary 35 30 0% 21 10
0.803921680.4%
 

Contributing tests

This file is covered by 2 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.test.ui.po.diff;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import org.openqa.selenium.By;
26    import org.openqa.selenium.WebElement;
27    import org.xwiki.test.ui.po.BaseElement;
28   
29    /**
30    * Represents the summary displayed when comparing two versions of a document.
31    *
32    * @version $Id: 0cbbcb3c68f300efe2f6f4911f64698c660a77ef $
33    * @since 7.0RC1
34    */
 
35    public class DocumentDiffSummary extends BaseElement
36    {
37    private static final String PAGE_PROPERTIES = "Page properties";
38   
39    private static final String ATTACHMENTS = "Attachments";
40   
41    private static final String OBJECTS = "Objects";
42   
43    private static final String CLASS_PROPERTIES = "Class properties";
44   
45    private static final String ACTION_CHANGE = "change";
46   
47    private static final String ACTION_INSERT = "insert";
48   
49    private static final String ACTION_DELETE = "delete";
50   
51    /**
52    * The element that wraps and container the summary.
53    */
54    private WebElement container;
55   
56    /**
57    * Creates a new instance for the specified summary.
58    *
59    * @param container the element that wraps and contains the summary
60    */
 
61  2 toggle public DocumentDiffSummary(WebElement container)
62    {
63  2 this.container = container;
64    }
65   
 
66  1 toggle public List<String> getItems()
67    {
68  1 List<WebElement> items =
69    getDriver().findElementsWithoutWaiting(this.container, By.xpath(".//div[@class = 'diff-summary-item']/a"));
70  1 List<String> labels = new ArrayList<>();
71  1 for (WebElement item : items) {
72  4 labels.add(item.getText());
73    }
74  1 return labels;
75    }
76   
 
77  1 toggle public String getPagePropertiesSummary()
78    {
79  1 return getSummaryItemHint(PAGE_PROPERTIES);
80    }
81   
 
82  1 toggle public String getAttachmentsSummary()
83    {
84  1 return getSummaryItemHint(ATTACHMENTS);
85    }
86   
 
87  1 toggle public DocumentDiffSummary toggleAttachmentsDetails()
88    {
89  1 return toggleDetails(ATTACHMENTS);
90    }
91   
 
92  0 toggle public List<String> getModifiedAttachments()
93    {
94  0 return getSummaryItemDetails(ATTACHMENTS, ACTION_CHANGE);
95    }
96   
 
97  1 toggle public List<String> getAddedAttachments()
98    {
99  1 return getSummaryItemDetails(ATTACHMENTS, ACTION_INSERT);
100    }
101   
 
102  0 toggle public List<String> getRemovedAttachments()
103    {
104  0 return getSummaryItemDetails(ATTACHMENTS, ACTION_DELETE);
105    }
106   
 
107  1 toggle public String getObjectsSummary()
108    {
109  1 return getSummaryItemHint(OBJECTS);
110    }
111   
 
112  2 toggle public DocumentDiffSummary toggleObjectsDetails()
113    {
114  2 return toggleDetails(OBJECTS);
115    }
116   
 
117  1 toggle public List<String> getModifiedObjects()
118    {
119  1 return getSummaryItemDetails(OBJECTS, ACTION_CHANGE);
120    }
121   
 
122  1 toggle public List<String> getAddedObjects()
123    {
124  1 return getSummaryItemDetails(OBJECTS, ACTION_INSERT);
125    }
126   
 
127  0 toggle public List<String> getRemovedObjects()
128    {
129  0 return getSummaryItemDetails(OBJECTS, ACTION_DELETE);
130    }
131   
 
132  1 toggle public String getClassPropertiesSummary()
133    {
134  1 return getSummaryItemHint(CLASS_PROPERTIES);
135    }
136   
 
137  1 toggle public DocumentDiffSummary toggleClassPropertiesDetails()
138    {
139  1 return toggleDetails(CLASS_PROPERTIES);
140    }
141   
 
142  0 toggle public List<String> getModifiedClassProperties()
143    {
144  0 return getSummaryItemDetails(CLASS_PROPERTIES, ACTION_CHANGE);
145    }
146   
 
147  1 toggle public List<String> getAddedClassProperties()
148    {
149  1 return getSummaryItemDetails(CLASS_PROPERTIES, ACTION_INSERT);
150    }
151   
 
152  0 toggle public List<String> getRemovedClassProperties()
153    {
154  0 return getSummaryItemDetails(CLASS_PROPERTIES, ACTION_DELETE);
155    }
156   
 
157  4 toggle private String getSummaryItemHint(String label)
158    {
159  4 return this.container.findElement(
160    By.xpath(".//span[@class = 'diff-summary-item-hint' and preceding-sibling::a[. = '" + label + "']]"))
161    .getText();
162    }
163   
 
164  4 toggle private List<String> getSummaryItemDetails(String label, String action)
165    {
166  4 List<WebElement> elements =
167    getDriver().findElementsWithoutWaiting(
168    this.container,
169    By.xpath(".//li[@class = 'diff-summary-item' and child::span[@class = 'diff-icon diff-icon-" + action
170    + "'] and parent::ul/preceding-sibling::div[1]/a[. = '" + label + "']]"));
171  4 List<String> labels = new ArrayList<>();
172  4 for (WebElement element : elements) {
173  5 labels.add(element.getText().trim());
174    }
175  4 return labels;
176    }
177   
 
178  4 toggle private DocumentDiffSummary toggleDetails(String label)
179    {
180  4 this.container.findElement(By.xpath(".//div[@class = 'diff-summary-item']/a[. = '" + label + "']")).click();
181  4 return this;
182    }
183    }