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

Docker tests.
  • Loading branch information
manuelleduc committed Jan 17, 2024
1 parent fb848a1 commit d7ce05d
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 282 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
{
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ public static String getURL()
return getUtil().getURL("Main", "AllDocs");
}

public AllDocsLivetable clickIndexTab()
/**
* Click on the index tab.
*
* @return the Live Data listing all the documents
*/
public AllDocsLiveData clickIndexTab()
{
this.indexTab.click();

AllDocsLivetable lt = new AllDocsLivetable();
lt.waitUntilReady();

return lt;
return new AllDocsLiveData();
}

public DocumentTreeElement clickTreeTab()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package org.xwiki.index.test.po;

import org.xwiki.test.ui.po.LiveTableElement;
import org.xwiki.livedata.test.po.LiveDataElement;
import org.xwiki.test.ui.po.ViewPage;

/**
Expand All @@ -36,10 +36,8 @@ public static DocumentsMacroPage gotoPage()
return new DocumentsMacroPage();
}

public LiveTableElement getDocumentsExampleLiveTable()
public LiveDataElement getDocumentsExampleLiveTable()
{
LiveTableElement lt = new LiveTableElement("example");
lt.waitUntilReady();
return lt;
return new LiveDataElement("example");
}
}
Loading

0 comments on commit d7ce05d

Please sign in to comment.