From bfa0fb98870e7a422c995526a946b02595c022f0 Mon Sep 17 00:00:00 2001 From: Sebastian Hofmann Date: Fri, 21 Jul 2023 17:37:40 +0200 Subject: [PATCH] MIR-1226 refinement and fixed tests --- .../it/controller/MIREditorController.java | 4 +- .../controller/MIRModsEditorController.java | 77 +++++++++++++++---- .../mir/it/tests/MIRAdminEditorITCase.java | 3 +- .../mir/it/tests/MIRAuthorEditorITCase.java | 14 +++- .../mycore/mir/editor/MIRPostProcessor.java | 9 ++- .../editor/editor-admins-includes.xed | 3 +- .../resources/editor/editor-includes.xed | 70 +++++++---------- .../resources/xsl/editor/mods2xeditor.xsl | 45 ++++++----- .../src/components/editor-wrapper.vue | 5 +- .../components/editor/cartographic-editor.vue | 12 +-- .../src/components/search/search-form.vue | 4 +- 11 files changed, 147 insertions(+), 99 deletions(-) diff --git a/mir-it/src/test/java/org/mycore/mir/it/controller/MIREditorController.java b/mir-it/src/test/java/org/mycore/mir/it/controller/MIREditorController.java index 155cda91a1..636fee3c83 100644 --- a/mir-it/src/test/java/org/mycore/mir/it/controller/MIREditorController.java +++ b/mir-it/src/test/java/org/mycore/mir/it/controller/MIREditorController.java @@ -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 { @@ -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(); } diff --git a/mir-it/src/test/java/org/mycore/mir/it/controller/MIRModsEditorController.java b/mir-it/src/test/java/org/mycore/mir/it/controller/MIRModsEditorController.java index 56e57b2e3c..44d9c7fadf 100644 --- a/mir-it/src/test/java/org/mycore/mir/it/controller/MIRModsEditorController.java +++ b/mir-it/src/test/java/org/mycore/mir/it/controller/MIRModsEditorController.java @@ -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; @@ -263,19 +262,71 @@ public void setIdentifier(List> typeIde public void setTopics(List 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 classifications) { if (classifications.size() > 0) { if (classifications.size() > 1) { @@ -292,14 +343,6 @@ public void setClassifications(List classifications) { } } - public void setGeograhicPlace(String place) { - setInputText("mods:geographic", place); - } - - public void setCoordinates(String coordinates) { - setInputText("mods:coordinates", coordinates); - } - public void setAuthors(List names) { setAuthors(names, 0); } diff --git a/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAdminEditorITCase.java b/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAdminEditorITCase.java index 58645aa912..7032c76256 100644 --- a/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAdminEditorITCase.java +++ b/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAdminEditorITCase.java @@ -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())); } diff --git a/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAuthorEditorITCase.java b/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAuthorEditorITCase.java index 4692b8b26b..6be04a9b1b 100644 --- a/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAuthorEditorITCase.java +++ b/mir-it/src/test/java/org/mycore/mir/it/tests/MIRAuthorEditorITCase.java @@ -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 { @@ -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)); @@ -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)); } diff --git a/mir-module/src/main/java/org/mycore/mir/editor/MIRPostProcessor.java b/mir-module/src/main/java/org/mycore/mir/editor/MIRPostProcessor.java index b735fd76e2..002fdc8b0a 100644 --- a/mir-module/src/main/java/org/mycore/mir/editor/MIRPostProcessor.java +++ b/mir-module/src/main/java/org/mycore/mir/editor/MIRPostProcessor.java @@ -44,11 +44,13 @@ public Document process(Document oldXML) throws IOException, JDOMException { } private static void fixSubject(Document newXML) throws JDOMException, IOException { - final XPathExpression subjectsXPath = XPathFactory.instance().compile(".//mods:subjectXML", + final XPathExpression subjectsXPath + = XPathFactory.instance().compile(".//mods:*[local-name()='subjectXML' or local-name()='subjectGEO']", Filters.element(), null, MCRConstants.MODS_NAMESPACE, MCRConstants.XLINK_NAMESPACE); final List subjectElements = new ArrayList<>(subjectsXPath.evaluate(newXML)); + List subjectsToRemove = new ArrayList<>(); for (Element subject : subjectElements) { subject.setName("subject"); subject.removeAttribute("geo"); @@ -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) { diff --git a/mir-module/src/main/resources/META-INF/resources/editor/editor-admins-includes.xed b/mir-module/src/main/resources/META-INF/resources/editor/editor-admins-includes.xed index 6b74e89a5b..5a8f1eb6f3 100644 --- a/mir-module/src/main/resources/META-INF/resources/editor/editor-admins-includes.xed +++ b/mir-module/src/main/resources/META-INF/resources/editor/editor-admins-includes.xed @@ -23,6 +23,7 @@ + @@ -34,7 +35,7 @@ - + diff --git a/mir-module/src/main/resources/META-INF/resources/editor/editor-includes.xed b/mir-module/src/main/resources/META-INF/resources/editor/editor-includes.xed index e6611a9178..a879479ff2 100644 --- a/mir-module/src/main/resources/META-INF/resources/editor/editor-includes.xed +++ b/mir-module/src/main/resources/META-INF/resources/editor/editor-includes.xed @@ -1732,7 +1732,7 @@ --> - +
+
-
- +
+
-
- +
+
-
- +
- + +
-
- +
- + +
-
- +
- + +
-
- +
- + +
- -
- - - -
- -
- -
-
- -
-
-
-
+
- +
- +
- - + +
- +
+
-
diff --git a/mir-module/src/main/resources/xsl/editor/mods2xeditor.xsl b/mir-module/src/main/resources/xsl/editor/mods2xeditor.xsl index 5f63e1ed79..3c0c12c4a5 100644 --- a/mir-module/src/main/resources/xsl/editor/mods2xeditor.xsl +++ b/mir-module/src/main/resources/xsl/editor/mods2xeditor.xsl @@ -1,11 +1,11 @@ @@ -28,20 +28,23 @@ - + - - - - true - false - - - - + + + + + + + + + + + + @@ -106,11 +109,11 @@ - - - aut - - + + + aut + + diff --git a/mir-webapp/src/main/vue/editor-tools/src/components/editor-wrapper.vue b/mir-webapp/src/main/vue/editor-tools/src/components/editor-wrapper.vue index 25d38cd071..d03e8efc87 100644 --- a/mir-webapp/src/main/vue/editor-tools/src/components/editor-wrapper.vue +++ b/mir-webapp/src/main/vue/editor-tools/src/components/editor-wrapper.vue @@ -64,7 +64,7 @@
-
@@ -175,6 +175,7 @@ const i18n = provideTranslations([ "mir.editor.subject.search.modal.title", "mir.editor.subject.search.modal.close", "mir.editor.subject.custom.modal.title", + "mir.editor.subject.custom.modal.type", "mir.editor.subject.custom.modal.type.Topic", "mir.editor.subject.custom.modal.type.Geographic", "mir.editor.subject.custom.modal.type.Institution", diff --git a/mir-webapp/src/main/vue/editor-tools/src/components/editor/cartographic-editor.vue b/mir-webapp/src/main/vue/editor-tools/src/components/editor/cartographic-editor.vue index a9bfbb3129..a2d7e113ae 100644 --- a/mir-webapp/src/main/vue/editor-tools/src/components/editor/cartographic-editor.vue +++ b/mir-webapp/src/main/vue/editor-tools/src/components/editor/cartographic-editor.vue @@ -1,13 +1,14 @@