Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-629: Test Features Guard with recipe import too #71

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}