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-423: Offer Media management testing as part of TestBasicOrchardFeaturesAsync() too in Lombiq.UITestingToolbox #226

Merged
merged 20 commits into from
Dec 14, 2022
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Atata;
using Lombiq.Tests.UI.Constants;
using Lombiq.Tests.UI.Helpers;
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;
Expand Down Expand Up @@ -107,6 +109,7 @@ public static async Task TestBasicOrchardFeaturesExceptSetupAsync(this UITestCon
await context.TestLoginAsync();
await context.TestContentOperationsAsync();
await context.TestTurningFeatureOnAndOffAsync();
await context.TestMediaOperationsAsync();
await context.TestLogoutAsync();
}

Expand Down Expand Up @@ -506,6 +509,103 @@ public static Task TestTurningFeatureOnAndOffAsync(
.SearchForFeature(featureName).IsEnabled.Should.Equal(originalEnabledState));
});

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

await context.GoToAdminRelativeUrlAsync("/Media");

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
.Get(By.XPath($"//span[contains(text(), '{imageName}')]"))
.Text
.ShouldBe(FileUploadHelper.SamplePngFileName);

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

context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync("/Media");

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
.Get(By.XPath($"//span[contains(text(), '{documentName}')]"))
.Text
.ShouldBe(FileUploadHelper.SamplePdfFileName);

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

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

context.WaitForPageLoad();
await context.GoToAdminRelativeUrlAsync("/Media");

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.Get(By.Id("modalFooterOk")).ClickReliablyAsync(context);

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}')]"));
image.Text.ShouldBe(FileUploadHelper.SamplePngFileName);
var pdf = context
.Get(By.XPath($"//span[contains(text(), '{documentName}')]"));
pdf.Text.ShouldBe(FileUploadHelper.SamplePdfFileName);

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();
Piedone marked this conversation as resolved.
Show resolved Hide resolved

var fileNames = context.GetAll(By.CssSelector("#mediaContainerMain tbody tr .break-word"));
foreach (var fileName in fileNames)
{
fileName.Text.ShouldNotBe(FileUploadHelper.SamplePngFileName);
}

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();
Piedone marked this conversation as resolved.
Show resolved Hide resolved

var folders = context.GetAll(By.CssSelector("#folder-tree ol li .folder-name"));
foreach (var folder in folders)
{
folder.Text.ShouldNotBe("Example Folder");
}
});

/// <summary>
/// Executes the <paramref name="testFunctionAsync"/> with the specified <paramref name="testName"/>.
/// </summary>
Expand Down
13 changes: 9 additions & 4 deletions Lombiq.Tests.UI/Helpers/FileUploadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ public static class FileUploadHelper
{
private static readonly string BasePath = Path.Combine(Environment.CurrentDirectory, "SampleUploadFiles");

public static readonly string SamplePdfPath = Path.Combine(BasePath, "Document.pdf");
public static readonly string SamplePngPath = Path.Combine(BasePath, "Image.png");
public static readonly string SampleDocxPath = Path.Combine(BasePath, "UploadingTestFileDOCX.docx");
public static readonly string SampleXlsxPath = Path.Combine(BasePath, "UploadingTestFileXLSX.xlsx");
public static readonly string SamplePdfFileName = "Document.pdf";
public static readonly string SamplePngFileName = "Image.png";
public static readonly string SampleDocxFileName = "UploadingTestFileDOCX.docx";
public static readonly string SampleXlsxFileName = "UploadingTestFileXLSX.xlsx";

public static readonly string SamplePdfPath = Path.Combine(BasePath, SamplePdfFileName);
public static readonly string SamplePngPath = Path.Combine(BasePath, SamplePngFileName);
public static readonly string SampleDocxPath = Path.Combine(BasePath, SampleDocxFileName);
public static readonly string SampleXlsxPath = Path.Combine(BasePath, SampleXlsxFileName);
}