Skip to content

Commit

Permalink
Merge pull request #59 from Lombiq/issue/SITE-63-OSOE
Browse files Browse the repository at this point in the history
SITE-63: Adjusting UI test extensions
  • Loading branch information
wAsnk authored Mar 28, 2024
2 parents bd7e34d + 662b9c3 commit 9c09c62
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using OrchardCore.Environment.Shell;
using System;

namespace Lombiq.Hosting.MediaTheme.Bridge.Helpers;

internal static class RequestUrlPrefixRemover
{
public static string RemoveIfHasPrefix(string path, ShellSettings shellSettings)
{
var requestUrlPrefix = shellSettings.RequestUrlPrefix;
if (string.IsNullOrEmpty(requestUrlPrefix) ||
!path.StartsWith("/" + requestUrlPrefix, StringComparison.OrdinalIgnoreCase))
{
return path;
}

return path[(requestUrlPrefix.Length + 1)..];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lombiq.Hosting.MediaTheme.Bridge.Constants;
using Lombiq.Hosting.MediaTheme.Bridge.Helpers;
using Microsoft.AspNetCore.Http;
using OrchardCore.Environment.Shell;
using OrchardCore.FileStorage;
Expand Down Expand Up @@ -41,13 +42,7 @@ public async Task InvokeAsync(
string assetUrl;
if (!context.IsDevelopment() || await mediaFileStore.FileExistsAsync(mediaPath))
{
assetUrl = mediaFileStore.MapPathToPublicUrl(mediaPath);

if (!string.IsNullOrEmpty(shellSettings.RequestUrlPrefix) &&
assetUrl.StartsWith("/" + shellSettings.RequestUrlPrefix, StringComparison.OrdinalIgnoreCase))
{
assetUrl = assetUrl[(shellSettings.RequestUrlPrefix.Length + 1)..];
}
assetUrl = RequestUrlPrefixRemover.RemoveIfHasPrefix(mediaFileStore.MapPathToPublicUrl(mediaPath), shellSettings);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@ namespace Lombiq.Hosting.MediaTheme.Tests.UI.Extensions;

public static class TestCaseUITestContextExtensions
{
public static async Task TestMediaThemeDeployedBehaviorAsync(this UITestContext context)
public static async Task TestMediaThemeDeployedBehaviorAsync(this UITestContext context, string tenantPrefix = null)
{
await context.ExecuteMediaThemeSampleRecipeDirectlyAsync();
await context.GoToMediaThemeTestContentPageAsync();
AssertElements(context, "v");
AssertElements(context, "v", tenantPrefix);
}

public static async Task TestMediaThemeLocalBehaviorAsync(this UITestContext context)
public static async Task TestMediaThemeLocalBehaviorAsync(this UITestContext context, string tenantPrefix = null)
{
await context.SetThemeDirectlyAsync("Lombiq.Hosting.MediaTheme.Tests.Theme");
await context.GoToHomePageAsync(onlyIfNotAlreadyThere: false);
AssertElements(context, "mediatheme");
AssertElements(context, "mediatheme", tenantPrefix);
}

private static void AssertElements(UITestContext context, string cacheBustingParameterName)
private static void AssertElements(UITestContext context, string cacheBustingParameterName, string tenantPrefix)
{
context.Exists(By.XPath($"//head//link[contains(@href, '/mediatheme/example.css?{cacheBustingParameterName}=')]").Hidden());
context.Exists(By.XPath(
$"//head//link[contains(@href, '{GetTenantUrlPrefix(tenantPrefix)}/mediatheme/example.css?{cacheBustingParameterName}=')]").Hidden());
context.Exists(By.XPath("//p[contains(., 'This is an example template hosted in Media Theme.')]"));
context.Exists(By.XPath("//img[contains(@src, '/mediatheme/example.png')]"));
context.Exists(By.XPath($"//img[contains(@src, '/mediatheme/example2.png?{cacheBustingParameterName}=')]"));
context.Exists(By.XPath($"//img[contains(@src, '{GetTenantUrlPrefix(tenantPrefix)}/mediatheme/example.png')]"));
context.Exists(By.XPath($"//img[contains(@src, '{GetTenantUrlPrefix(tenantPrefix)}/mediatheme/example2.png?{cacheBustingParameterName}=')]"));
}

private static string GetTenantUrlPrefix(string tenantName) =>
string.IsNullOrEmpty(tenantName) ? string.Empty : "/" + tenantName;
}

0 comments on commit 9c09c62

Please sign in to comment.