|
15 | 15 | */ |
16 | 16 | package org.labkey.test.tests; |
17 | 17 |
|
| 18 | +import org.assertj.core.api.Assertions; |
18 | 19 | import org.junit.Test; |
19 | 20 | import org.junit.experimental.categories.Category; |
20 | 21 | import org.labkey.remoteapi.CommandException; |
|
25 | 26 | import org.labkey.test.Locator; |
26 | 27 | import org.labkey.test.WebDriverWrapper; |
27 | 28 | import org.labkey.test.WebTestHelper; |
| 29 | +import org.labkey.test.util.OptionalFeatureHelper; |
28 | 30 | import org.labkey.test.categories.Daily; |
29 | 31 | import org.labkey.test.pages.core.admin.CustomizeSitePage; |
| 32 | +import org.labkey.test.pages.core.admin.OptionalFeaturesPage; |
30 | 33 | import org.labkey.test.pages.core.login.LoginConfigRow; |
31 | 34 | import org.labkey.test.pages.core.login.LoginConfigurePage; |
32 | 35 | import org.labkey.test.util.LogMethod; |
33 | 36 |
|
34 | 37 | import java.io.IOException; |
| 38 | +import java.time.Duration; |
35 | 39 | import java.util.ArrayList; |
36 | 40 | import java.util.Arrays; |
37 | 41 | import java.util.List; |
@@ -226,6 +230,26 @@ public void testSiteBannerAPIConfiguration() throws Exception |
226 | 230 | .verifyFalse("expect banner not to be shown", bannerLoc.isDisplayed(getDriver())); |
227 | 231 | } |
228 | 232 |
|
| 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 | + |
229 | 253 | @Test |
230 | 254 | public void testAppAdminRole() |
231 | 255 | { |
@@ -357,4 +381,41 @@ public void testAdminConsoleCredits() |
357 | 381 | log("Verifying the page is properly loaded"); |
358 | 382 | assertTextPresent("JAR Files Distributed with the API Module"); |
359 | 383 | } |
| 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 | + } |
360 | 421 | } |
0 commit comments