From 302abd2183108229bfa0cbda88e2f0f2d60f4121 Mon Sep 17 00:00:00 2001 From: labkey-sweta Date: Thu, 13 Jul 2023 02:06:39 -0700 Subject: [PATCH 1/4] Automation test for Issue 48056: More list indexing fixes --- .../list/AdvancedListSettingsDialog.java | 7 +- .../test/tests/list/ListIndexingTest.java | 173 ++++++++++++++++++ src/org/labkey/test/tests/list/ListTest.java | 2 +- 3 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 src/org/labkey/test/tests/list/ListIndexingTest.java diff --git a/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java b/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java index 0e95f5f242..5a9de0ec60 100644 --- a/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java +++ b/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java @@ -1,5 +1,6 @@ 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; @@ -46,7 +47,7 @@ public AdvancedListSettingsDialog allowMultipleDiscussionsPerItem() public AdvancedListSettingsDialog indexEntireListAsASingleDocument(boolean checked, String docTitle, SearchIncludeOptions includeOptions, - SearchIndexOptions indexOptions) + SearchIndexOptions indexOptions, @Nullable String customTemplate) { String labelText = "Index entire list as a single document"; new Checkbox(this, labelText).set(checked); @@ -59,13 +60,15 @@ 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 AdvancedListSettingsDialog disableEntireListIndex() { - return indexEntireListAsASingleDocument(false, null, null, null); + return indexEntireListAsASingleDocument(false, null, null, null, null); } public AdvancedListSettingsDialog indexEachItemAsASeparateDocument(boolean checked, String docTitle, SearchIndexOptions indexOptions) diff --git a/src/org/labkey/test/tests/list/ListIndexingTest.java b/src/org/labkey/test/tests/list/ListIndexingTest.java new file mode 100644 index 0000000000..c5fe719c71 --- /dev/null +++ b/src/org/labkey/test/tests/list/ListIndexingTest.java @@ -0,0 +1,173 @@ +package org.labkey.test.tests.list; + +import org.jetbrains.annotations.Nullable; +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.CustomizeView; +import org.labkey.test.components.list.AdvancedListSettingsDialog; +import org.labkey.test.pages.list.EditListDefinitionPage; +import org.labkey.test.params.FieldDefinition; +import org.labkey.test.util.DataRegionTable; +import org.labkey.test.util.ListHelper; +import org.labkey.test.util.PortalHelper; + +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"; + + @Override + protected @Nullable String getProjectName() + { + return getClass().getSimpleName() + " Project"; + } + + @Override + public List getAssociatedModules() + { + return Arrays.asList("list"); + } + + @BeforeClass + public static void setupProject() + { + ListIndexingTest init = (ListIndexingTest) getCurrentTest(); + init.doSetup(); + } + + 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"); + + log("Adding LastIndexed column"); + _listHelper.goToList(listName); + DataRegionTable listTable = new DataRegionTable.DataRegionFinder(getDriver()).withName("query").waitFor(); + CustomizeView customizeView = listTable.openCustomizeGrid(); + customizeView.showHiddenItems(); + customizeView.addColumn("LastIndexed"); + customizeView.saveCustomView(); + } + + @Test + public void testEachItemIndexing() + { + EditListDefinitionPage editListDefinitionPage = _listHelper.goToEditDesign("NIMHSlides"); + editListDefinitionPage.openAdvancedListSettings() + .indexEachItemAsASeparateDocument(true, "${SubjectId}", AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText) + .clickApply() + .clickSave(); + + searchFor(getProjectName(), "10001", 8, null); + } + + @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(); + + 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.NonPhiText, null) + .clickApply() + .clickSave(); + + editDesign = _listHelper.goToEditDesign("NIMHSamples"); + editDesign.openAdvancedListSettings() + .indexEntireListAsASingleDocument(true, "", + AdvancedListSettingsDialog.SearchIncludeOptions.MetadataAndData, + AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText, 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(), "Justin", 2, null); + searchFor(getProjectName(), "Occupation", 0, null); + + _listHelper.goToEditDesign(listName) + .openAdvancedListSettings() + .disableEntireListIndex() + .clickApply() + .clickSave(); + + editDesign = _listHelper.goToEditDesign(listName); + editDesign.openAdvancedListSettings() + .indexEntireListAsASingleDocument(true, "", + AdvancedListSettingsDialog.SearchIncludeOptions.MetadataOnly, + AdvancedListSettingsDialog.SearchIndexOptions.NonPhiFields, 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); + } +} diff --git a/src/org/labkey/test/tests/list/ListTest.java b/src/org/labkey/test/tests/list/ListTest.java index 8fb8198b11..dc9a3f8feb 100644 --- a/src/org/labkey/test/tests/list/ListTest.java +++ b/src/org/labkey/test/tests/list/ListTest.java @@ -1232,7 +1232,7 @@ public void testAttachmentSearch() .openAdvancedListSettings() .indexEntireListAsASingleDocument(true, "", AdvancedListSettingsDialog.SearchIncludeOptions.MetadataAndData, - AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText) + AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText, null) .setIndexFileAttachments(true) .clickApply() .clickSave(); From f750c2f563ad7f27eaa88cae0d9e7976752f2f95 Mon Sep 17 00:00:00 2001 From: labkey-sweta Date: Thu, 13 Jul 2023 13:35:16 -0700 Subject: [PATCH 2/4] Test updates --- .../test/tests/list/ListIndexingTest.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/org/labkey/test/tests/list/ListIndexingTest.java b/src/org/labkey/test/tests/list/ListIndexingTest.java index c5fe719c71..69ae92b2a6 100644 --- a/src/org/labkey/test/tests/list/ListIndexingTest.java +++ b/src/org/labkey/test/tests/list/ListIndexingTest.java @@ -7,11 +7,9 @@ import org.labkey.test.BaseWebDriverTest; import org.labkey.test.TestFileUtils; import org.labkey.test.categories.Daily; -import org.labkey.test.components.CustomizeView; import org.labkey.test.components.list.AdvancedListSettingsDialog; import org.labkey.test.pages.list.EditListDefinitionPage; import org.labkey.test.params.FieldDefinition; -import org.labkey.test.util.DataRegionTable; import org.labkey.test.util.ListHelper; import org.labkey.test.util.PortalHelper; @@ -46,6 +44,9 @@ public static void setupProject() init.doSetup(); } + /* + Regression test cases for Issue 48056: More list indexing fixes + */ private void doSetup() { log("Setup project and list module"); @@ -54,22 +55,15 @@ private void doSetup() goToProjectHome(); new PortalHelper(this).addWebPart("Search"); - - log("Adding LastIndexed column"); - _listHelper.goToList(listName); - DataRegionTable listTable = new DataRegionTable.DataRegionFinder(getDriver()).withName("query").waitFor(); - CustomizeView customizeView = listTable.openCustomizeGrid(); - customizeView.showHiddenItems(); - customizeView.addColumn("LastIndexed"); - customizeView.saveCustomView(); } @Test public void testEachItemIndexing() { + goToProjectHome(); EditListDefinitionPage editListDefinitionPage = _listHelper.goToEditDesign("NIMHSlides"); editListDefinitionPage.openAdvancedListSettings() - .indexEachItemAsASeparateDocument(true, "${SubjectId}", AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText) + .indexEachItemAsASeparateDocument(true, "Subject Id: ${SubjectId}", AdvancedListSettingsDialog.SearchIndexOptions.NonPhiFields) .clickApply() .clickSave(); @@ -111,7 +105,7 @@ public void testEntireListIndexing() editDesign.openAdvancedListSettings() .indexEntireListAsASingleDocument(true, customTitle, AdvancedListSettingsDialog.SearchIncludeOptions.DataOnly, - AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText, null) + AdvancedListSettingsDialog.SearchIndexOptions.NonPhiFields, null) .clickApply() .clickSave(); @@ -119,14 +113,14 @@ public void testEntireListIndexing() editDesign.openAdvancedListSettings() .indexEntireListAsASingleDocument(true, "", AdvancedListSettingsDialog.SearchIncludeOptions.MetadataAndData, - AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText, null) + 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(), "Justin", 2, null); searchFor(getProjectName(), "Occupation", 0, null); + searchFor(getProjectName(), "10001", 2, null); _listHelper.goToEditDesign(listName) .openAdvancedListSettings() @@ -138,7 +132,7 @@ public void testEntireListIndexing() editDesign.openAdvancedListSettings() .indexEntireListAsASingleDocument(true, "", AdvancedListSettingsDialog.SearchIncludeOptions.MetadataOnly, - AdvancedListSettingsDialog.SearchIndexOptions.NonPhiFields, null) + AdvancedListSettingsDialog.SearchIndexOptions.NonPhiText, null) .clickApply() .clickSave(); From 6565dc30f65d860f746629e5d343c83e2d1aed28 Mon Sep 17 00:00:00 2001 From: labkey-sweta Date: Mon, 17 Jul 2023 09:59:54 -0700 Subject: [PATCH 3/4] Code review feedback --- .../list/AdvancedListSettingsDialog.java | 52 ++++++++++++++++--- .../test/tests/list/ListIndexingTest.java | 19 +++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java b/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java index 5a9de0ec60..e670ca7457 100644 --- a/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java +++ b/src/org/labkey/test/components/list/AdvancedListSettingsDialog.java @@ -5,9 +5,9 @@ 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; @@ -45,6 +45,13 @@ public AdvancedListSettingsDialog allowMultipleDiscussionsPerItem() return this; } + 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) @@ -60,12 +67,38 @@ 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)) + 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, null); @@ -97,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); } } @@ -135,7 +168,7 @@ protected ElementCache newElementCache() @Override protected ElementCache elementCache() { - return (ElementCache) super.elementCache(); + return (ElementCache) super.elementCache(); } protected class ElementCache extends ModalDialog.ElementCache @@ -144,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") @@ -170,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)"); diff --git a/src/org/labkey/test/tests/list/ListIndexingTest.java b/src/org/labkey/test/tests/list/ListIndexingTest.java index 69ae92b2a6..dc5642e6e1 100644 --- a/src/org/labkey/test/tests/list/ListIndexingTest.java +++ b/src/org/labkey/test/tests/list/ListIndexingTest.java @@ -1,6 +1,7 @@ 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; @@ -86,6 +87,18 @@ public void testEntireListIndexing() .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); @@ -128,6 +141,12 @@ public void testEntireListIndexing() .clickApply() .clickSave(); + _listHelper.goToEditDesign("NIMHSamples") + .openAdvancedListSettings() + .disableEntireListIndex() + .clickApply() + .clickSave(); + editDesign = _listHelper.goToEditDesign(listName); editDesign.openAdvancedListSettings() .indexEntireListAsASingleDocument(true, "", From 3a380188575c18bac3709c782be55cb30cecce12 Mon Sep 17 00:00:00 2001 From: labkey-sweta Date: Thu, 20 Jul 2023 22:53:23 -0700 Subject: [PATCH 4/4] Code review changes --- src/org/labkey/test/tests/list/ListIndexingTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/org/labkey/test/tests/list/ListIndexingTest.java b/src/org/labkey/test/tests/list/ListIndexingTest.java index dc5642e6e1..3f60f67c4b 100644 --- a/src/org/labkey/test/tests/list/ListIndexingTest.java +++ b/src/org/labkey/test/tests/list/ListIndexingTest.java @@ -10,9 +10,13 @@ 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; @@ -26,6 +30,8 @@ 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() { @@ -68,7 +74,11 @@ public void testEachItemIndexing() .clickApply() .clickSave(); - searchFor(getProjectName(), "10001", 8, null); + SearchResultsPage resultsPage = _searchHelper.searchFor("10001"); + Assert.assertEquals("Incorrect number of search result", Integer.valueOf(8), resultsPage.getResultCount()); + List res = resultsPage.getResults(); + for (WebElement row : res) + Assert.assertTrue("Custom title is not applied in results", row.getText().startsWith("Subject Id: 10001")); } @Test