From 00af84172886a1440c350029d2d294a2a78c5c2d Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Thu, 3 Jul 2025 07:54:34 -0700 Subject: [PATCH] Add test for "Reset" email notifications settings --- .../pages/announcements/EmailPrefsPage.java | 70 +++++++++++++++++-- .../labkey/test/tests/MessagesLongTest.java | 47 ++++++++++--- 2 files changed, 101 insertions(+), 16 deletions(-) diff --git a/src/org/labkey/test/pages/announcements/EmailPrefsPage.java b/src/org/labkey/test/pages/announcements/EmailPrefsPage.java index 4b6f70746d..02b74c319d 100644 --- a/src/org/labkey/test/pages/announcements/EmailPrefsPage.java +++ b/src/org/labkey/test/pages/announcements/EmailPrefsPage.java @@ -43,36 +43,92 @@ public static EmailPrefsPage beginAt(WebDriverWrapper driver, String containerPa return new EmailPrefsPage(driver.getDriver()); } + @Deprecated // Inconsistent name, but leave for backward compatibility public EmailPrefsPage setNoNotify() + { + return setNotifyNone(); + } + + public EmailPrefsPage setNotifyNone() { elementCache().notifyNone.click(); return new EmailPrefsPage(getDriver()); } + public boolean isNotifyNoneSelected() + { + return elementCache().notifyNone.isSelected(); + } + + public boolean isNotifyNoneDisabled() + { + return !elementCache().notifyNone.isEnabled(); + } + public EmailPrefsPage setNotifyOnMine() { elementCache().notifyMine.click(); return new EmailPrefsPage(getDriver()); } + public boolean isNotifyOnMineSelected() + { + return elementCache().notifyMine.isSelected(); + } + + public boolean isNotifyOnMineDisabled() + { + return !elementCache().notifyMine.isEnabled(); + } + public EmailPrefsPage setNotifyOnAll() { elementCache().notifyAll.click(); return new EmailPrefsPage(getDriver()); } + public boolean isNotifyOnAllSelected() + { + return elementCache().notifyAll.isSelected(); + } + + public boolean isNotifyOnAllDisabled() + { + return !elementCache().notifyAll.isEnabled(); + } + public EmailPrefsPage setTypeIndividual() { - elementCache().notifyAll.click(); + elementCache().typeIndividual.click(); return new EmailPrefsPage(getDriver()); } + public boolean isTypeIndividualSelected() + { + return elementCache().typeIndividual.isSelected(); + } + + public boolean isTypeIndividualDisabled() + { + return !elementCache().typeIndividual.isEnabled(); + } + public EmailPrefsPage setTypeDigest() { - elementCache().notifyAll.click(); + elementCache().typeDigest.click(); return new EmailPrefsPage(getDriver()); } + public boolean isTypeDigestSelected() + { + return elementCache().typeDigest.isSelected(); + } + + public boolean isTypeDigestDisabled() + { + return !elementCache().typeDigest.isEnabled(); + } + public EmailPrefsPage reset(boolean reset) { if (reset) @@ -108,16 +164,16 @@ protected ElementCache newElementCache() protected class ElementCache extends LabKeyPage.ElementCache { - private Locator.XPathLocator notify = Locator.radioButtonByName("emailPreference"); + private final Locator.XPathLocator notify = Locator.radioButtonByName("emailPreference"); protected WebElement notifyNone = notify.withAttribute("value", "0").findWhenNeeded(this); protected WebElement notifyMine = notify.withAttribute("value", "2").findWhenNeeded(this); protected WebElement notifyAll = notify.withAttribute("value", "1").findWhenNeeded(this); - private Locator.XPathLocator type = Locator.radioButtonByName("notificationType"); - protected WebElement typeIndividual = notify.withAttribute("value", "3").findWhenNeeded(this); - protected WebElement typeDigest = notify.withAttribute("value", "4").findWhenNeeded(this); + private final Locator.XPathLocator type = Locator.radioButtonByName("notificationType"); + protected WebElement typeIndividual = type.withAttribute("value", "3").findWhenNeeded(this); + protected WebElement typeDigest = type.withAttribute("value", "4").findWhenNeeded(this); - Checkbox resetCheckbox = Checkbox(Locator.tagWithName("input", "emailPreference").withAttribute("value", "1")).findWhenNeeded(this); + Checkbox resetCheckbox = Checkbox(Locator.tagWithId("input", "resetFolderDefault")).findWhenNeeded(this); WebElement updateButton = Locator.lkButton("Update").findWhenNeeded(this); WebElement cancelButton = Locator.lkButton("Cancel").findWhenNeeded(this); diff --git a/src/org/labkey/test/tests/MessagesLongTest.java b/src/org/labkey/test/tests/MessagesLongTest.java index 5974d1b803..136dcc2431 100644 --- a/src/org/labkey/test/tests/MessagesLongTest.java +++ b/src/org/labkey/test/tests/MessagesLongTest.java @@ -33,6 +33,7 @@ import org.labkey.test.components.html.SiteNavBar; import org.labkey.test.pages.admin.PermissionsPage; import org.labkey.test.pages.announcements.AdminPage; +import org.labkey.test.pages.announcements.EmailPrefsPage; import org.labkey.test.pages.announcements.InsertPage; import org.labkey.test.pages.announcements.RespondPage; import org.labkey.test.util.ApiPermissionsHelper; @@ -170,8 +171,6 @@ private void doSetup() .assertPermissionSetting("testers1", "No Permissions") .clickSaveAndFinish(); _containerHelper.enableModule(PROJECT_NAME, "Dumbster"); - - } @Test @@ -190,10 +189,37 @@ public void testSteps() clickProject(PROJECT_NAME); log("Check email preferences"); + // Unlike EmailPrefsPage.beginAt(), this ensures returnUrl is passed to the action _portalHelper.clickWebpartMenuItem("Messages", true, "Email Preferences"); - checkCheckbox(Locator.radioButtonByName("emailPreference").index(2)); - clickButton("Update"); - clickButton("Done"); + EmailPrefsPage prefsPage = new EmailPrefsPage(getDriver()); + // Verify prefs are "Mine" (doTestEmailPrefsMine() sets this) and "Individual" (folder default) + assertTrue(prefsPage.isNotifyOnMineSelected()); + assertTrue(prefsPage.isTypeIndividualSelected()); + + // Update to settings that differ from the folder default values to test "Reset to folder default setting", Issue 53387 + prefsPage = prefsPage + .setNotifyOnAll() + .setTypeDigest() + .update(); + assertTrue(prefsPage.isNotifyOnAllSelected()); + assertTrue(prefsPage.isTypeDigestSelected()); + + // After clicking "Reset", all options should be disabled + prefsPage = prefsPage.reset(true); + assertTrue(prefsPage.isNotifyNoneDisabled()); + assertTrue(prefsPage.isNotifyOnMineDisabled()); + assertTrue(prefsPage.isNotifyOnAllDisabled()); + assertTrue(prefsPage.isTypeIndividualDisabled()); + assertTrue(prefsPage.isTypeDigestDisabled()); + + // Submit reset to folder default and verify + prefsPage = prefsPage.update(); + assertTrue(prefsPage.isNotifyOnMineSelected()); + assertTrue(prefsPage.isTypeIndividualSelected()); + + prefsPage = prefsPage.setNotifyOnAll().update(); + assertTrue(prefsPage.isNotifyOnAllSelected()); + prefsPage.done(); SiteNavBar siteNavBar = new SiteNavBar(getDriver()); siteNavBar.enterPageAdminMode(); @@ -225,7 +251,7 @@ public void testSteps() log("Create message using markdown"); clickButton( "New"); InsertPage markdownPage = new InsertPage(getDriver()); - assertEquals("default selection should be 'Markdown'",markdownPage.getRenderAs(), WikiHelper.WikiRendererType.MARKDOWN); + assertEquals("default selection should be 'Markdown'", WikiHelper.WikiRendererType.MARKDOWN, markdownPage.getRenderAs()); markdownPage.setTitle("Markdown is a thing now") .setBody(""" # Holy Header, Batman! @@ -644,10 +670,13 @@ private void doTestEmailPrefsMine() createUserWithPermissions(RESPONDER, PROJECT_NAME, "Editor"); goToProjectHome(PROJECT_NAME); + // Unlike EmailPrefsPage.beginAt(), this ensures returnUrl is passed to the action _portalHelper.clickWebpartMenuItem("Messages", true, "Email Preferences"); - checkCheckbox(Locator.radioButtonByName("emailPreference").index(1)); - clickButton("Update"); - clickButton("Done"); + EmailPrefsPage prefsPage = new EmailPrefsPage(getDriver()) + .setNotifyOnMine() + .update(); + assertTrue(prefsPage.isNotifyOnMineSelected()); + prefsPage.done(); createNewMessage(_messageTitle, _messageBody);