Skip to content

Commit 445de90

Browse files
committed
coverage for Issue 51843
1 parent e43f02c commit 445de90

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

src/org/labkey/test/tests/AdminConsoleTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.labkey.remoteapi.CommandException;
2121
import org.labkey.remoteapi.Connection;
2222
import org.labkey.remoteapi.SimpleGetCommand;
23+
import org.labkey.remoteapi.SimplePostCommand;
2324
import org.labkey.test.BaseWebDriverTest;
2425
import org.labkey.test.Locator;
2526
import org.labkey.test.WebTestHelper;
@@ -33,11 +34,13 @@
3334
import java.util.ArrayList;
3435
import java.util.Arrays;
3536
import java.util.List;
37+
import java.util.Map;
3638

3739
import static org.junit.Assert.assertEquals;
3840
import static org.junit.Assert.assertFalse;
3941
import static org.junit.Assert.assertNull;
4042
import static org.junit.Assert.assertTrue;
43+
import static org.junit.Assert.fail;
4144

4245
@Category({Daily.class})
4346
@BaseWebDriverTest.ClassTimeout(minutes = 3)
@@ -151,6 +154,73 @@ public void testRibbonBar()
151154
assertElementNotPresent(ribbonLink);
152155
}
153156

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+
154224
@Test
155225
public void testAppAdminRole()
156226
{

0 commit comments

Comments
 (0)