Skip to content

Commit

Permalink
Merge pull request #226 from Lombiq/issue/OSOE-423
Browse files Browse the repository at this point in the history
OSOE-423: Offer Media management testing as part of TestBasicOrchardFeaturesAsync() too in Lombiq.UITestingToolbox
  • Loading branch information
Piedone authored Dec 14, 2022
2 parents 29df808 + f9fe726 commit 9a9898c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 4 deletions.
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();

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();

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);
}

0 comments on commit 9a9898c

Please sign in to comment.