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

File EntityDiff.java

 

Coverage histogram

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

Code metrics

2
12
3
1
87
39
5
0.42
4
3
1.67

Classes

Class Line # Actions
EntityDiff 37 12 0% 5 0
1.0100%
 

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.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 pane that displays the differences between two versions of an entity (e.g. document, attachment,
31    * object, class property). For each modified property of the target entity a unified diff is displayed (e.g. the diff
32    * for the document title, attachment content or a meta property of a class property).
33    *
34    * @version $Id: 9efe939087f4ffec5d450df000175565a0116569 $
35    * @since 7.0RC1
36    */
 
37    public class EntityDiff extends BaseElement
38    {
39    /**
40    * The element that wraps and contains the changes for all the entity's properties.
41    */
42    private final WebElement container;
43   
44    /**
45    * Create a new instance for the entity specified by the given element.
46    *
47    * @param container The element that wraps and contains the changes for all the entity's properties.
48    */
 
49  10 toggle public EntityDiff(WebElement container)
50    {
51  10 this.container = container;
52    }
53   
54    /**
55    * @return the list of properties that have been modified
56    */
 
57  7 toggle public List<String> getPropertyNames()
58    {
59  7 List<String> propertyNames = new ArrayList<>();
60  7 for (WebElement element : getDriver().findElementsWithoutWaiting(this.container, By.className("diff-header"))) {
61  23 propertyNames.add(element.getText().trim());
62    }
63  7 return propertyNames;
64    }
65   
66    /**
67    * @param propertyName the name of a modified property of the underlying entity
68    * @return the changes made to the specified property (each item in the returned list is a line in the diff)
69    */
 
70  25 toggle public List<String> getDiff(String propertyName)
71    {
72  25 WebElement element =
73    this.container.findElement(By.xpath(".//div[@class = 'diff-container' and "
74    + "parent::dd/preceding-sibling::dt[1][@class = 'diff-header' and normalize-space(.) = '"
75    + propertyName + "']]"));
76  25 List<String> diff = new ArrayList<>();
77  25 for (WebElement line : getDriver().findElementsWithoutWaiting(element, By.xpath(".//td[3]"))) {
78  81 if (getDriver().findElementsWithoutWaiting(line, By.tagName("ins")).size() > 0
79    || getDriver().findElementsWithoutWaiting(line, By.tagName("del")).size() > 0) {
80  15 diff.add(String.valueOf(getDriver().executeJavascript("return arguments[0].innerHTML", line)));
81    } else {
82  66 diff.add(line.getText());
83    }
84    }
85  25 return diff;
86    }
87    }