1
|
/**
|
2
|
* Copyright (C) 2020 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.dataportal.selenium.tests.reference;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.util.List;
|
13
|
import java.util.Optional;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.lang3.StringUtils;
|
17
|
import org.apache.log4j.Level;
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.Test;
|
21
|
import org.openqa.selenium.By;
|
22
|
import org.openqa.selenium.WebElement;
|
23
|
|
24
|
import eu.etaxonomy.dataportal.DataPortalSite;
|
25
|
import eu.etaxonomy.dataportal.DrupalVars;
|
26
|
import eu.etaxonomy.dataportal.elements.BaseElement;
|
27
|
import eu.etaxonomy.dataportal.elements.LinkElement;
|
28
|
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
|
29
|
import eu.etaxonomy.dataportal.junit.DataPortalContextSuite.DataPortalContexts;
|
30
|
import eu.etaxonomy.dataportal.pages.TaxonPage;
|
31
|
import eu.etaxonomy.drush.DrushExecuter;
|
32
|
import eu.etaxonomy.drush.DrushExecutionFailure;
|
33
|
|
34
|
/**
|
35
|
* @author a.kohlbecker
|
36
|
* @since Aug 11, 2020
|
37
|
*/
|
38
|
@DataPortalContexts( { DataPortalSite.reference })
|
39
|
public class SpecimenTableViewTest extends CdmDataPortalTestBase {
|
40
|
|
41
|
|
42
|
private static final String DETAIL_IMAGE_DERIVATE_ICON = "cdm_dataportal/images/detail_image_derivate-16x16-32.png";
|
43
|
|
44
|
private static final String STEP_DONE_ICON = "cdm_dataportal/images/step_done.gif";
|
45
|
|
46
|
public static final Logger logger = Logger.getLogger(DrushExecuter.class);
|
47
|
|
48
|
private static final UUID glenodinium_apiculatum_t = UUID.fromString("d245083e-3bda-435f-9bb3-bdc2249ff23c");
|
49
|
|
50
|
TaxonPage p = null;
|
51
|
|
52
|
@Before
|
53
|
public void switchToView() throws IOException, InterruptedException, DrushExecutionFailure {
|
54
|
Logger.getLogger(DrushExecuter.class).setLevel(Level.DEBUG);
|
55
|
setDrupalVar(DrupalVars.CDM_DATAPORTAL_TAXONPAGE_TABS, "1");
|
56
|
setDrupalVar(DrupalVars.CDM_SPECIMEN_LIST_VIEW_MODE, "derivate_table");
|
57
|
p = new TaxonPage(driver, getContext(), glenodinium_apiculatum_t, "specimens");
|
58
|
}
|
59
|
|
60
|
@Test
|
61
|
public void testPageTitle() {
|
62
|
assertEquals(getContext().prepareTitle("Glenodinium apiculatum"), p.getTitle());
|
63
|
}
|
64
|
|
65
|
// @Test no point testing for the tab, the reference portal is set up being tab-less
|
66
|
public void testPageTab() {
|
67
|
Optional<LinkElement> activeTab = p.getActivePrimaryTab();
|
68
|
assertTrue(activeTab.isPresent());
|
69
|
assertEquals("Specimens\n(active tab)", activeTab.get().getText());
|
70
|
}
|
71
|
|
72
|
@Test
|
73
|
public void testTableHaders() {
|
74
|
|
75
|
WebElement specimensTable = p.getDataPortalContent().getElement().findElement(By.cssSelector("#derivate_hierarchy_table"));
|
76
|
List<WebElement> headerRows = specimensTable.findElements(By.cssSelector("tr th"));
|
77
|
// Country Date Collector + collecting number Herbaria Type Scan Derivatives
|
78
|
// first row is empty, this is the "expand row"
|
79
|
assertEquals("Country", headerRows.get(1).getText());
|
80
|
assertEquals("Date", headerRows.get(2).getText());
|
81
|
assertEquals("Collector + collecting number", headerRows.get(3).getText());
|
82
|
assertEquals("Herbaria", headerRows.get(4).getText());
|
83
|
assertEquals("Type", headerRows.get(5).getText());
|
84
|
assertEquals("Scan", headerRows.get(6).getText());
|
85
|
assertEquals("Derivatives", headerRows.get(7).getText());
|
86
|
|
87
|
}
|
88
|
|
89
|
@Test
|
90
|
public void testTable() {
|
91
|
|
92
|
WebElement specimensTable = p.getDataPortalContent().getElement().findElement(By.cssSelector("#derivate_hierarchy_table"));
|
93
|
|
94
|
List<WebElement> rows = specimensTable.findElements(By.cssSelector("tr"));
|
95
|
assertEquals(7, rows.size());
|
96
|
// expected rows:
|
97
|
// 0: header row
|
98
|
|
99
|
// 1: summary row
|
100
|
// 2: detail row
|
101
|
// 3: summary row
|
102
|
// 4: detail row
|
103
|
// 3: summary row
|
104
|
// 4: detail row
|
105
|
|
106
|
// summary row
|
107
|
int rowId = 1;
|
108
|
assertTrue(rows.get(rowId).getAttribute("class").contains("summary_row"));
|
109
|
List<WebElement> cells = rows.get(rowId).findElements(By.tagName("td"));
|
110
|
assertEquals("(B SP-99999).", cells.get(1).getText());
|
111
|
// cell number 1 has colspan = 5 !!!
|
112
|
assertTrue(cells.get(2).findElement(By.tagName("img")).getAttribute("src")
|
113
|
.endsWith(STEP_DONE_ICON)); // scan
|
114
|
++rowId;
|
115
|
|
116
|
++rowId;
|
117
|
assertTrue(rows.get(rowId).getAttribute("class").contains("summary_row"));
|
118
|
cells = rows.get(rowId).findElements(By.tagName("td"));
|
119
|
assertEquals("Germany", cells.get(1).getText());
|
120
|
assertEquals("1835-04-02", cells.get(2).getText());
|
121
|
assertEquals("", cells.get(3).getText());
|
122
|
// all other empty, TODO check if this is correct or if some data is being missed here
|
123
|
|
124
|
// details row
|
125
|
++rowId;
|
126
|
assertTrue(rows.get(rowId).getAttribute("class").contains("detail_row"));
|
127
|
assertEquals("Should be initially invisible", "none", rows.get(rowId).getCssValue("display"));
|
128
|
rows.get(rowId - 1).click();
|
129
|
assertEquals("The click should make it visible", "table-row", rows.get(rowId).getCssValue("display"));
|
130
|
cells = rows.get(rowId).findElements(By.tagName("td"));
|
131
|
String detailsText = cells.get(1).getText();
|
132
|
String[] detailsLines = StringUtils.split(detailsText, "\n");
|
133
|
assertEquals(1, detailsLines.length);
|
134
|
assertEquals("Citation: Germany, Berlin, 2 Apr 1835.", detailsLines[0]);
|
135
|
|
136
|
|
137
|
// summary row
|
138
|
++rowId;
|
139
|
assertTrue(rows.get(rowId).getAttribute("class").contains("summary_row"));
|
140
|
cells = rows.get(rowId).findElements(By.tagName("td"));
|
141
|
assertEquals("Germany", cells.get(1).getText());
|
142
|
assertEquals("2016-03-28", cells.get(2).getText());
|
143
|
assertEquals("Ehrenberg, C.G. D047", cells.get(3).getText());
|
144
|
// Only two preserved specimes exepectet in the collection statistics"
|
145
|
assertEquals("CEDiT, M", cells.get(4).getText());
|
146
|
assertTrue(cells.get(5).findElement(By.tagName("img")).getAttribute("src")
|
147
|
.endsWith(STEP_DONE_ICON));
|
148
|
assertTrue(cells.get(6).findElement(By.tagName("img")).getAttribute("src")
|
149
|
.endsWith(STEP_DONE_ICON));
|
150
|
assertTrue(cells.get(7).findElement(By.tagName("img")).getAttribute("src")
|
151
|
.endsWith(DETAIL_IMAGE_DERIVATE_ICON));
|
152
|
|
153
|
|
154
|
// details row
|
155
|
++rowId;
|
156
|
assertTrue(rows.get(rowId).getAttribute("class").contains("detail_row"));
|
157
|
assertEquals("Should be initially invisible", "none", rows.get(rowId).getCssValue("display"));
|
158
|
rows.get(rowId - 1).click();
|
159
|
assertEquals("The click should make it visible", "table-row", rows.get(rowId).getCssValue("display"));
|
160
|
cells = rows.get(rowId).findElements(By.tagName("td"));
|
161
|
detailsText = cells.get(1).getText();
|
162
|
detailsLines = StringUtils.split(detailsText, "\n");
|
163
|
BaseElement detailsCell = new BaseElement(cells.get(1));
|
164
|
List<LinkElement> linksInDetails = detailsCell.getLinksInElement();
|
165
|
assertEquals(9, detailsLines.length);
|
166
|
assertEquals("Citation: Germany, Berlin, alt. 165 m, 52°31'1.2\"N, 13°21'E (WGS84), 28 Mar 2016, Ehrenberg D047. (CEDiT 2017E68, M M-0289351)", detailsLines[0]);
|
167
|
|
168
|
assertEquals("Specimen summary: CEDiT 2017E68", detailsLines[1]);
|
169
|
assertEquals("CEDiT 2017E68" ,linksInDetails.get(0).getText());
|
170
|
assertTrue(linksInDetails.get(0).getUrl().endsWith("cdm_dataportal/occurrence/8585081c-b73b-440b-b349-582845cf3fb4"));
|
171
|
assertEquals("Preferred stable URI: http://testid.org/2017E68", detailsLines[2]);
|
172
|
assertEquals("http://testid.org/2017E68" ,linksInDetails.get(1).getText());
|
173
|
assertEquals("http://testid.org/2017E68", linksInDetails.get(1).getUrl());
|
174
|
assertEquals("Epitype of Glenodinium apiculatum Ehrenb.", detailsLines[3]);
|
175
|
assertEquals("Specimen Scans: CEDiT 2017E68", detailsLines[4]);
|
176
|
assertEquals("Detail Images: Masks", detailsLines[5]);
|
177
|
assertEquals("Masks" ,linksInDetails.get(3).getText());
|
178
|
assertEquals("https://imgs.xkcd.com/comics/masks_2x.png", linksInDetails.get(3).getUrl());
|
179
|
|
180
|
assertEquals("Specimen summary: M M-0289351", detailsLines[6]);
|
181
|
assertEquals("Preferred stable URI: http://herbarium.bgbm.org/object/B400042045", detailsLines[7]);
|
182
|
assertEquals("Isolectotype of Glenodinium apiculatum Ehrenb.", detailsLines[8]);
|
183
|
assertEquals(6, linksInDetails.size());
|
184
|
|
185
|
}
|
186
|
|
187
|
}
|