Skip to content

Commit

Permalink
MIR-1226 refinement and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhofmann authored and xaher committed Aug 30, 2023
1 parent f2dad3c commit bfa0fb9
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

public abstract class MIREditorController extends MIRTestController {

Expand Down Expand Up @@ -44,7 +45,8 @@ protected void setHTMLAreaText(String childElementName, String text) {
protected void clickRepeater(String field) {
driver
.waitAndFindElement(
By.xpath(".//button[contains(@name, '" + field + "') and contains(@name, '_xed_submit_insert')]"))
By.xpath(".//button[contains(@name, '" + field + "') and contains(@name, '_xed_submit_insert')]"),
ExpectedConditions::elementToBeClickable)
.click();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.common.MCRException;
import org.mycore.common.selenium.drivers.MCRWebdriverWrapper;
import org.mycore.mir.it.model.MIRAbstract;
import org.mycore.mir.it.model.MIRAccess;
Expand Down Expand Up @@ -263,19 +262,71 @@ public void setIdentifier(List<AbstractMap.Entry<MIRIdentifier, String>> typeIde

public void setTopics(List<String> topics) {
if (topics.size() > 0) {
if (topics.size() > 1) {
IntStream.range(1, topics.size()).forEach((n) -> clickRepeaterAndWait("mods:topic",
".//input[contains(@name, 'mods:topic[" + (n + 1) + "]')]"));
}

IntStream.range(0, topics.size()).forEach(i -> {
String xp = "mods:topic[" + (i + 1) + "]";
String topic = topics.get(i);
setInputText(xp, topic);
IntStream.range(0, topics.size()).forEach((i) -> {
String appBaseXPath = ".//input[contains(@name, 'mods:subjectXML[" + (i + 1)
+ "]')]/following-sibling::div[contains(@class, 'editorToolsApp')]";
String addCustomButton = appBaseXPath + "//button[contains(@class, 'search-add-custom')]";
if (i > 0) {
clickRepeaterAndWait("mods:subjectXML", addCustomButton);
}

driver.waitAndFindElement(By.xpath(addCustomButton)).click();

WebElement selectElement = driver
.waitAndFindElement(By.xpath(appBaseXPath + "//select[contains(@class, 'custom-type-select')]"));
new Select(selectElement).selectByValue("Topic");
WebElement topicInput = driver.waitAndFindElement(
By.xpath(appBaseXPath + "//input[contains(@id, 'topic') and contains(@class, 'form-control')]"));
topicInput.clear();
topicInput.sendKeys(topics.get(i));
waitForAnimationFinish();
driver.waitAndFindElement(By.xpath(appBaseXPath + "//button[contains(@class, 'custom-add')]"))
.click();
});
}
}

public void setGeoPair(String place, String coordinates) {
IntStream.range(0, 2).forEach((i) -> {
String appBaseXPath = ".//input[contains(@name, 'mods:subjectGEO[" + (i + 1)
+ "]')]/following-sibling::div[contains(@class, 'editorToolsApp')]";
String addCustomButton = appBaseXPath + "//button[contains(@class, 'search-add-custom')]";
if (i > 0) {
clickRepeaterAndWait("mods:subjectGEO", addCustomButton);
}

driver.waitAndFindElement(By.xpath(addCustomButton)).click();
if (i == 0) {
WebElement selectElement = driver
.waitAndFindElement(By.xpath(appBaseXPath + "//select[contains(@class, 'custom-type-select')]"));
new Select(selectElement).selectByValue("Geographic");
} else {
WebElement selectElement = driver
.waitAndFindElement(By.xpath(appBaseXPath + "//select[contains(@class, 'custom-type-select')]"));
new Select(selectElement).selectByValue("Cartographics");

driver.waitAndFindElement(
By.xpath(
appBaseXPath + "//div[label[contains(text(), 'Koordinaten')]]/following-sibling::div/button"))
.click();
}

WebElement topicInput = driver.waitAndFindElement(By.xpath(appBaseXPath + "//input[contains(@id, "
+ (i == 0 ? "'geographic'" : "'coordinates'") + ") and contains(@class, 'form-control')]"));
topicInput.clear();
if (i == 0) {
topicInput.sendKeys(place);
} else {
topicInput.sendKeys(coordinates);
}

waitForAnimationFinish();
driver.waitAndFindElement(By.xpath(appBaseXPath + "//button[contains(@class, 'custom-add')]"))
.click();
});
}

public void setClassifications(List<MIRDNBClassification> classifications) {
if (classifications.size() > 0) {
if (classifications.size() > 1) {
Expand All @@ -292,14 +343,6 @@ public void setClassifications(List<MIRDNBClassification> classifications) {
}
}

public void setGeograhicPlace(String place) {
setInputText("mods:geographic", place);
}

public void setCoordinates(String coordinates) {
setInputText("mods:coordinates", coordinates);
}

public void setAuthors(List<String> names) {
setAuthors(names, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ private void fillEditorForm() {
editorController.setEdition(MIRTestData.EDITION);
editorController.setExtend(MIRTestData.EXTEND_SOLO);
editorController.setTypeOfResource(MIRTypeOfResource.still_image);
editorController.setCoordinates(MIRTestData.COORDINATES);
editorController.setGeograhicPlace(MIRTestData.GEOGRAPHIC_PLACE);
editorController.setGeoPair(MIRTestData.GEOGRAPHIC_PLACE, MIRTestData.COORDINATES);
editorController.setClassifications(
Stream.of(MIRDNBClassification._004, MIRDNBClassification._010).collect(Collectors.toList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.mycore.mir.it.model.MIRLanguage;
import org.mycore.mir.it.model.MIRLicense;
import org.mycore.mir.it.model.MIRTypeOfResource;
import org.openqa.selenium.By;

public class MIRAuthorEditorITCase extends MIRITBase {

Expand Down Expand Up @@ -240,8 +241,11 @@ public void testTeachingMaterial() throws InterruptedException {
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_UNI_GER));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_INFORMATIK));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_BIBLIOGRAPHIEN));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC1));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC2));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC1 + ")]"));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC2 + ")]"));

// TODO: enable validation for license
//driver.waitAndFindElement(MCRBy.partialText(MIRLicense.cc_by_40.getValue()));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.VALIDATION_RESOURCE_TEXT));
Expand Down Expand Up @@ -326,8 +330,10 @@ private void refPublicationCommonValidation(boolean standAlone) {
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.URN));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.DOI));

driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC1));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.TOPIC2));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC1 + ")]"));
driver.waitAndFindElement(
By.xpath(".//*[contains(@class, 'topic-element') and contains(text(), " + MIRTestData.TOPIC2 + ")]"));
driver.waitAndFindElement(MCRBy.partialText(MIRTestData.ABSTRACT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public Document process(Document oldXML) throws IOException, JDOMException {
}

private static void fixSubject(Document newXML) throws JDOMException, IOException {
final XPathExpression<Element> subjectsXPath = XPathFactory.instance().compile(".//mods:subjectXML",
final XPathExpression<Element> subjectsXPath
= XPathFactory.instance().compile(".//mods:*[local-name()='subjectXML' or local-name()='subjectGEO']",
Filters.element(), null, MCRConstants.MODS_NAMESPACE,
MCRConstants.XLINK_NAMESPACE);
final List<Element> subjectElements = new ArrayList<>(subjectsXPath.evaluate(newXML));

List<Element> subjectsToRemove = new ArrayList<>();
for (Element subject : subjectElements) {
subject.setName("subject");
subject.removeAttribute("geo");
Expand All @@ -64,7 +66,12 @@ private static void fixSubject(Document newXML) throws JDOMException, IOExceptio
child.detach();
subject.addContent(child);
});
if (subject.getChildren().size() == 0) {
subjectsToRemove.add(subject);
}
}

subjectsToRemove.forEach(subjectToRemove -> subjectToRemove.getParent().removeContent(subjectToRemove));
}

private static void fixTitleInfos(Document newXML) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<xed:include ref="extent" />
<xed:include ref="type.of.resource" />
<xed:include ref="language" />
<xed:include ref="geographicAndCartographics" />
<xed:include ref="sdnb.repeat" />
<xed:include ref="openAIRE" />
<xed:include ref="identifier.managed" />
Expand All @@ -34,7 +35,7 @@
<xed:include ref="rights" />
<xed:include ref="copyrightMD" />
<xed:include ref="institutes" />
<xed:include ref="subject.admin" />
<xed:include ref="subject.complex" />
<xed:include ref="abstract.repeated" />
<xed:include ref="comment.complex" />
<xed:include ref="related.item.search.of.all.items" />
Expand Down
Loading

0 comments on commit bfa0fb9

Please sign in to comment.