From effff8204ef2888bd4827814173492d95401a533 Mon Sep 17 00:00:00 2001 From: Manuel Leduc Date: Thu, 7 Nov 2024 16:36:19 +0100 Subject: [PATCH] XWIKI-22409: Add automated test for "Show Page Information Tab (No)" --- .../test/ui/AdministrationIT.java | 25 ++++++ .../po/PresentationAdministrationPage.java | 85 +++++++++++++++++++ .../org/xwiki/test/ui/po/InformationPane.java | 24 ++++++ 3 files changed, 134 insertions(+) create mode 100644 xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/PresentationAdministrationPage.java diff --git a/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-docker/src/test/it/org/xwiki/administration/test/ui/AdministrationIT.java b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-docker/src/test/it/org/xwiki/administration/test/ui/AdministrationIT.java index 2679f8611c20..aa7fe758faf8 100644 --- a/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-docker/src/test/it/org/xwiki/administration/test/ui/AdministrationIT.java +++ b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-docker/src/test/it/org/xwiki/administration/test/ui/AdministrationIT.java @@ -24,9 +24,11 @@ import org.junit.jupiter.api.Test; import org.xwiki.administration.test.po.AdministrablePage; import org.xwiki.administration.test.po.AdministrationPage; +import org.xwiki.administration.test.po.PresentationAdministrationPage; import org.xwiki.test.docker.junit5.TestReference; import org.xwiki.test.docker.junit5.UITest; import org.xwiki.test.ui.TestUtils; +import org.xwiki.test.ui.po.InformationPane; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -91,4 +93,27 @@ void verifyAdministrationSections(TestUtils setup, TestReference testReference) .stream().forEach(sectionId -> assertTrue(pageAdministrationPage.hasNotSection(sectionId), String.format("Menu section [%s] shouldn't be present.", sectionId))); } + + /** + * Validate that the show information setting of the Presentation section of the administration has an effect. + * + * @since 15.10.14 + * @since 16.4.6 + * @since 16.10.0RC1 + */ + @Test + void showPageInformationTabSettings(TestUtils setup, TestReference testReference) + { + setup.loginAsSuperAdmin(); + setup.createPage(testReference, ""); + // Check that the information tab is displayed by default. + assertTrue(new InformationPane().exists()); + PresentationAdministrationPage adminPage = PresentationAdministrationPage.goToAdminSection(); + adminPage.setShowInformation("No"); + adminPage.save(); + assertEquals("No", adminPage.getShowInformation()); + + setup.gotoPage(testReference); + assertTrue(new InformationPane().doesNotExist()); + } } diff --git a/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/PresentationAdministrationPage.java b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/PresentationAdministrationPage.java new file mode 100644 index 000000000000..8c95b5546445 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/PresentationAdministrationPage.java @@ -0,0 +1,85 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.administration.test.po; + +import java.util.HashMap; +import java.util.Map; + +import org.openqa.selenium.By; +import org.xwiki.model.reference.DocumentReference; +import org.xwiki.test.ui.po.Select; +import org.xwiki.test.ui.po.ViewPage; + +/** + * Page object for the Presentation section of the administration. + * + * @version $Id$ + * @since 15.10.14 + * @since 16.4.6 + * @since 16.10.0RC1 + */ +public class PresentationAdministrationPage extends ViewPage +{ + /** + * Go to the Presentation section of the administration. + * + * @return a {@link PresentationAdministrationPage} instance + */ + public static PresentationAdministrationPage goToAdminSection() + { + Map queryParameters = new HashMap<>(); + queryParameters.put("editor", "globaladmin"); + queryParameters.put("section", "Presentation"); + DocumentReference reference = new DocumentReference("xwiki", "XWiki", "XWikiPreferences"); + getUtil().gotoPage(reference, "admin", queryParameters); + return new PresentationAdministrationPage(); + } + + /** + * Set the value of the show information field. + * + * @param value {@code No}, {@code Yes} or {@code ---} + */ + public void setShowInformation(String value) + { + getShowInformationSelect().selectByVisibleText(value); + } + + /** + * Save the administration page. + */ + public void save() + { + getDriver().findElement(By.cssSelector("#presentation input[value='Save']")).click(); + } + + /** + * @return the text of the currently selected show information option + */ + public String getShowInformation() + { + return getShowInformationSelect().getFirstSelectedOption().getText(); + } + + private Select getShowInformationSelect() + { + return new Select(getDriver().findElement(By.id("XWiki.XWikiPreferences_0_showinformation"))); + } +} diff --git a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/InformationPane.java b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/InformationPane.java index 544bb4e4d525..c8fd7d02c15c 100644 --- a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/InformationPane.java +++ b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/InformationPane.java @@ -36,6 +36,8 @@ public class InformationPane extends BaseElement { private static final By ORIGINAL_LOCALE_SELECTOR = By.cssSelector("dd[data-key='originalLocale']"); + private static final String INFORMATION_TAB_ID = "Informationtab"; + @FindBy(id = "informationcontent") private WebElement pane; @@ -131,4 +133,26 @@ public DocumentSyntaxPropertyPane editSyntax() { return new DocumentSyntaxPropertyPane().clickEdit(); } + + /** + * @return {@code true} if the information tab is found, {@code false} otherwise + * @since 15.10.14 + * @since 16.4.6 + * @since 16.10.0RC1 + */ + public boolean exists() + { + return getDriver().findElements(By.id(INFORMATION_TAB_ID)).size() == 1; + } + + /** + * @return {@code true} if the information tab is not found, {@code false} otherwise + * @since 15.10.14 + * @since 16.4.6 + * @since 16.10.0RC1 + */ + public boolean doesNotExist() + { + return getDriver().findElements(By.id(INFORMATION_TAB_ID)).isEmpty(); + } }