Skip to content

Commit

Permalink
XWIKI-19041: Replace the Livetable from DocumentsMacro with a Live Da…
Browse files Browse the repository at this point in the history
…ta macro (#2775)
  • Loading branch information
manuelleduc authored Feb 2, 2024
1 parent cf7cd6c commit af6b5ab
Show file tree
Hide file tree
Showing 14 changed files with 549 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import java.io.ByteArrayInputStream;
import java.util.Arrays;

import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.xwiki.index.test.po.AllDocsLivetable;
import org.xwiki.index.test.po.AllDocsLiveData;
import org.xwiki.index.test.po.AllDocsPage;
import org.xwiki.livedata.test.po.TableLayoutElement;
import org.xwiki.model.reference.DocumentReference;
Expand Down Expand Up @@ -52,7 +53,20 @@
@UITest
class AllDocsIT
{
private static final String LOCATION_COLUMN_LABEL = "Location";

private static final String TYPE_COLUMN_LABEL = "Type";

private static final String NAME_COLUMN_LABEL = "Name";

private static final String SIZE_COLUMN_LABEL = "Size";

private static final String DATE_COLUMN_LABEL = "Date";

private static final String AUTHOR_COLUMN_LABEL = "Author";

@Test
@Order(1)
void verifyAllDocs(TestUtils setup, TestInfo testInfo, TestReference testReference)
{
// Fixture
Expand All @@ -62,7 +76,7 @@ void verifyAllDocs(TestUtils setup, TestInfo testInfo, TestReference testReferen

// tests
validateActionsAndGuest(setup);
validateFilterDoc(setup, testReference);
validateFilterDoc(testReference);
validateCopyLink(setup, testInfo, testReference);
validateRenameLink(setup, testInfo, testReference);
validateDeleteLink(setup, testReference);
Expand All @@ -75,6 +89,7 @@ void verifyAllDocs(TestUtils setup, TestInfo testInfo, TestReference testReferen
* This test is against XWiki Enterprise XE-701 https://jira.xwiki.org/browse/XE-701 (fixed in 2.5M1).
*/
@Test
@Order(2)
void attachmentsTabFilteringAndSorting(TestUtils setup, TestReference testReference) throws Exception
{
// Create 2 pages with attachments so that this test filter returns only one.
Expand All @@ -89,48 +104,48 @@ void attachmentsTabFilteringAndSorting(TestUtils setup, TestReference testRefere
TableLayoutElement liveData = docsPage.clickAttachmentsTab().getTableLayout();

// Here we test if all the Columns are displayed.
assertTrue(liveData.hasColumn("Type"), "No Type column found");
assertTrue(liveData.hasColumn("Name"), "No Name column found");
assertTrue(liveData.hasColumn("Location"), "No Location column found");
assertTrue(liveData.hasColumn("Size"), "No Size column found");
assertTrue(liveData.hasColumn("Date"), "No Date column found");
assertTrue(liveData.hasColumn("Author"), "No Author column found");
assertTrue(liveData.hasColumn(TYPE_COLUMN_LABEL), "No Type column found");
assertTrue(liveData.hasColumn(NAME_COLUMN_LABEL), "No Name column found");
assertTrue(liveData.hasColumn(LOCATION_COLUMN_LABEL), "No Location column found");
assertTrue(liveData.hasColumn(SIZE_COLUMN_LABEL), "No Size column found");
assertTrue(liveData.hasColumn(DATE_COLUMN_LABEL), "No Date column found");
assertTrue(liveData.hasColumn(AUTHOR_COLUMN_LABEL), "No Author column found");

String defaultLocationFilter = className + ".";

liveData.filterColumn("Location", defaultLocationFilter);
liveData.filterColumn(LOCATION_COLUMN_LABEL, defaultLocationFilter);

assertEquals(2, liveData.countRows());

// Filter by attachment file name.
liveData.filterColumn("Name", "t1");
liveData.filterColumn(NAME_COLUMN_LABEL, "t1");
assertEquals(1, liveData.countRows());
assertEquals("attachment1.txt", liveData.getCell("Name", 1).getText());
assertEquals("attachment1.txt", liveData.getCell(NAME_COLUMN_LABEL, 1).getText());

// Clear the filter.
liveData.filterColumn("Name", "");
liveData.filterColumn(NAME_COLUMN_LABEL, "");

// Filter by attachment location.
liveData.filterColumn("Location", defaultLocationFilter + "Oth");
liveData.filterColumn(LOCATION_COLUMN_LABEL, defaultLocationFilter + "Oth");
assertEquals(1, liveData.countRows());
assertEquals(className + "OtherPage", liveData.getCell("Location", 1).getText());
assertEquals(className + "OtherPage", liveData.getCell(LOCATION_COLUMN_LABEL, 1).getText());

// Reset the filter.
liveData.filterColumn("Location", defaultLocationFilter);
liveData.filterColumn(LOCATION_COLUMN_LABEL, defaultLocationFilter);

// Sort by attachment file name. The live table should be already sorted by file name ascending. This will
// reverse the order.
assertEquals("attachment2.txt", liveData.getCell("Name", 2).getText());
liveData.sortBy("Name");
assertEquals("attachment2.txt", liveData.getCell(NAME_COLUMN_LABEL, 2).getText());
liveData.sortBy(NAME_COLUMN_LABEL);
assertEquals(2, liveData.countRows());
assertEquals("attachment2.txt", liveData.getCell("Name", 1).getText());
assertEquals("attachment2.txt", liveData.getCell(NAME_COLUMN_LABEL, 1).getText());

// Sort by attachment location.
liveData.sortBy("Location");
assertEquals(className + "Page", liveData.getCell("Location", 2).getText());
liveData.sortBy("Location");
liveData.sortBy(LOCATION_COLUMN_LABEL);
assertEquals(className + "Page", liveData.getCell(LOCATION_COLUMN_LABEL, 2).getText());
liveData.sortBy(LOCATION_COLUMN_LABEL);
assertEquals(2, liveData.countRows());
assertEquals(className + "Page", liveData.getCell("Location", 1).getText());
assertEquals(className + "Page", liveData.getCell(LOCATION_COLUMN_LABEL, 1).getText());
}

/**
Expand All @@ -141,35 +156,36 @@ private void validateActionsAndGuest(TestUtils setup)
// Create a test user
setup.createUserAndLogin("Foobar", "password");
AllDocsPage page = AllDocsPage.gotoPage();
AllDocsLivetable livetable = page.clickIndexTab();
assertTrue(livetable.hasColumn("Actions"), "No Actions column found");
AllDocsLiveData livetable = page.clickIndexTab();
assertTrue(livetable.getTableLayout().hasColumn("Actions"), "No Actions column found");

// Logs out to be guest to verify that the Action columns is no longer displayed
setup.forceGuestUser();

page = AllDocsPage.gotoPage();
livetable = page.clickIndexTab();
assertFalse(livetable.hasColumn("Actions"), "Actions column shouldn't be visible for guests");
assertFalse(livetable.getTableLayout().hasColumn("Actions"), "Actions column shouldn't be visible for guests");

setup.loginAsSuperAdmin();
}

/**
* Verify filtering works by filtering on the document name
*/
private void validateFilterDoc(TestUtils setup, TestReference testReference)
private void validateFilterDoc(TestReference testReference)
{
String testName = testReference.getLastSpaceReference().getName();
AllDocsPage page = AllDocsPage.gotoPage();
AllDocsLivetable livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
AllDocsLiveData livetable = page.clickIndexTab();
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
// We get one result for the page we've created
assertEquals(1, livetable.getRowCount());
assertTrue(livetable.hasRow("Title", testName));
TableLayoutElement tableLayout = livetable.getTableLayout();
assertEquals(1, tableLayout.countRows());
tableLayout.assertRow("Title", testName);

// We get no result for a page created by user barbaz
livetable.filterColumn(4, "barbaz");
assertEquals(0, livetable.getRowCount());
livetable.filterColumn("Last Author", "barbaz");
assertEquals(0, tableLayout.countRows());
}

/**
Expand All @@ -185,11 +201,12 @@ private void validateCopyLink(TestUtils setup, TestInfo testInfo, TestReference
setup.deletePage(copyPageReference);

AllDocsPage page = AllDocsPage.gotoPage();
AllDocsLivetable livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
AllDocsLiveData livetable = page.clickIndexTab();
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
// We get one result for the page we've created
assertEquals(1, livetable.getRowCount());
assertTrue(livetable.hasRow("Title", testName));
TableLayoutElement tableLayout = livetable.getTableLayout();
assertEquals(1, tableLayout.countRows());
tableLayout.assertRow("Title", testName);

// click on the copy action link.
livetable.clickAction(1, "copy");
Expand All @@ -202,10 +219,11 @@ private void validateCopyLink(TestUtils setup, TestInfo testInfo, TestReference

page = AllDocsPage.gotoPage();
livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
assertEquals(2, livetable.getRowCount());
livetable.filterColumn(2, copyPageName);
assertEquals(1, livetable.getRowCount());
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
tableLayout = livetable.getTableLayout();
assertEquals(2, tableLayout.countRows());
livetable.filterColumn(LOCATION_COLUMN_LABEL, copyPageName);
assertEquals(1, tableLayout.countRows());

setup.deletePage(copyPageReference);
}
Expand All @@ -219,11 +237,12 @@ private void validateRenameLink(TestUtils setup, TestInfo testInfo, TestReferenc
Arrays.asList(testSpace, renamedPageName), "WebHome");

AllDocsPage page = AllDocsPage.gotoPage();
AllDocsLivetable livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
AllDocsLiveData livetable = page.clickIndexTab();
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
// We get one result for the page we've created
assertEquals(1, livetable.getRowCount());
assertTrue(livetable.hasRow("Title", testName));
TableLayoutElement tableLayout = livetable.getTableLayout();
assertEquals(1, tableLayout.countRows());
tableLayout.assertRow("Title", testName);

// click on the copy action link.
livetable.clickAction(1, "rename");
Expand All @@ -236,9 +255,10 @@ private void validateRenameLink(TestUtils setup, TestInfo testInfo, TestReferenc

page = AllDocsPage.gotoPage();
livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
assertEquals(1, livetable.getRowCount());
assertEquals(testSpace + renamedPageName, livetable.getCell(1, 2).getText());
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
tableLayout = livetable.getTableLayout();
assertEquals(1, tableLayout.countRows());
assertEquals(testSpace + renamedPageName, tableLayout.getCell(LOCATION_COLUMN_LABEL, 1).getText());

setup.deletePage(renamedPageReference);
setup.createPage(testReference, "", testReference.getLastSpaceReference().getName());
Expand All @@ -249,11 +269,12 @@ private void validateDeleteLink(TestUtils setup, TestReference testReference)
String testName = testReference.getLastSpaceReference().getName();

AllDocsPage page = AllDocsPage.gotoPage();
AllDocsLivetable livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
AllDocsLiveData livetable = page.clickIndexTab();
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
// We get one result for the page we've created
assertEquals(1, livetable.getRowCount());
assertTrue(livetable.hasRow("Title", testName));
TableLayoutElement tableLayout = livetable.getTableLayout();
assertEquals(1, tableLayout.countRows());
tableLayout.assertRow("Title", testName);

// click on the copy action link.
livetable.clickAction(1, "delete");
Expand All @@ -262,8 +283,8 @@ private void validateDeleteLink(TestUtils setup, TestReference testReference)
deletingPage.waitUntilFinished();
page = AllDocsPage.gotoPage();
livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
assertEquals(0, livetable.getRowCount());
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
assertEquals(0, livetable.getTableLayout().countRows());
setup.createPage(testReference, "", testReference.getLastSpaceReference().getName());
}

Expand All @@ -272,11 +293,12 @@ private void validateRightLink(TestUtils setup, TestReference testReference)
String testName = testReference.getLastSpaceReference().getName();

AllDocsPage page = AllDocsPage.gotoPage();
AllDocsLivetable livetable = page.clickIndexTab();
livetable.filterColumn(2, testName);
AllDocsLiveData livetable = page.clickIndexTab();
livetable.filterColumn(LOCATION_COLUMN_LABEL, testName);
// We get one result for the page we've created
assertEquals(1, livetable.getRowCount());
assertTrue(livetable.hasRow("Title", testName));
TableLayoutElement tableLayout = livetable.getTableLayout();
assertEquals(1, tableLayout.countRows());
tableLayout.assertRow("Title", testName);

// click on the copy action link.
livetable.clickAction(1, "rights");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ class NestedDeletedAttachmentsIT extends DeletedAttachmentsIT
class NestedOrphanedPagesIT extends OrphanedPagesIT
{
}

@Nested
@DisplayName("Documents Macro UI")
class NestedDocumentsMacroIT extends DocumentsMacroIT
{
}

@Nested
@DisplayName("Spaces UI")
class NestedSpacesIT extends SpacesIT
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.index.test.ui.docker;

import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.xwiki.index.test.po.DocumentsMacroPage;
import org.xwiki.livedata.test.po.TableLayoutElement;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.SpaceReference;
import org.xwiki.test.docker.junit5.TestReference;
import org.xwiki.test.docker.junit5.UITest;
import org.xwiki.test.ui.TestUtils;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests for the DocumentsMacro page.
*
* @version $Id$
* @since 4.2M3
*/
@UITest
class DocumentsMacroIT
{
/**
* Verify that the {@code {{documents/}}} macro works by going to the page defining this wiki macro since it
* contains an example usage and we can verify it displays the expected result.
*/
@Test
@Order(1)
void documentsMacro(TestUtils setup, TestReference testReference)
{
// Create a dummy page in the Main space and having Main.WebHome as its parent so that it appears in the
// Documents Macro livetable (since the example lists pages in the Main space having Main.WebHome as their
// parent).
String testMethodName = testReference.getLastSpaceReference().getName();
DocumentReference documentReference = new DocumentReference(testMethodName,
new SpaceReference("Main", testReference.getWikiReference()));
setup.createPage(documentReference, "", "Test Title", "xwiki/2.1", "Main.WebHome");

DocumentsMacroPage dmp = DocumentsMacroPage.gotoPage();
TableLayoutElement tableLayout = dmp.getDocumentsExampleLiveTable().getTableLayout();

// Verify that we have a Page column
assertTrue(tableLayout.hasColumn("Title"), "No Title column found");

// Verify there are several rows displayed
assertTrue(tableLayout.countRows() > 0);

// Verify that page titles are displayed by filtering on one page for which we know the title
tableLayout.filterColumn("Location", testMethodName);
tableLayout.assertRow("Title", "Test Title");
}
}
Loading

0 comments on commit af6b5ab

Please sign in to comment.