Skip to content

Commit

Permalink
Add functional tests xwikisas#16
Browse files Browse the repository at this point in the history
* added tests for instance usage section
* added comments
* updated test poms version
  • Loading branch information
ChiuchiuSorin committed Dec 4, 2024
1 parent 71ebc08 commit 14b883d
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>com.xwiki.admintools</groupId>
<artifactId>application-admintools-test</artifactId>
<version>1.0-rc-3-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
</parent>
<artifactId>application-admintools-test-docker</artifactId>
<name>Admin Tools Application - Tests - Functional Docker Tests</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package com.xwiki.admintools.test.ui;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Map;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -40,13 +41,16 @@
import org.xwiki.test.ui.po.ViewPage;

import com.xwiki.admintools.test.po.AdminToolsHomePage;
import com.xwiki.admintools.test.po.CommentsSpamModalView;
import com.xwiki.admintools.test.po.DashboardConfigurationSectionView;
import com.xwiki.admintools.test.po.DashboardFilesSectionView;
import com.xwiki.admintools.test.po.DashboardHealthSectionView;
import com.xwiki.admintools.test.po.DashboardUsageSectionView;
import com.xwiki.admintools.test.po.DownloadArchiveModalView;
import com.xwiki.admintools.test.po.EmptyPagesModalView;
import com.xwiki.admintools.test.po.FlushCacheModalView;
import com.xwiki.admintools.test.po.LastNLinesModalView;
import com.xwiki.admintools.test.po.RecycleBinsModalView;
import com.xwiki.admintools.test.po.WikisSizeModalView;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -64,6 +68,17 @@ class AdminToolsIT
private static final DocumentReference ADMINTOOLS_CONFIGURATION_REFERENCE =
new DocumentReference("xwiki", Arrays.asList("AdminTools", "Code"), "Configuration");

private static final DocumentReference ADMINTOOLS_WEBHOME_REFERENCE =
new DocumentReference("xwiki", "AdminTools", "WebHome");

private static final DocumentReference ADMINTOOLS_DELETE_PAGE_REF =
new DocumentReference("xwiki", "TestSpace", "WebHome");

private static final DocumentReference EMPTY_PAGE_REF = new DocumentReference("xwiki", "TestSpace", "emptyPage");

private static final DocumentReference EMPTY_PAGE_WITH_COMM_REF =
new DocumentReference("xwiki", "TestSpace", "emptyPageWithComm");

private static final String ADMINTOOLS_CONFIGURATION_CLASSNAME = "AdminTools.Code.ConfigurationClass";

private static final String PASSWORD = "pass";
Expand Down Expand Up @@ -199,17 +214,18 @@ void adminToolsHealthSection(TestUtils testUtils)

// Because the health check result is inserted at runtime by a velocity script, the testUtils fails to select
// the result message element. Therefore, it's necessary to select the text from the entire content.
WebElement healthCheckResult = healthSectionView.getHealthContent();
WebElement healthCheckResult = healthSectionView.getResult();
List<String> messages = List.of("Critical issues were found, please consult the results below!",
"Some issues have been found, for more details please see the results below.", "No issue found!");

boolean rightResult = messages.stream().anyMatch(healthCheckResult.getText()::contains);
boolean rightResult = messages.stream().anyMatch(healthCheckResult.getText()::equals);
assertTrue(rightResult);

WebElement logs = healthSectionView.getLogs();
assertFalse(logs.isDisplayed());
healthSectionView.clickResultsToggle();
assertTrue(logs.isDisplayed());
assertEquals(12, logs.findElements(By.className("log-item")).size());

FlushCacheModalView flushCacheModalView = healthSectionView.clickFlushCacheHyperlink();
assertTrue(flushCacheModalView.isDisplayed());
Expand All @@ -229,13 +245,61 @@ void adminToolsHealthSection(TestUtils testUtils)
@Order(7)
void adminToolsUsageSection(TestUtils testUtils)
{
setSpamCount(testUtils);
addComments(testUtils);
createEmptyPage(testUtils);
AdminToolsHomePage.gotoPage();

// Test the usage info for all wikis modal.
DashboardUsageSectionView usageSectionView = AdminToolsHomePage.getInstanceUsageSection();
WikisSizeModalView sizeModalView = usageSectionView.getWikisSizeModal();
assertTrue(sizeModalView.isDisplayed());
List<WebElement> sizeRows = sizeModalView.getTableRows();
for (WebElement row : sizeRows) {
assertFalse(row.getText().contains("null"));
}
assertEquals(2, Integer.parseInt(sizeModalView.getUserCount()));
sizeModalView.clickCancelButton();
assertFalse(sizeModalView.isDisplayed());

// Test the spammed pages for all wikis modal.
CommentsSpamModalView spamModalView = usageSectionView.getWikiSpamModal();
assertTrue(spamModalView.isDisplayed());
assertEquals("Pages with more than 2 comments", spamModalView.getTableTitle());
WebElement spamRow = spamModalView.getTableRow();
assertEquals("Home", spamRow.findElement(By.cssSelector("td:nth-child(1)")).getText());
assertEquals("$services.localization.render(\"adminTools.extension.title\")",
spamRow.findElement(By.cssSelector("td:nth-child(2)")).getText());
assertEquals("3", spamRow.findElement(By.cssSelector("td:nth-child(3)")).getText());
spamModalView.clickCancelButton();
assertFalse(spamModalView.isDisplayed());

// Test the recycle bins view for all wikis modal.
RecycleBinsModalView recycleBinsModalView = usageSectionView.getRecycleBinsModalView();
assertTrue(recycleBinsModalView.isDisplayed());
WebElement recycleBinsTableRow = recycleBinsModalView.getTableRow();
assertEquals("Home", recycleBinsTableRow.findElement(By.cssSelector("td:nth-child(1)")).getText());
assertEquals("0", recycleBinsTableRow.findElement(By.cssSelector("td:nth-child(2)")).getText());
assertEquals("0", recycleBinsTableRow.findElement(By.cssSelector("td:nth-child(3)")).getText());
createAndDeletePage(testUtils);
AdminToolsHomePage.gotoPage();
recycleBinsModalView = usageSectionView.getRecycleBinsModalView();
assertTrue(recycleBinsModalView.isDisplayed());
recycleBinsTableRow = recycleBinsModalView.getTableRow();
assertEquals("1", recycleBinsTableRow.findElement(By.cssSelector("td:nth-child(2)")).getText());
recycleBinsModalView.clickCancelButton();
assertFalse(recycleBinsModalView.isDisplayed());

// Test the empty pages view for all wikis modal.
EmptyPagesModalView emptyPagesModalView = usageSectionView.getEmptyPagesModalView();
assertTrue(emptyPagesModalView.isDisplayed());
List<WebElement> emptyPagesRows = emptyPagesModalView.getTableRows();
assertEquals(1, emptyPagesRows.size());
WebElement emptyPageRow = emptyPagesRows.get(0);
assertEquals("Home", emptyPageRow.findElement(By.cssSelector("td:nth-child(1)")).getText());
assertEquals(EMPTY_PAGE_REF.toString(), emptyPageRow.findElement(By.cssSelector("td:nth-child(2)")).getText());
emptyPagesModalView.clickCancelButton();
assertFalse(emptyPagesModalView.isDisplayed());
}

@Test
Expand Down Expand Up @@ -278,4 +342,33 @@ private void excludeContent(TestUtils testUtils, List<String> lines)
testUtils.updateObject(ADMINTOOLS_CONFIGURATION_REFERENCE, ADMINTOOLS_CONFIGURATION_CLASSNAME, 0,
"excludedLines", String.join(",", lines));
}

private void setSpamCount(TestUtils testUtils)
{
testUtils.updateObject(ADMINTOOLS_CONFIGURATION_REFERENCE, ADMINTOOLS_CONFIGURATION_CLASSNAME, 0, "spamSize",
2);
}

private void addComments(TestUtils testUtils)
{
for (int i = 1; i < 4; i++) {
Map<String, Object> parameters =
Map.of("author", USER_NAME, "date", new Date(), "comment", String.format("test_%d", i));
testUtils.addObject(ADMINTOOLS_WEBHOME_REFERENCE, "XWiki.XWikiComments", parameters);
}
}

private void createAndDeletePage(TestUtils testUtils)
{
testUtils.createPage(ADMINTOOLS_DELETE_PAGE_REF, "testContent");
testUtils.deletePage(ADMINTOOLS_DELETE_PAGE_REF);
}

private void createEmptyPage(TestUtils testUtils)
{
testUtils.createPage(EMPTY_PAGE_REF, "");
testUtils.createPage(EMPTY_PAGE_WITH_COMM_REF, "");
Map<String, Object> parameters = Map.of("author", USER_NAME, "date", new Date(), "comment", "test");
testUtils.addObject(EMPTY_PAGE_WITH_COMM_REF, "XWiki.XWikiComments", parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>com.xwiki.admintools</groupId>
<artifactId>application-admintools-test</artifactId>
<version>1.0-rc-3-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
</parent>
<artifactId>application-admintools-test-pageobjects</artifactId>
<name>Admin Tools Application - Tests - Page Objects</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 com.xwiki.admintools.test.po;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.xwiki.test.ui.po.BaseModal;

/**
* Represents actions that can be done on the spammed wikis modal.
*
* @version $Id$
*/
public class CommentsSpamModalView extends BaseModal
{
@FindBy(css = "div#pagesOverNumberOfComments")
public WebElement content;

public CommentsSpamModalView(By selector)
{
super(selector);
}

public WebElement getTableRow()
{
return content.findElement(By.cssSelector("table > tbody > tr"));
}

public String getTableTitle()
{
return content.findElement(By.id("pagesOverNumberOfCommentsLabel")).getText();
}

public void clickCancelButton()
{
content.findElement(By.cssSelector("div.modal-footer > .btn-default")).click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.xwiki.test.ui.po.ViewPage;

/**
* Represents actions that can be done on the files section from within the AdminTools.WebHome page dashboard.
* Represents actions that can be done on the files section from within the AdminTools.
*
* @version $Id$
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import org.openqa.selenium.support.FindBy;
import org.xwiki.test.ui.po.ViewPage;

/**
* Represents actions that can be done on the health section from within the AdminTools application.
*
* @version $Id$
*/
public class DashboardHealthSectionView extends ViewPage
{
@FindBy(css = "#healthCheck")
Expand All @@ -32,31 +37,41 @@ public class DashboardHealthSectionView extends ViewPage
@FindBy(css = "a[href='#confirmCacheFlushModal']")
private WebElement flushCacheModalHyperlink;

/**
* Get the health check job start button.
*/
public WebElement getHealthJobStartButton()
{
return healthContent.findElement(By.id("healthCheckJobStart"));
}

/**
* Get the health check job result.
*/
public WebElement getResult()
{
return healthContent.findElement(By.className("health-check-result-message"));
}

public WebElement getHealthContent()
{
return healthContent;
}

/**
* Toggle the results logs.
*/
public void clickResultsToggle()
{
healthContent.findElement(By.className("collapse-toggle")).click();
}

/**
* Get the health check job logs.
*/
public WebElement getLogs()
{
return healthContent.findElement(By.className("log"));
}

/**
* Open the flush cache modal.
*/
public FlushCacheModalView clickFlushCacheHyperlink()
{
flushCacheModalHyperlink.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import org.openqa.selenium.support.FindBy;
import org.xwiki.test.ui.po.ViewPage;

/**
* Represents actions that can be done on the usage section from within the AdminTools application.
*
* @version $Id$
*/
public class DashboardUsageSectionView extends ViewPage
{
@FindBy(css = ".wiki-size-section")
Expand All @@ -32,9 +37,48 @@ public class DashboardUsageSectionView extends ViewPage
@FindBy(css = "a[href='#viewWikisSizeModal']")
private WebElement wikiSizeModalHyperlink;

@FindBy(css = "a[href='#pagesOverNumberOfComments']")
private WebElement wikiSpamModalHyperLink;

@FindBy(css = "a[href='#checkRecycleBinsModal']")
private WebElement wikisRecycleBinsModalHyperLink;

@FindBy(css = "a[href='#emptyPagesData']")
private WebElement emptyPagesModalHyperLink;

/**
* Open the wikis size modal.
*/
public WikisSizeModalView getWikisSizeModal()
{
wikiSizeModalHyperlink.click();
return new WikisSizeModalView(By.id("viewWikisSizeModal"));
}

/**
* Open the wikis spam modal.
*/
public CommentsSpamModalView getWikiSpamModal()
{
wikiSpamModalHyperLink.click();
return new CommentsSpamModalView(By.id("pagesOverNumberOfComments"));
}

/**
* Open the wikis recycle bins modal.
*/
public RecycleBinsModalView getRecycleBinsModalView()
{
wikisRecycleBinsModalHyperLink.click();
return new RecycleBinsModalView(By.id("checkRecycleBinsModal"));
}

/**
* Open the wikis empty pages modal.
*/
public EmptyPagesModalView getEmptyPagesModalView()
{
emptyPagesModalHyperLink.click();
return new EmptyPagesModalView(By.id("emptyPagesData"));
}
}
Loading

0 comments on commit 14b883d

Please sign in to comment.