Skip to content

Commit ae84fec

Browse files
committed
Optional features ui coverage
1 parent bd3461c commit ae84fec

2 files changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 Featueres, 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 Map<String, String> getFeatureMap()
46+
{
47+
return elementCache().getListItems();
48+
}
49+
50+
public Set<String> getFeatureIds()
51+
{
52+
return getFeatureMap().keySet();
53+
}
54+
55+
public boolean getFeatureStatus(String id)
56+
{
57+
return elementCache().getCheckboxById(id).get();
58+
}
59+
60+
public OptionalFeaturesPage setFeatureStatus(String id, boolean status)
61+
{
62+
elementCache().getCheckboxById(id).set(status);
63+
return this;
64+
}
65+
66+
@Override
67+
protected ElementCache newElementCache()
68+
{
69+
return new ElementCache();
70+
}
71+
72+
protected class ElementCache extends LabKeyPage<ElementCache>.ElementCache
73+
{
74+
public final Locator.XPathLocator listGroupLoc = Locator.tagWithClass("div", "list-group");
75+
public final WebElement listGroupElement = listGroupLoc.waitForElement(getDriver(), 1500);
76+
public final Locator listItemLabelLoc = Locator.tagWithClass("div", "list-group-item")
77+
.child(Locator.tag("Label"));
78+
private Map<String, String> _listItems;
79+
80+
public Map<String, String> getListItems()
81+
{
82+
if (_listItems == null) {
83+
_listItems = new HashMap<String, String>();
84+
for (WebElement el : listItemLabelLoc.findElements(listGroupElement)) {
85+
WebElement idEl = Locator.tagWithAttribute("type", "checkbox")
86+
.findElement(el);
87+
WebElement labelEl = Locator.tagWithClass("span", "toggle-label-text")
88+
.findElement(el);
89+
_listItems.put(idEl.getText(), labelEl.getText());
90+
}
91+
}
92+
return _listItems;
93+
}
94+
95+
public Checkbox getCheckboxById(String id)
96+
{
97+
return Checkbox.Checkbox(Locator.id(id)).waitFor(listGroupElement);
98+
}
99+
}
100+
101+
public enum OptionalFeatureType{
102+
Experimental,
103+
Optional,
104+
Deprecated
105+
}
106+
}

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

Lines changed: 86 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,88 @@ 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+
waitAndClickAndWait(Locator.linkWithText("optional features"));
238+
var optionalFeaturesPage = new OptionalFeaturesPage(getDriver());
239+
var featureIds = List.of("extendedMetrics", "StageFileUploads");
240+
var cn = createDefaultConnection();
241+
242+
for (String testId : featureIds) {
243+
// capture initial state
244+
boolean initialState = OptionalFeatureHelper.isOptionalFeatureEnabled(cn, testId);
245+
246+
// ensure the UI reflects the same state
247+
boolean initialUIState = optionalFeaturesPage.getFeatureStatus(testId);
248+
checker().withScreenshot("initial state not as expected")
249+
.wrapAssertion(()-> Assertions.assertThat(initialUIState)
250+
.as("expect ui to align with API initial state")
251+
.isEqualTo(initialState));
252+
253+
// toggle it the other way
254+
optionalFeaturesPage.setFeatureStatus(testId, !initialState);
255+
checker().withScreenshot("toggled state not as expected")
256+
.awaiting(Duration.ofMillis(500), ()-> Assertions.assertThat(OptionalFeatureHelper.isOptionalFeatureEnabled(cn, testId))
257+
.as("expect toggling the UI to update the server status for the feature")
258+
.isEqualTo(!initialState));
259+
260+
// use the API to restore the initial state
261+
OptionalFeatureHelper.setOptionalFeature(cn, testId, initialState);
262+
optionalFeaturesPage.goToAdminConsole();
263+
264+
optionalFeaturesPage = OptionalFeaturesPage.beginAt(this,
265+
OptionalFeaturesPage.OptionalFeatureType.Optional);
266+
267+
// verify the page state reflects the API change after a reload
268+
checker().withScreenshot("state not as expected after api set and refresh")
269+
.verifyEquals("expect page to reflect state after api config",
270+
initialState, optionalFeaturesPage.getFeatureStatus(testId));
271+
}
272+
}
273+
274+
@Test
275+
public void testUIExperimentalFeatures()
276+
{
277+
goToAdminConsole();
278+
waitAndClickAndWait(Locator.linkWithText("experimental features"));
279+
var experimentalFeaturesPage = new OptionalFeaturesPage(getDriver());
280+
var featureIds = List.of("queryBasedDatasets", "LinkedDatasetCheck", "blockMaliciousClients");
281+
var cn = createDefaultConnection();
282+
283+
for (String testId : featureIds) {
284+
// capture initial state
285+
boolean initialState = OptionalFeatureHelper.isOptionalFeatureEnabled(cn, testId);
286+
287+
// ensure the UI reflects the same state
288+
boolean initialUIState = experimentalFeaturesPage.getFeatureStatus(testId);
289+
checker().withScreenshot("initial state not as expected")
290+
.wrapAssertion(()-> Assertions.assertThat(initialUIState)
291+
.as("expect ui to align with API initial state")
292+
.isEqualTo(initialState));
293+
294+
// toggle it the other way
295+
experimentalFeaturesPage.setFeatureStatus(testId, !initialState);
296+
checker().withScreenshot("toggled state not as expected")
297+
.awaiting(Duration.ofMillis(500), ()-> Assertions.assertThat(OptionalFeatureHelper.isOptionalFeatureEnabled(cn, testId))
298+
.as("expect toggling the UI to update the server status for the feature")
299+
.isEqualTo(!initialState));
300+
301+
// use the API to restore the initial state
302+
OptionalFeatureHelper.setOptionalFeature(cn, testId, initialState);
303+
experimentalFeaturesPage.goToAdminConsole();
304+
305+
experimentalFeaturesPage = OptionalFeaturesPage.beginAt(this,
306+
OptionalFeaturesPage.OptionalFeatureType.Experimental);
307+
308+
// verify the page state reflects the API change after a reload
309+
checker().withScreenshot("state not as expected after api set and refresh")
310+
.verifyEquals("expect page to reflect state after api config",
311+
initialState, experimentalFeaturesPage.getFeatureStatus(testId));
312+
}
313+
}
314+
229315
@Test
230316
public void testAppAdminRole()
231317
{

0 commit comments

Comments
 (0)