Skip to content

Commit dbcb9bf

Browse files
Optional features ui coverage (#2559)
1 parent 136140b commit dbcb9bf

2 files changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.labkey.test.pages.core.admin;
2+
3+
import org.labkey.test.Locator;
4+
import org.labkey.test.WebDriverWrapper;
5+
import org.labkey.test.WebTestHelper;
6+
import org.labkey.test.components.html.Checkbox;
7+
import org.labkey.test.pages.LabKeyPage;
8+
import org.openqa.selenium.WebDriver;
9+
import org.openqa.selenium.WebElement;
10+
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
import java.util.Set;
14+
15+
/*
16+
Wraps Optional Features, Experimental Features, Deprecated Features pages linked
17+
from Admin Console
18+
*/
19+
public class OptionalFeaturesPage extends LabKeyPage<OptionalFeaturesPage.ElementCache>
20+
{
21+
public OptionalFeaturesPage(WebDriver driver)
22+
{
23+
super(driver);
24+
}
25+
26+
public static OptionalFeaturesPage beginAt(WebDriverWrapper webDriverWrapper, OptionalFeatureType featureType)
27+
{
28+
webDriverWrapper.beginAt(WebTestHelper.buildURL("admin", "/", "optionalFeatures", Map.of("Type", featureType.toString())));
29+
return new OptionalFeaturesPage(webDriverWrapper.getDriver());
30+
}
31+
32+
@Override
33+
protected void waitForPage()
34+
{
35+
waitFor(()-> elementCache().listGroupLoc.findWhenNeeded(getDriver()).isDisplayed(),
36+
"The page did not render in time", WAIT_FOR_JAVASCRIPT);
37+
}
38+
39+
public ShowAdminPage goToAdminConsole()
40+
{
41+
clickAndWait(Locator.linkWithText("Admin Console"));
42+
return new ShowAdminPage(getDriver());
43+
}
44+
45+
public boolean getFeatureStatus(String id)
46+
{
47+
return elementCache().getCheckboxById(id).get();
48+
}
49+
50+
public OptionalFeaturesPage setFeatureStatus(String id, boolean status)
51+
{
52+
elementCache().getCheckboxById(id).set(status);
53+
return this;
54+
}
55+
56+
@Override
57+
protected ElementCache newElementCache()
58+
{
59+
return new ElementCache();
60+
}
61+
62+
protected class ElementCache extends LabKeyPage<ElementCache>.ElementCache
63+
{
64+
public final Locator.XPathLocator listGroupLoc = Locator.tagWithClass("div", "list-group");
65+
public final WebElement listGroupElement = listGroupLoc.waitForElement(getDriver(), 1500);
66+
public final Locator listItemLabelLoc = Locator.tagWithClass("div", "list-group-item")
67+
.child(Locator.tag("Label"));
68+
69+
public Checkbox getCheckboxById(String id)
70+
{
71+
return Checkbox.Checkbox(Locator.id(id)).waitFor(listGroupElement);
72+
}
73+
}
74+
75+
public enum OptionalFeatureType{
76+
Experimental,
77+
Optional,
78+
Deprecated
79+
}
80+
}

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.labkey.test.tests;
1717

18+
import org.assertj.core.api.Assertions;
1819
import org.junit.Test;
1920
import org.junit.experimental.categories.Category;
2021
import org.labkey.remoteapi.CommandException;
@@ -25,13 +26,16 @@
2526
import org.labkey.test.Locator;
2627
import org.labkey.test.WebDriverWrapper;
2728
import org.labkey.test.WebTestHelper;
29+
import org.labkey.test.util.OptionalFeatureHelper;
2830
import org.labkey.test.categories.Daily;
2931
import org.labkey.test.pages.core.admin.CustomizeSitePage;
32+
import org.labkey.test.pages.core.admin.OptionalFeaturesPage;
3033
import org.labkey.test.pages.core.login.LoginConfigRow;
3134
import org.labkey.test.pages.core.login.LoginConfigurePage;
3235
import org.labkey.test.util.LogMethod;
3336

3437
import java.io.IOException;
38+
import java.time.Duration;
3539
import java.util.ArrayList;
3640
import java.util.Arrays;
3741
import java.util.List;
@@ -226,6 +230,26 @@ public void testSiteBannerAPIConfiguration() throws Exception
226230
.verifyFalse("expect banner not to be shown", bannerLoc.isDisplayed(getDriver()));
227231
}
228232

233+
@Test
234+
public void testUIOptionalFeatures()
235+
{
236+
goToAdminConsole();
237+
238+
var featureIds = List.of("extendedMetrics", "StageFileUploads");
239+
240+
verifyOptionalFeatures("optional features", featureIds, OptionalFeaturesPage.OptionalFeatureType.Optional);
241+
}
242+
243+
@Test
244+
public void testUIExperimentalFeatures()
245+
{
246+
goToAdminConsole();
247+
248+
var featureIds = List.of("queryBasedDatasets", "LinkedDatasetCheck", "blockMaliciousClients");
249+
250+
verifyOptionalFeatures("experimental features", featureIds, OptionalFeaturesPage.OptionalFeatureType.Experimental);
251+
}
252+
229253
@Test
230254
public void testAppAdminRole()
231255
{
@@ -357,4 +381,41 @@ public void testAdminConsoleCredits()
357381
log("Verifying the page is properly loaded");
358382
assertTextPresent("JAR Files Distributed with the API Module");
359383
}
384+
385+
private void verifyOptionalFeatures(String linkText, List<String> featureIds, OptionalFeaturesPage.OptionalFeatureType optionalFeatureType)
386+
{
387+
waitAndClickAndWait(Locator.linkWithText(linkText));
388+
var optionalFeaturesPage = new OptionalFeaturesPage(getDriver());
389+
var cn = createDefaultConnection();
390+
391+
for (String testId : featureIds) {
392+
// capture initial state
393+
boolean initialState = OptionalFeatureHelper.isOptionalFeatureEnabled(cn, testId);
394+
395+
// ensure the UI reflects the same state
396+
boolean initialUIState = optionalFeaturesPage.getFeatureStatus(testId);
397+
checker().withScreenshot("initial state not as expected")
398+
.wrapAssertion(()-> Assertions.assertThat(initialUIState)
399+
.as("expect ui to align with API initial state")
400+
.isEqualTo(initialState));
401+
402+
// toggle it the other way
403+
optionalFeaturesPage.setFeatureStatus(testId, !initialState);
404+
checker().withScreenshot("toggled state not as expected")
405+
.awaiting(Duration.ofMillis(500), ()-> Assertions.assertThat(OptionalFeatureHelper.isOptionalFeatureEnabled(cn, testId))
406+
.as("expect toggling the UI to update the server status for the feature")
407+
.isEqualTo(!initialState));
408+
409+
// use the API to restore the initial state
410+
OptionalFeatureHelper.setOptionalFeature(cn, testId, initialState);
411+
optionalFeaturesPage.goToAdminConsole();
412+
413+
optionalFeaturesPage = OptionalFeaturesPage.beginAt(this, optionalFeatureType);
414+
415+
// verify the page state reflects the API change after a reload
416+
checker().withScreenshot("state not as expected after api set and refresh")
417+
.verifyEquals("expect page to reflect state after api config",
418+
initialState, optionalFeaturesPage.getFeatureStatus(testId));
419+
}
420+
}
360421
}

0 commit comments

Comments
 (0)