Project

General

Profile

« Previous | Next » 

Revision 09762fde

Added by Andreas Kohlbecker over 3 years ago

fix #9191 test for SpecimensTreeView

View differences:

modules/cdm_dataportal/includes/occurrences.inc
986 986
}
987 987

  
988 988
/**
989
 * Crates an array which can be used in render arrays to be passed to the theme_table() and theme_list().
989
 * Crates an array which can be used in render arrays to be passed to the
990
 * theme_table() and theme_list().
991
 *
990 992
 * @param array $fieldunit_dtos
991 993
 *     list of FieldUnitDTOs
992 994
 */
......
1156 1158
}
1157 1159

  
1158 1160
/**
1159
 * Creates an array from a list of FieldUnitDTOs.
1161
 * Composes the view on specimens and occurrences as derivate tree
1162
 * starting from the field unit including all derivatives.
1160 1163
 *
1164
 * @see DM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE
1161 1165
 *
1162 1166
 * @param object $fieldunit_dtos
1163 1167
 *   list of FieldUnitDTOs
1164 1168
 * @return array
1165
 *   An array containing the hierarchy of the field units corresponding to the taxon
1169
 *   The Drupal render array
1166 1170
 *
1167 1171
 * @ingroup compose
1168 1172
 */
......
1191 1195
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1192 1196
    // otherwise it is handled as child render array
1193 1197
    '#attributes' => array(
1194
      'class' => 'specimens',
1198
      'class' => 'specimens ' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE ,
1195 1199
      'id' => $tableId
1196 1200
    ),
1197 1201
    '#rows' => array(),
......
1644 1648
    '#weight' => 2,
1645 1649
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1646 1650
    // otherwise it is handled as child render array
1647
    '#attributes' => array('class' => 'specimens'),
1651
    '#attributes' => array('class' => 'specimens '),
1648 1652
    '#rows' => array(),
1649 1653
  );
1650 1654

  
src/main/java/eu/etaxonomy/dataportal/ElementUtils.java
137 137
        if(StringUtils.isNotEmpty(classAttr)) {
138 138
            markup += " class=\""+ classAttr + "\"";
139 139
        }
140
        markup += " >";
140
        markup += ">";
141 141
        return markup;
142 142
    }
143 143

  
src/main/java/eu/etaxonomy/dataportal/elements/BaseElement.java
13 13
import java.util.List;
14 14

  
15 15
import org.apache.commons.lang.StringUtils;
16
import org.apache.log4j.Level;
17 16
import org.apache.log4j.Logger;
18 17
import org.openqa.selenium.By;
19 18
import org.openqa.selenium.NoSuchElementException;
......
101 100

  
102 101
    public List<LinkElement> getFootNoteKeys(){
103 102
        return ElementUtils.linkElementsFromFootNoteKeyListElements(
104
                getElement().findElements(By.xpath("//*[contains(@class, 'footnote-key')]/a"))
103
                getElement().findElements(By.xpath(".//*[contains(@class, 'footnote-key')]/a"))
105 104
                );
106 105
    }
107 106

  
......
160 159

  
161 160
    public BaseElement(WebElement element) {
162 161

  
163
        logger.setLevel(Level.TRACE);
164 162
        logger.trace("BaseElement() - constructor");
165 163
        this.element = element;
166 164

  
165
        logger.debug("wrapping " + ElementUtils.webElementTagToMarkup(getElement()));
167 166
        // read and tokenize the class attribute
168 167
        if (element.getAttribute("class") != null) {
169 168
            String[] classTokens = element.getAttribute("class").split("\\s");
......
175 174

  
176 175
    @Override
177 176
    public String toString() {
178
        return this.getClass().getSimpleName() + "<" + this.getElement().getTagName() + ">" ;
177
        return this.getClass().getSimpleName() + ":" + ElementUtils.webElementTagToMarkup(getElement()) ;
179 178
    }
180 179

  
181 180
    public String toStringWithLinks() {
src/test/java/eu/etaxonomy/dataportal/selenium/tests/reference/SpecimensTreeViewTest.java
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.net.MalformedURLException;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.apache.log4j.Level;
17
import org.apache.log4j.Logger;
18
import org.junit.Before;
19
import org.junit.Test;
20
import org.openqa.selenium.By;
21
import org.openqa.selenium.WebElement;
22

  
23
import eu.etaxonomy.dataportal.DataPortalSite;
24
import eu.etaxonomy.dataportal.DrupalVars;
25
import eu.etaxonomy.dataportal.ElementUtils;
26
import eu.etaxonomy.dataportal.elements.BaseElement;
27
import eu.etaxonomy.dataportal.elements.DescriptionList;
28
import eu.etaxonomy.dataportal.elements.DescriptionList.DescriptionElement;
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.DrushExecuter;
34
import eu.etaxonomy.drush.DrushExecutionFailure;
35

  
36
/**
37
 * @author a.kohlbecker
38
 * @since Aug 11, 2020
39
 */
40
@DataPortalContexts( { DataPortalSite.reference })
41
public class SpecimensTreeViewTest extends CdmDataPortalTestBase {
42

  
43
    public static final Logger logger = Logger.getLogger(DrushExecuter.class);
44

  
45
    private static final UUID glenodinium_apiculatum_t = UUID.fromString("d245083e-3bda-435f-9bb3-bdc2249ff23c");
46

  
47

  
48

  
49
    @Before
50
    public void switchToView() throws IOException, InterruptedException, DrushExecutionFailure {
51
        Logger.getLogger(DrushExecuter.class).setLevel(Level.DEBUG);
52
        setDrupalVar(DrupalVars.CDM_DATAPORTAL_TAXONPAGE_TABS, "1");
53
        setDrupalVar(DrupalVars.CDM_SPECIMEN_LIST_VIEW_MODE, "derivate_tree");
54
    }
55

  
56
    @Test
57
    public void test1() throws MalformedURLException {
58
        TaxonPage p = new TaxonPage(driver, getContext(), glenodinium_apiculatum_t, "specimens");
59
        WebElement specimensTable = p.getDataPortalContent().getElement().findElement(By.cssSelector("#specimens table.derivate_tree"));
60
        List<WebElement> summaryRows = specimensTable.findElements(By.cssSelector("tr.summary_row"));
61
        List<WebElement> detailRows = specimensTable.findElements(By.cssSelector("tr.detail_row"));
62
        assertEquals(3, summaryRows.size());
63
        assertEquals("Germany, Berlin, 52°31'1.2\"N, 13°21'E, 28.3.2016, D047.", summaryRows.get(0).getText());
64
        assertEquals("Germany, Berlin, 52°31'1.2\"N, 13°21'E, 28.3.2016, D047.", summaryRows.get(1).getText());
65
        assertEquals("Germany, Berlin, 2.4.1835.", summaryRows.get(2).getText());
66

  
67

  
68
        // Germany, Berlin, 52°31'1.2\"N, 13°21'E, 28.3.2016, D047.
69
        summaryRows.get(0).click(); // make the row visible
70

  
71
        WebElement descriptionListContainerElement = detailRows.get(0).findElement(By.cssSelector("div.description_list"));
72
        WebElement derivateTreeContainer = descriptionListContainerElement.findElement(By.xpath("./parent::li"));
73
        logger.debug("derivateTreeContainer: " + ElementUtils.webElementTagToMarkup(derivateTreeContainer));
74

  
75
        List<WebElement> dls = detailRows.get(0).findElements(By.cssSelector("div.description_list"));
76
        assertEquals(3, dls.size());
77
        DescriptionList dl1 = new DescriptionList(dls.get(0).findElement(By.tagName("dl")));
78
        assertEquals("Field Unit", dl1.joinedDescriptionElementText("Record base:"));
79
        assertEquals("Germany", dl1.joinedDescriptionElementText("Country:"));
80
        assertEquals("Berlin", dl1.joinedDescriptionElementText("Locality:"));
81
        BaseElement descriptionListContainer = new BaseElement(derivateTreeContainer);
82
        assertEquals(3, descriptionListContainer.getLinksInElement().size()); // other links in the derivate tree are also found
83
        LinkElement link1 = descriptionListContainer.getLinksInElement().get(0);
84
        assertEquals("Detail page", link1.getText());
85
        assertTrue(link1.getUrl().endsWith("/cdm_dataportal/occurrence/89d36e79-3e80-4468-986e-411ca391452e"));
86

  
87
        DescriptionList dl2 = new DescriptionList(dls.get(1).findElement(By.tagName("dl")));
88

  
89
        assertEquals("Preserved Specimen", dl2.joinedDescriptionElementText("Record base:"));
90
        assertEquals("2017E68", dl2.joinedDescriptionElementText("Accession number:"));
91
        assertEquals("\nCode:\nCEDiT", dl2.joinedDescriptionElementText("Collection"));
92
        assertEquals("Specimen", dl2.joinedDescriptionElementText("Kind of unit:"));
93
        assertEquals("Epitype: Germany, Berlin, 52°31'1.2\"N, 13°21'E, 28 Mar 2016, D047 (CEDiT 2017E68).",
94
                dl2.joinedDescriptionElementText("Specimen type designations:"));
95
        DescriptionElement specimenTypeDesignation_dd = dl2.getDescriptionGroups().get("Specimen type designations:").get(0);
96
        List<LinkElement> specimenTypeDesignationLinks = specimenTypeDesignation_dd.getDescriptionElementContent().getLinksInElement();
97
        assertEquals(1, specimenTypeDesignationLinks.size());
98
        assertEquals("CEDiT 2017E68", specimenTypeDesignationLinks.get(0).getText());
99
        assertTrue(specimenTypeDesignationLinks.get(0).getUrl().endsWith("cdm_dataportal/occurrence/8585081c-b73b-440b-b349-582845cf3fb4"));
100

  
101
        // Germany, Berlin, 52°31'1.2"N, 13°21'E, 28.3.2016, D047.
102
        summaryRows.get(1).click(); // make the row visible
103
        descriptionListContainerElement = detailRows.get(1).findElement(By.cssSelector("div.description_list"));
104
        derivateTreeContainer = descriptionListContainerElement.findElement(By.xpath("./parent::li"));
105

  
106
        dls = detailRows.get(1).findElements(By.cssSelector("div.description_list"));
107
        assertEquals(3, dls.size());
108
        dl1 = new DescriptionList(dls.get(0).findElement(By.tagName("dl")));
109
        assertEquals("Field Unit", dl1.joinedDescriptionElementText("Record base:"));
110
        assertEquals("Germany", dl1.joinedDescriptionElementText("Country:"));
111
        assertEquals("Berlin", dl1.joinedDescriptionElementText("Locality:"));
112
        descriptionListContainer = new BaseElement(derivateTreeContainer);
113
        assertEquals(5, descriptionListContainer.getLinksInElement().size()); // other links in the derivate tree are also found
114
        link1 = descriptionListContainer.getLinksInElement().get(0);
115
        assertEquals("Detail page", link1.getText());
116
        assertTrue(link1.getUrl().endsWith("/cdm_dataportal/occurrence/89d36e79-3e80-4468-986e-411ca391452e"));
117

  
118
        dl2 = new DescriptionList(dls.get(1).findElement(By.tagName("dl")));
119

  
120
        assertEquals("Preserved Specimen", dl2.joinedDescriptionElementText("Record base:"));
121
        assertEquals("M-0289351", dl2.joinedDescriptionElementText("Accession number:"));
122
        assertEquals("\nCode:\nM", dl2.joinedDescriptionElementText("Collection"));
123
        assertEquals("Specimen", dl2.joinedDescriptionElementText("Kind of unit:"));
124
        assertEquals("Isolectotype: Germany, Berlin, 52°31'1.2\"N, 13°21'E, 28 Mar 2016, D047 (M M-0289351). http://herbarium.bgbm.org/object/B400042045",
125
                dl2.joinedDescriptionElementText("Specimen type designations:"));
126
        specimenTypeDesignationLinks = dl2.getDescriptionGroups().get("Specimen type designations:").get(0).getDescriptionElementContent().getLinksInElement();
127
        assertEquals(2, specimenTypeDesignationLinks.size());
128
        assertEquals("M M-0289351", specimenTypeDesignationLinks.get(0).getText());
129
        assertTrue(specimenTypeDesignationLinks.get(0).getUrl().endsWith("cdm_dataportal/occurrence/e86c5acd-de55-44af-99f7-484207657264"));
130
        assertEquals("http://herbarium.bgbm.org/object/B400042045", specimenTypeDesignationLinks.get(1).getText());
131
        assertEquals("http://herbarium.bgbm.org/object/B400042045", specimenTypeDesignationLinks.get(1).getUrl().toString());
132

  
133
    }
134

  
135
}

Also available in: Unified diff