|
20 | 20 | import org.labkey.remoteapi.CommandException; |
21 | 21 | import org.labkey.remoteapi.Connection; |
22 | 22 | import org.labkey.remoteapi.SimpleGetCommand; |
| 23 | +import org.labkey.remoteapi.SimplePostCommand; |
23 | 24 | import org.labkey.test.BaseWebDriverTest; |
24 | 25 | import org.labkey.test.Locator; |
25 | 26 | import org.labkey.test.WebTestHelper; |
|
33 | 34 | import java.util.ArrayList; |
34 | 35 | import java.util.Arrays; |
35 | 36 | import java.util.List; |
| 37 | +import java.util.Map; |
36 | 38 |
|
37 | 39 | import static org.junit.Assert.assertEquals; |
38 | 40 | import static org.junit.Assert.assertFalse; |
39 | 41 | import static org.junit.Assert.assertNull; |
40 | 42 | import static org.junit.Assert.assertTrue; |
| 43 | +import static org.junit.Assert.fail; |
41 | 44 |
|
42 | 45 | @Category({Daily.class}) |
43 | 46 | @BaseWebDriverTest.ClassTimeout(minutes = 3) |
@@ -151,6 +154,73 @@ public void testRibbonBar() |
151 | 154 | assertElementNotPresent(ribbonLink); |
152 | 155 | } |
153 | 156 |
|
| 157 | + // Issue 51843 allow site banner configuration via api |
| 158 | + @Test |
| 159 | + public void testSiteBannerAPIConfiguration() throws Exception |
| 160 | + { |
| 161 | + goToAdminConsole(); |
| 162 | + |
| 163 | + String bannerMessage = "test banner message" + TRICKY_CHARACTERS; |
| 164 | + Locator bannerLoc = Locator.tagWithClass("div", "lk-dismissable-warn").containing(bannerMessage); |
| 165 | + |
| 166 | + //As site admin |
| 167 | + // set the message and show it |
| 168 | + var showBannerCmd = new SimplePostCommand("admin", "setRibbonMessage.api"); |
| 169 | + showBannerCmd.setParameters(Map.of("message", bannerMessage, |
| 170 | + "show", true)); |
| 171 | + showBannerCmd.execute(createDefaultConnection(), "/"); |
| 172 | + refresh(); |
| 173 | + // verify it is shown |
| 174 | + checker().withScreenshot("banner not shown or not as expected") |
| 175 | + .verifyTrue("expect banner to be shown", bannerLoc.isDisplayed(getDriver())); |
| 176 | + |
| 177 | + // hide the banner |
| 178 | + var hideBannerCmd = new SimplePostCommand("admin", "setRibbonMessage.api"); |
| 179 | + hideBannerCmd.setParameters(Map.of("show", false)); |
| 180 | + hideBannerCmd.execute(createDefaultConnection(), "/"); |
| 181 | + refresh(); |
| 182 | + // verify it is hidden |
| 183 | + checker().withScreenshot("banner is shown when not expected") |
| 184 | + .verifyFalse("expect banner not to be shown", bannerLoc.isDisplayed(getDriver())); |
| 185 | + |
| 186 | + // restore it with the previous banner value |
| 187 | + var restoreBannerCmd = new SimplePostCommand("admin", "setRibbonMessage.api"); |
| 188 | + restoreBannerCmd.setParameters(Map.of("show", true)); |
| 189 | + restoreBannerCmd.execute(createDefaultConnection(), "/"); |
| 190 | + refresh(); |
| 191 | + // verify it is restored with the previous value |
| 192 | + checker().withScreenshot("banner not shown or not as expected") |
| 193 | + .verifyTrue("expect banner to be shown", bannerLoc.isDisplayed(getDriver())); |
| 194 | + |
| 195 | + // as app admin |
| 196 | + impersonateRole("Application Admin"); |
| 197 | + var reHideBannerCmd = new SimplePostCommand("admin", "setRibbonMessage.api"); |
| 198 | + reHideBannerCmd.setParameters(Map.of("show", false)); |
| 199 | + try |
| 200 | + { |
| 201 | + reHideBannerCmd.execute(createDefaultConnection(), "/"); |
| 202 | + fail("expect exception trying to call this API as app admin"); |
| 203 | + } |
| 204 | + catch (CommandException e) |
| 205 | + { |
| 206 | + // success, caller with app admin failed to hit this api |
| 207 | + } |
| 208 | + refresh(); |
| 209 | + // verify it remains shown |
| 210 | + checker().withScreenshot("banner is hidden when not expected") |
| 211 | + .verifyTrue("expect banner to be shown", bannerLoc.isDisplayed(getDriver())); |
| 212 | + |
| 213 | + stopImpersonating(); |
| 214 | + |
| 215 | + // clean up after ourselves as site admin |
| 216 | + var clearAndHideBannerCmd = new SimplePostCommand("admin", "setRibbonMessage.api"); |
| 217 | + clearAndHideBannerCmd.setParameters(Map.of("show", false, "message", "")); |
| 218 | + clearAndHideBannerCmd.execute(createDefaultConnection(), "/"); |
| 219 | + refresh(); |
| 220 | + checker().withScreenshot("banner is shown when not expected") |
| 221 | + .verifyFalse("expect banner not to be shown", bannerLoc.isDisplayed(getDriver())); |
| 222 | + } |
| 223 | + |
154 | 224 | @Test |
155 | 225 | public void testAppAdminRole() |
156 | 226 | { |
|
0 commit comments