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