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-847: Basic Orchard features testing should include Workflows and Audit Trail #365

Merged
merged 21 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI.Samples/Tests/BasicOrchardFeaturesTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.BasicOrchardFeaturesTesting;
using Lombiq.Tests.UI.Samples.Constants;
using System.Threading.Tasks;
using Xunit;
Expand Down
1 change: 1 addition & 0 deletions Lombiq.Tests.UI.Samples/Tests/DatabaseSnapshotTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Lombiq.Tests.UI.BasicOrchardFeaturesTesting;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Samples.Constants;
using System.IO;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Atata;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.BasicOrchardFeaturesTesting;

/// <summary>
/// Provides a set of extension methods for Orchard Core Audit Trail feature testing.
/// </summary>
public static class AuditTrailFeatureTestingUITestContextExtensions
{
public static Task TestAuditTrailAsync(this UITestContext context) =>
context.ExecuteTestAsync(
"Test Audit Trail",
async () =>
{
var auditTrailPath = "/AuditTrail";
var auditTrailTestPageTitle = "Audit Trail Test Page";

await context.EnableFeatureDirectlyAsync("OrchardCore.AuditTrail");
await context.GoToAdminRelativeUrlAsync("/Settings" + auditTrailPath);

await context.GoToEditorTabAsync("Content");

await context.SetCheckboxValueAsync(By.XPath("//input[@value='Page']"));

await context.ClickReliablyOnSubmitAsync();

var contentItemsPage = await context.GoToContentItemsPageAsync();
context.RefreshCurrentAtataContext();
contentItemsPage
.CreateNewPage()
.Title.Set(auditTrailTestPageTitle)
.Publish.ClickAndGo()
.AlertMessages.Should.Contain(message => message.IsSuccess);

await context.GoToAdminRelativeUrlAsync(auditTrailPath);

var auditTrailTestPageSuccessXpath = "//div[contains(@class, eventdata)]/small[contains(., 'was published')" + // #spell-check-ignore-line
$" and contains(., 'of the Page')]/a[text()='{auditTrailTestPageTitle}']";

context.Exists(By.XPath(auditTrailTestPageSuccessXpath));

auditTrailTestPageSuccessXpath = auditTrailTestPageSuccessXpath.Replace("published", "created");

context.Exists(By.XPath(auditTrailTestPageSuccessXpath));
});
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Atata;
using Lombiq.Tests.UI.Constants;
using Lombiq.Tests.UI.Helpers;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Models;
using Lombiq.Tests.UI.Pages;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using Shouldly;
using System;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Extensions;
namespace Lombiq.Tests.UI.BasicOrchardFeaturesTesting;

/// <summary>
/// Provides a set of extension methods for basic Orchard features testing.
/// </summary>
public static class BasicOrchardFeaturesTestingUITestContextExtensions
public static class BasicFeaturesTestingUITestContextExtensions
{
/// <summary>
/// <para>
Expand Down Expand Up @@ -141,6 +140,8 @@ public static async Task TestBasicOrchardFeaturesExceptSetupAsync(
await context.TestContentOperationsAsync(customPageHeaderCheckAsync: customPageHeaderCheckAsync);
await context.TestTurningFeatureOnAndOffAsync();
await context.TestMediaOperationsAsync();
await context.TestAuditTrailAsync();
await context.TestWorkflowsAsync();
await context.TestLogoutAsync();
}

Expand Down Expand Up @@ -168,6 +169,8 @@ public static async Task TestBasicOrchardFeaturesExceptSetupAndRegistrationAsync
await context.TestLoginAsync();
await context.TestContentOperationsAsync(dontCheckFrontend, customPageHeaderCheckAsync: customPageHeaderCheckAsync);
await context.TestTurningFeatureOnAndOffAsync();
await context.TestAuditTrailAsync();
await context.TestWorkflowsAsync();
await context.TestLogoutAsync();
}

Expand Down Expand Up @@ -559,97 +562,6 @@ public static Task TestTurningFeatureOnAndOffAsync(
.SearchForFeature(featureName).IsEnabled.Should.Equal(originalEnabledState));
});

public static Task TestMediaOperationsAsync(this UITestContext context) =>
context.ExecuteTestAsync(
"Test media operations",
async () =>
{
const string mediaPath = "/Media";
var imageName = FileUploadHelper.SamplePngFileName;
var documentName = FileUploadHelper.SamplePdfFileName;

await context.GoToAdminRelativeUrlAsync(mediaPath);

context.UploadSamplePngByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line

// Workaround for pending uploads, until you make an action the page is stuck on "Uploads Pending".
context.WaitForPageLoad();
await context.ClickReliablyOnAsync(By.CssSelector("body"));

context.Exists(By.XPath($"//span[contains(text(), '{imageName}')]"));

await context
.Get(By.CssSelector($"a[href=\"/media/{imageName}\"]").OfAnyVisibility())
.ClickReliablyAsync(context);
context.SwitchToFirstWindow();

context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

context.UploadSamplePdfByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line

// Workaround for pending uploads, until you make an action the page is stuck on "Uploads Pending".
context.WaitForPageLoad();
await context.ClickReliablyOnAsync(By.CssSelector("body"));

context.Exists(By.XPath($"//span[contains(text(), '{documentName}')]"));

await context
.Get(By.XPath($"//span[contains(text(), '{documentName}')]/ancestor::tr").OfAnyVisibility())
.ClickReliablyAsync(context);

await context
.Get(By.CssSelector($"a[href=\"/media/{documentName}\"]"))
.ClickReliablyAsync(context);
context.SwitchToFirstWindow();

context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

await context
.Get(By.CssSelector("#folder-tree .treeroot .folder-actions")) // #spell-check-ignore-line
.ClickReliablyAsync(context);

context.Get(By.Id("create-folder-name")).SendKeys("Example Folder");

await context.ClickReliablyOnAsync(By.Id("modalFooterOk"));

// Wait until new folder is created.
context.Exists(
By.XPath("//div[contains(@class, 'alert-info') and contains(.,'This folder is empty')]"));

context.UploadSamplePngByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line
context.UploadSamplePdfByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line
context.WaitForPageLoad();

var image = context.Get(By.XPath($"//span[contains(text(), '{imageName}')]"));

context.Exists(By.XPath($"//span[contains(text(), '{documentName}')]"));

await image.ClickReliablyAsync(context);

await context
.Get(By.XPath($"//span[contains(text(), '{imageName}')]/ancestor::tr"))
.Get(By.CssSelector("a.btn.btn-link.btn-sm.delete-button"))
.ClickReliablyAsync(context);

await context.ClickModalOkAsync();
context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

context.Missing(By.XPath("//span[text()=' Image.png ' and @class='break-word']"));

var deleteFolderButton =
context.Get(By.CssSelector("#folder-tree li.selected div.btn-group.folder-actions .svg-inline--fa.fa-trash"));
await deleteFolderButton.ClickReliablyAsync(context);

await context.ClickModalOkAsync();
context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

context.Missing(By.XPath("//div[text()='Example Folder' and @class='folder-name ms-2']"));
});

/// <summary>
/// Executes the <paramref name="testFunctionAsync"/> with the specified <paramref name="testName"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Atata;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Helpers;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.BasicOrchardFeaturesTesting;

/// <summary>
/// Provides a set of extension methods for testing Orchard Core media operations.
/// </summary>
public static class MediaOperationsTestingUITestContextExtensions
{
public static Task TestMediaOperationsAsync(this UITestContext context) =>
context.ExecuteTestAsync(
"Test media operations",
async () =>
{
const string mediaPath = "/Media";
var imageName = FileUploadHelper.SamplePngFileName;
var documentName = FileUploadHelper.SamplePdfFileName;

await context.GoToAdminRelativeUrlAsync(mediaPath);

context.UploadSamplePngByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line

// Workaround for pending uploads, until you make an action the page is stuck on "Uploads Pending".
context.WaitForPageLoad();
await context.ClickReliablyOnAsync(By.CssSelector("body"));

context.Exists(By.XPath($"//span[contains(text(), '{imageName}')]"));

await context
.Get(By.CssSelector($"a[href=\"/media/{imageName}\"]").OfAnyVisibility())
.ClickReliablyAsync(context);
context.SwitchToFirstWindow();

context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

context.UploadSamplePdfByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line

// Workaround for pending uploads, until you make an action the page is stuck on "Uploads Pending".
context.WaitForPageLoad();
await context.ClickReliablyOnAsync(By.CssSelector("body"));

context.Exists(By.XPath($"//span[contains(text(), '{documentName}')]"));

await context
.Get(By.XPath($"//span[contains(text(), '{documentName}')]/ancestor::tr").OfAnyVisibility())
.ClickReliablyAsync(context);

await context
.Get(By.CssSelector($"a[href=\"/media/{documentName}\"]"))
.ClickReliablyAsync(context);
context.SwitchToFirstWindow();

context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

await context
.Get(By.CssSelector("#folder-tree .treeroot .folder-actions")) // #spell-check-ignore-line
.ClickReliablyAsync(context);

context.Get(By.Id("create-folder-name")).SendKeys("Example Folder");

await context.ClickReliablyOnAsync(By.Id("modalFooterOk"));

// Wait until new folder is created.
context.Exists(
By.XPath("//div[contains(@class, 'alert-info') and contains(.,'This folder is empty')]"));

context.UploadSamplePngByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line
context.UploadSamplePdfByIdOfAnyVisibility("fileupload"); // #spell-check-ignore-line
context.WaitForPageLoad();

var image = context.Get(By.XPath($"//span[contains(text(), '{imageName}')]"));

context.Exists(By.XPath($"//span[contains(text(), '{documentName}')]"));

await image.ClickReliablyAsync(context);

await context
.Get(By.XPath($"//span[contains(text(), '{imageName}')]/ancestor::tr"))
.Get(By.CssSelector("a.btn.btn-link.btn-sm.delete-button"))
.ClickReliablyAsync(context);

await context.ClickModalOkAsync();
context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

context.Missing(By.XPath("//span[text()=' Image.png ' and @class='break-word']"));

var deleteFolderButton =
context.Get(By.CssSelector("#folder-tree li.selected div.btn-group.folder-actions .svg-inline--fa.fa-trash"));
await deleteFolderButton.ClickReliablyAsync(context);

await context.ClickModalOkAsync();
context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync(mediaPath);

context.Missing(By.XPath("//div[text()='Example Folder' and @class='folder-name ms-2']"));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Atata;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.BasicOrchardFeaturesTesting;

/// <summary>
/// Provides a set of extension methods for Orchard Core Workflows feature testing.
/// </summary>
public static class WorkflowsFeatureTestingUITestContextExtensions
{
public static Task TestWorkflowsAsync(this UITestContext context) =>
context.ExecuteTestAsync(
"Test Workflows",
async () =>
{
var workflowsPath = "/Workflows/Types";
var contentItemPublishTestSuccessMessage = "The content item was published.";

await context.EnableFeatureDirectlyAsync("OrchardCore.Workflows");
await context.GoToAdminRelativeUrlAsync(workflowsPath + "/EditProperties");

await context.ClickAndFillInWithRetriesAsync(By.Id("Name"), "Test workflow");
await context.ClickReliablyOnSubmitAsync();

await context.ClickReliablyOnAsync(By.XPath("//button[@data-activity-type='Event']"));
await context.ClickReliablyOnAsync(By.XPath("//a[contains(@href, 'ContentPublishedEvent')]"));

await context.ClickAndFillInWithRetriesAsync(By.Id("IActivity_Title"), "Content Published Trigger");
await context.SetCheckboxValueAsync(By.XPath("//input[@value='Page']"));
await context.ClickReliablyOnSubmitAsync();

await context.ClickReliablyOnAsync(By.XPath("//button[@data-activity-type='Task']"));
await context.ClickReliablyOnAsync(By.XPath("//a[contains(@href, 'NotifyTask')]"));

await context.ClickAndFillInWithRetriesAsync(By.Id("IActivity_Title"), "Content Published Notification");
await context.ClickAndFillInWithRetriesAsync(By.Id("NotifyTask_Message"), contentItemPublishTestSuccessMessage);
await context.ClickReliablyOnSubmitAsync();

var taskXPath = "//div[contains(@class, 'activity-task')]";

context.DragAndDropToOffset(By.XPath(taskXPath), 400, 0);

context.DragAndDrop(
By.XPath("//div[@class = 'jtk-endpoint jtk-endpoint-anchor jtk-draggable jtk-droppable']"), // #spell-check-ignore-line
By.XPath(taskXPath));

// We need to save the workflow early, because sometimes the editor, thus the startup task button can be
// buggy during UI testing (it won't be clicked, even if we check for its existence). This way it's
// always clicked.
await context.ClickReliablyOnSubmitAsync();
await context.ClickReliablyOnAsync(By.XPath("//div[contains(@class, 'activity-event')]"));

await context.ClickReliablyOnAsync(By.XPath("//a[@title='Startup task']"));
await context.ClickReliablyOnSubmitAsync();

context.ShouldBeSuccess("Workflow has been saved.");

var contentItemsPage = await context.GoToContentItemsPageAsync();
context.RefreshCurrentAtataContext();
contentItemsPage
.CreateNewPage()
.Title.Set("Workflows Test Page")
.Publish.ClickAndGo();

context.ShouldBeSuccess(contentItemPublishTestSuccessMessage);

// Checking if the workflow run was logged.
await context.GoToAdminRelativeUrlAsync(workflowsPath);
await context.ClickReliablyOnAsync(By.XPath("//a[text()='Test workflow']/following-sibling::a[contains(@href, 'Instances')]"));
context.Exists(By.XPath("//span[@class = 'badge text-bg-success']"));
});
}
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/Extensions/FormUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static Task FillInCodeMirrorEditorWithRetriesAsync(
public static bool IsElementChecked(this UITestContext context, By by) =>
context.Get(by.OfAnyVisibility()).GetDomProperty("checked") == bool.TrueString;

public static async Task SetCheckboxValueAsync(this UITestContext context, By by, bool isChecked)
public static async Task SetCheckboxValueAsync(this UITestContext context, By by, bool isChecked = true)
{
var element = context.Get(by.OfAnyVisibility());
var currentValue = element.GetDomProperty("checked") == bool.TrueString;
Expand Down
Loading