Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bot] Merge 23.7 to 23.8 #1593

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.labkey.test.components.list;

import org.jetbrains.annotations.Nullable;
import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.bootstrap.ModalDialog;
import org.labkey.test.components.html.Checkbox;
import org.labkey.test.components.react.ReactSelect;
import org.labkey.test.components.html.Input;
import org.labkey.test.components.html.RadioButton;
import org.labkey.test.components.react.ReactSelect;
import org.labkey.test.pages.list.EditListDefinitionPage;
import org.openqa.selenium.WebElement;

Expand Down Expand Up @@ -47,6 +48,13 @@ public AdvancedListSettingsDialog allowMultipleDiscussionsPerItem()
public AdvancedListSettingsDialog indexEntireListAsASingleDocument(boolean checked, String docTitle,
SearchIncludeOptions includeOptions,
SearchIndexOptions indexOptions)
{
return indexEntireListAsASingleDocument(checked, docTitle, includeOptions, indexOptions, null);
}

public AdvancedListSettingsDialog indexEntireListAsASingleDocument(boolean checked, String docTitle,
SearchIncludeOptions includeOptions,
SearchIndexOptions indexOptions, @Nullable String customTemplate)
{
String labelText = "Index entire list as a single document";
new Checkbox(this, labelText).set(checked);
Expand All @@ -59,13 +67,41 @@ public AdvancedListSettingsDialog indexEntireListAsASingleDocument(boolean check
Input.Input(Locator.id("entireListTitleTemplate"), getDriver()).find().set(docTitle);
elementCache().radio(includeOptions.toString()).check();
elementCache().radio(indexOptions.toString()).check();
if (indexOptions.equals(SearchIndexOptions.CustomTemplate))
Input.Input(Locator.id("entireListBodyTemplate"), getDriver()).find().set(customTemplate);
}
return this;
}

public boolean isSearchIncludeSelected(String mainLabel, SearchIncludeOptions searchInclude)
{
if (new Checkbox(this, mainLabel).isSelected())
{
WebElement expandCollapsePane = elementCache().collapsibleField(mainLabel);
expandPane(expandCollapsePane);
if (elementCache().radio(searchInclude.toString()).isSelected())
return true;
}

return false;
}

public boolean isSearchIndexSelected(String mainLabel, SearchIndexOptions searchIndex)
{
if (new Checkbox(this, mainLabel).isSelected())
{
WebElement expandCollapsePane = elementCache().collapsibleField(mainLabel);
expandPane(expandCollapsePane);
if (elementCache().radio(searchIndex.toString()).isSelected())
return true;
}

return false;
}

public AdvancedListSettingsDialog disableEntireListIndex()
{
return indexEntireListAsASingleDocument(false, null, null, null);
return indexEntireListAsASingleDocument(false, null, null, null, null);
}

public AdvancedListSettingsDialog indexEachItemAsASeparateDocument(boolean checked, String docTitle, SearchIndexOptions indexOptions)
Expand Down Expand Up @@ -94,8 +130,8 @@ private void expandPane(WebElement expandCollapsePane)
{
if (!isPaneExpanded(expandCollapsePane))
{
expandCollapsePane.click();
WebDriverWrapper.waitFor(()-> isPaneExpanded(expandCollapsePane),
elementCache().expandCarat().findElement(expandCollapsePane).click();
WebDriverWrapper.waitFor(() -> isPaneExpanded(expandCollapsePane),
"the pane did not expand in time", 1000);
}
}
Expand Down Expand Up @@ -132,7 +168,7 @@ protected ElementCache newElementCache()
@Override
protected ElementCache elementCache()
{
return (ElementCache) super.elementCache();
return (ElementCache) super.elementCache();
}

protected class ElementCache extends ModalDialog.ElementCache
Expand All @@ -141,16 +177,23 @@ Locator.XPathLocator checkBoxLoc(String labelText)
{
return Locator.tagWithText("label", labelText);
}

Locator.XPathLocator collapsibleFieldLoc(String checkboxLabelText)
{
return Locator.tagWithClass("div", "list__advanced-settings-modal__collapsible-field")
.withDescendant(checkBoxLoc(checkboxLabelText));
}

Locator.XPathLocator collapsibleFieldContainer(String checkboxLabelText)
{
return Locator.tag("div").withChild(checkBoxLoc(checkboxLabelText));
}

Locator.XPathLocator expandCarat()
{
return Locator.tagWithClassContaining("span", "fa-lg"); //Matches both angle right or angle down
}

RadioButton radio(String labelText)
{
Locator loc = Locator.tagWithClass("div", "radio")
Expand All @@ -167,7 +210,7 @@ WebElement collapsibleField(String checkboxLabelText)

public enum SearchIncludeOptions
{
MetadataAndData("Include both metadata and data" ),
MetadataAndData("Include both metadata and data"),
DataOnly("Include data only"),
MetadataOnly("Include metadata only (name and description of list and fields)");

Expand Down
196 changes: 196 additions & 0 deletions src/org/labkey/test/tests/list/ListIndexingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package org.labkey.test.tests.list;

import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.TestFileUtils;
import org.labkey.test.categories.Daily;
import org.labkey.test.components.list.AdvancedListSettingsDialog;
import org.labkey.test.pages.list.EditListDefinitionPage;
import org.labkey.test.pages.search.SearchResultsPage;
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.util.ListHelper;
import org.labkey.test.util.PortalHelper;
import org.labkey.test.util.SearchHelper;
import org.labkey.test.util.search.SearchResultsQueue;
import org.openqa.selenium.WebElement;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Category({Daily.class})
@BaseWebDriverTest.ClassTimeout(minutes = 5)
public class ListIndexingTest extends BaseWebDriverTest
{
private final ListHelper _listHelper = new ListHelper(this);
private static final String listName = "NIMHDemographics";

private final SearchHelper _searchHelper = new SearchHelper(this, new SearchResultsQueue()).setMaxTries(6);

@Override
protected @Nullable String getProjectName()
{
return getClass().getSimpleName() + " Project";
}

@Override
public List<String> getAssociatedModules()
{
return Arrays.asList("list");
}

@BeforeClass
public static void setupProject()
{
ListIndexingTest init = (ListIndexingTest) getCurrentTest();
init.doSetup();
}

/*
Regression test cases for Issue 48056: More list indexing fixes
*/
private void doSetup()
{
log("Setup project and list module");
_containerHelper.createProject(getProjectName(), null);
_listHelper.importListArchive(getProjectName(), TestFileUtils.getSampleData("lists/ListDemo.lists.zip"));

goToProjectHome();
new PortalHelper(this).addWebPart("Search");
}

@Test
public void testEachItemIndexing()
{
goToProjectHome();
EditListDefinitionPage editListDefinitionPage = _listHelper.goToEditDesign("NIMHSlides");
editListDefinitionPage.openAdvancedListSettings()
.indexEachItemAsASeparateDocument(true, "Subject Id: ${SubjectId}", AdvancedListSettingsDialog.SearchIndexOptions.NonPhiFields)
.clickApply()
.clickSave();

SearchResultsPage resultsPage = _searchHelper.searchFor("10001");
Assert.assertEquals("Incorrect number of search result", Integer.valueOf(8), resultsPage.getResultCount());
List<WebElement> res = resultsPage.getResults();
for (WebElement row : res)
Assert.assertTrue("Custom title is not applied in results", row.getText().startsWith("Subject Id: 10001"));
}

@Test
public void testEntireListIndexing()
{
/*
Test coverage for :
Issue 48188: Selecting 'All non-PHI' or 'Custom template' under 'Index each item as a separate document' doesn't stick
*/
goToProjectHome();
EditListDefinitionPage editDesign = _listHelper.goToEditDesign(listName);
editDesign.openAdvancedListSettings()
.indexEntireListAsASingleDocument(true, "",
AdvancedListSettingsDialog.SearchIncludeOptions.MetadataAndData,
AdvancedListSettingsDialog.SearchIndexOptions.CustomTemplate, "${Name}")
.clickApply()
.clickSave();

editDesign = _listHelper.goToEditDesign(listName);
AdvancedListSettingsDialog settingsDialog = editDesign.openAdvancedListSettings();
Assert.assertTrue("Search index options did not save",
settingsDialog.isSearchIndexSelected("Index entire list as a single document",
AdvancedListSettingsDialog.SearchIndexOptions.CustomTemplate));

Assert.assertTrue("Search include option did not save",
settingsDialog.isSearchIncludeSelected("Index entire list as a single document",
AdvancedListSettingsDialog.SearchIncludeOptions.MetadataAndData));
settingsDialog.clickCancel();
editDesign.clickCancel();

log("Verifying search result based on advanced settings(Custom template and metadata+data");
searchFor(getProjectName(), "Justin", 1, "List " + listName);
searchFor(getProjectName(), "Child", 0, null);

_listHelper.goToEditDesign(listName)
.openAdvancedListSettings()
.disableEntireListIndex()
.clickApply()
.clickSave();

/*
Test coverage for : Issue 48182: Custom titles on list search results aren't working
*/

String customTitle = "Custom title for " + listName;
editDesign = _listHelper.goToEditDesign(listName);
editDesign.openAdvancedListSettings()
.indexEntireListAsASingleDocument(true, customTitle,
AdvancedListSettingsDialog.SearchIncludeOptions.DataOnly,
AdvancedListSettingsDialog.SearchIndexOptions.NonPhiFields, null)
.clickApply()
.clickSave();

editDesign = _listHelper.goToEditDesign("NIMHSamples");
editDesign.openAdvancedListSettings()
.indexEntireListAsASingleDocument(true, "",
AdvancedListSettingsDialog.SearchIncludeOptions.MetadataAndData,
AdvancedListSettingsDialog.SearchIndexOptions.NonPhiFields, null)
.clickApply()
.clickSave();

log("Verifying search result based on advanced settings(Document title, dataOnly and non phi text fields");
searchFor(getProjectName(), customTitle, 1, null);
searchFor(getProjectName(), "Occupation", 0, null);
searchFor(getProjectName(), "10001", 2, null);

_listHelper.goToEditDesign(listName)
.openAdvancedListSettings()
.disableEntireListIndex()
.clickApply()
.clickSave();

_listHelper.goToEditDesign("NIMHSamples")
.openAdvancedListSettings()
.disableEntireListIndex()
.clickApply()
.clickSave();

editDesign = _listHelper.goToEditDesign(listName);
editDesign.openAdvancedListSettings()
.indexEntireListAsASingleDocument(true, "",
AdvancedListSettingsDialog.SearchIncludeOptions.MetadataOnly,
AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText, null)
.clickApply()
.clickSave();

log("Verifying search result based on advanced settings(Metadata only and non phi fields)");
goToProjectHome();
searchFor(getProjectName(), "Justin", 0, null);
searchFor(getProjectName(), "Occupation", 1, "List " + listName);
}

@Test
public void testAttachmentIndexing()
{
String attachmentList = "List with Attachment";
File attachmentFile = TestFileUtils.getSampleData("fileTypes/pdf_sample.pdf");
_listHelper.createList(getProjectName(), attachmentList, ListHelper.ListColumnType.AutoInteger, "id",
new FieldDefinition("Name", FieldDefinition.ColumnType.String),
new FieldDefinition("File", FieldDefinition.ColumnType.Attachment));
_listHelper.beginAtList(getProjectName(), attachmentList);
_listHelper.insertNewRow(Map.of("Name", "pdf file",
"File", attachmentFile.getAbsolutePath()), false);

searchFor(getProjectName(), attachmentFile.getName(), 0, null);

EditListDefinitionPage editListDefinitionPage = _listHelper.goToEditDesign(attachmentList);
editListDefinitionPage.openAdvancedListSettings()
.setIndexFileAttachments(true)
.clickApply()
.clickSave();

searchFor(getProjectName(), attachmentFile.getName(), 1, null);
}
}
2 changes: 1 addition & 1 deletion src/org/labkey/test/tests/list/ListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ public void testAttachmentSearch()
.openAdvancedListSettings()
.indexEntireListAsASingleDocument(true, "",
AdvancedListSettingsDialog.SearchIncludeOptions.MetadataAndData,
AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText)
AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText, null)
.setIndexFileAttachments(true)
.clickApply()
.clickSave();
Expand Down