Project

General

Profile

Download (4.13 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2011 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.dataportal.elements;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14

    
15
import static junit.framework.Assert.*;
16
import static org.junit.Assert.assertEquals;
17

    
18
import org.openqa.selenium.By;
19
import org.openqa.selenium.WebElement;
20
import org.openqa.selenium.WebElement;
21

    
22
/**
23
 * @author andreas
24
 * @date Jul 4, 2011
25
 *
26
 */
27
public class FeatureBlock extends DrupalBlock {
28

    
29
	private List<LinkElement> footNoteKeys = new ArrayList<LinkElement>();
30

    
31
	private List<BaseElement> footNotes = new ArrayList<BaseElement>();
32

    
33
	private List<BaseElement> originalSources = new ArrayList<BaseElement>();
34

    
35
	private List<DescriptionElementRepresentation> descriptionElements = new ArrayList<DescriptionElementRepresentation>();
36

    
37
	private String featureType = null;
38

    
39

    
40
	public List<LinkElement> getFootNoteKeys() {
41
		return footNoteKeys;
42
	}
43

    
44
	public List<BaseElement> getFootNotes() {
45
		return footNotes;
46
	}
47

    
48
	public List<BaseElement> getOriginalSourcesSections() {
49
		return originalSources;
50
	}
51

    
52

    
53
	public List<DescriptionElementRepresentation> getDescriptionElements() {
54
		return descriptionElements;
55
	}
56

    
57
	public String getFeatureType() {
58
		return featureType;
59
	}
60

    
61

    
62
	/**
63
	 * @param element
64
	 */
65
	public FeatureBlock(WebElement element, String enclosingTag, String elementTag) {
66
		super(element);
67

    
68
		List<WebElement> fnkList = element.findElements(By.className("footnote-key"));
69
		for(WebElement fnk : fnkList) {
70
			footNoteKeys.add(new LinkElement(fnk.findElement(By.tagName("a"))));
71
		}
72

    
73
		List<WebElement> fnList = element.findElements(By.className("footnote"));
74
		for(WebElement fn : fnList) {
75
			footNotes.add(new BaseElement(fn));
76
		}
77

    
78
		List<WebElement> sourcesList = element.findElements(By.className("sources"));
79
		for(WebElement source : sourcesList) {
80
			originalSources.add(new BaseElement(source));
81
		}
82

    
83
		WebElement descriptionElementsRepresentation =  element.findElement(By.className("description"));
84
		featureType = descriptionElementsRepresentation.getAttribute("id");
85

    
86
		//TODO throw exception instead of making an assetion! selenium should have appropriate exeptions
87
		assertEquals("Unexpected tag enclosing description element representations", enclosingTag, descriptionElementsRepresentation.getTagName());
88

    
89
		for(WebElement el : descriptionElementsRepresentation.findElements(By.tagName(elementTag))){
90
			descriptionElements.add(new DescriptionElementRepresentation(el));
91
		}
92

    
93
	}
94

    
95
	/**
96
	 * @param indent
97
	 * @param computedFontSize
98
	 * @param expectedCssDisplay
99
	 * @param expectedListStyleType only applies if cssDisplay equals list-item
100
	 * @param expectedListStylePosition only applies if cssDisplay equals list-item
101
	 * @param expectedListStyleImage only applies if cssDisplay equals list-item
102
	 */
103
	public void testDescriptionElementLayout(int descriptionElementId, int indent, int computedFontSize
104
			, String expectedCssDisplay, String expectedListStyleType, String expectedListStylePosition, String expectedListStyleImage) {
105

    
106
		DescriptionElementRepresentation firstDescriptionElement = getDescriptionElements().get(descriptionElementId);
107

    
108
		int parentX = getElement().getLocation().getX();
109
		int elementX = firstDescriptionElement.getElement().getLocation().getX();
110
		double elementPadLeft = pxSizeToDouble(firstDescriptionElement.getElement().getCssValue("padding-left"));
111

    
112
		assertEquals(indent, elementX - parentX + elementPadLeft, PIXEL_TOLERANCE);
113
		assertEquals(computedFontSize, firstDescriptionElement.getComputedFontSize(), 0.5);
114
		assertEquals(expectedCssDisplay, firstDescriptionElement.getElement().getCssValue("display"));
115

    
116
		if(expectedCssDisplay.equals("list-item")){
117
			assertEquals(expectedListStylePosition, firstDescriptionElement.getElement().getCssValue("list-style-position"));
118
			assertEquals(expectedListStyleImage, firstDescriptionElement.getElement().getCssValue("list-style-image"));
119
			assertEquals(expectedListStyleType, firstDescriptionElement.getElement().getCssValue("list-style-type"));
120
		}
121
	}
122

    
123
}
(4-4/10)