Skip to content

Commit

Permalink
Merge pull request #71 from Lombiq/issue/OSOE-629
Browse files Browse the repository at this point in the history
OSOE-629: Test Features Guard with recipe import too
  • Loading branch information
Psichorex authored Jun 14, 2023
2 parents 8b066fa + a38c0a9 commit a82bcb8
Showing 1 changed file with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Atata;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Pages;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using System;
using System.Threading.Tasks;

namespace Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.Extensions;
Expand Down Expand Up @@ -33,46 +35,92 @@ public static async Task TestConditionallyEnabledFeaturesAsync(this UITestContex
// After setup, Twitter should be enabled.
context.Exists(By.XPath("//a[@id='btn-disable-OrchardCore_Twitter']"));

await RunTestConditionallyEnabledFeaturesAssertionsAsync(
context,
featureId => context.ClickReliablyOnAsync(By.XPath($"//a[@id='btn-enable-{featureId.Replace('.', '_')}']")),
async featureId =>
{
await context.ClickReliablyOnAsync(By.XPath($"//a[@id='btn-disable-{featureId.Replace('.', '_')}']"));
await context.ClickModalOkAsync();
});

// Doing the same checks but with recipes. Starting with a new tenant to make sure that the starting state is
// correct.
context.SwitchCurrentTenantToDefault();
await SetUpNewTenantAndGoToFeaturesListAsync(context, setupRecipeId, "TestTenant2", "test-tenant2");

// Note that when doing feature operations via recipes, we deliberately use the JSON Import feature, not the
// ExecuteRecipeDirectlyAsync() shortcut. This way, we can make sure that it works the same as it would for a
// user.
await RunTestConditionallyEnabledFeaturesAssertionsAsync(
context,
featureId => EnableFeatureViaJsonImportAndGoToFeaturesListAsync(context, featureId),
featureId => DisableFeatureViaJsonImportAndGoToFeaturesListAsync(context, featureId));
}

private static async Task SetUpNewTenantAndGoToFeaturesListAsync(
UITestContext context,
string setupRecipeId,
string tenantName = "TestTenant1",
string tenantUrlPrefix = "test-tenant1")
{
await context.SignInDirectlyAsync();

await context.CreateAndSwitchToTenantManuallyAsync(tenantName, tenantUrlPrefix, string.Empty, "features guard");

await context.GoToSetupPageAndSetupOrchardCoreAsync(
new OrchardCoreSetupParameters(context)
{
SiteName = tenantName,
RecipeId = setupRecipeId,
TablePrefix = tenantName,
RunSetupOnCurrentPage = true,
});

await context.SignInDirectlyAsync();
await context.GoToAdminRelativeUrlAsync("/Features");
}

private static async Task RunTestConditionallyEnabledFeaturesAssertionsAsync(
UITestContext context,
Func<string, Task> enableFeature,
Func<string, Task> disableFeature)
{
// When ChartJs gets disabled but UIKit is enabled, Twitter should remain enabled.
await context.ClickReliablyOnAsync(By.XPath("//a[@id='btn-disable-Lombiq_ChartJs']"));
await context.ClickModalOkAsync();
await disableFeature("Lombiq.ChartJs");
context.Exists(By.XPath("//a[@id='btn-disable-Lombiq_UIKit']"));
context.Exists(By.XPath("//a[@id='btn-disable-OrchardCore_Twitter']"));

// When either UIKit or ChartJs is enabled, it should not be possible to disable Twitter.
await context.ClickReliablyOnAsync(By.XPath("//a[@id='btn-disable-OrchardCore_Twitter']"));
await context.ClickModalOkAsync();
await disableFeature("OrchardCore.Twitter");
context.Exists(By.XPath("//a[@id='btn-disable-OrchardCore_Twitter']"));

// When UIKit gets disabled and ChartJs is also disabled, Twitter should get disabled.
await context.ClickReliablyOnAsync(By.XPath("//a[@id='btn-disable-Lombiq_UIKit']"));
await context.ClickModalOkAsync();
await disableFeature("Lombiq.UIKit");
context.Exists(By.XPath("//a[@id='btn-enable-Lombiq_ChartJs']"));
context.Exists(By.XPath("//a[@id='btn-enable-OrchardCore_Twitter']"));

// When UIKit is enabled, Twitter should get enabled.
await context.ClickReliablyOnAsync(By.XPath("//a[@id='btn-enable-Lombiq_UIKit']"));
await enableFeature("Lombiq.UIKit");
context.Exists(By.XPath("//a[@id='btn-disable-OrchardCore_Twitter']"));
}

private static async Task SetUpNewTenantAndGoToFeaturesListAsync(UITestContext context, string setupRecipeId)
{
await context.SignInDirectlyAsync();
private static Task EnableFeatureViaJsonImportAndGoToFeaturesListAsync(UITestContext context, string featureId) =>
RunFeatureStepViaJsonImportAndGoToFeaturesListAsync(context, "enable", featureId);

const string tenantName = "TestTenant";
private static Task DisableFeatureViaJsonImportAndGoToFeaturesListAsync(UITestContext context, string featureId) =>
RunFeatureStepViaJsonImportAndGoToFeaturesListAsync(context, "disable", featureId);

await context.CreateAndSwitchToTenantManuallyAsync(tenantName, "tt1", string.Empty, "features guard");
private static async Task RunFeatureStepViaJsonImportAndGoToFeaturesListAsync(
UITestContext context, string command, string featureId)
{
await context.GoToAdminRelativeUrlAsync("/DeploymentPlan/Import/Json");

await context.GoToSetupPageAndSetupOrchardCoreAsync(
new OrchardCoreSetupParameters(context)
{
SiteName = tenantName,
RecipeId = setupRecipeId,
TablePrefix = tenantName,
RunSetupOnCurrentPage = true,
});
await context.FillInCodeMirrorEditorWithRetriesAsync(
By.CssSelector(".CodeMirror.cm-s-default"),
@"{ ""steps"": [ { ""name"": ""Feature"", """ + command + @""": [ """ + featureId + @""" ] } ] }");

await context.SignInDirectlyAsync();
await context.ClickReliablyOnSubmitAsync();
await context.GoToAdminRelativeUrlAsync("/Features");
}
}

0 comments on commit a82bcb8

Please sign in to comment.