|
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,88 @@ 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 | + 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 | + |
229 | 315 | @Test |
230 | 316 | public void testAppAdminRole() |
231 | 317 | { |
|
0 commit comments