Skip to content

Commit

Permalink
Merge pull request #754 from Lombiq/issue/OSOE-770-re
Browse files Browse the repository at this point in the history
OSOE-770: Add support for structured html-validate output
  • Loading branch information
DemeSzabolcs committed May 12, 2024
2 parents 4a8a030 + 0535c14 commit 227f477
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
8 changes: 1 addition & 7 deletions test/Lombiq.OSOCE.Tests.UI/Lombiq.OSOCE.Tests.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<Content Include="BehaviorWalkthroughsTests.htmlvalidate.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
<Content Include="BehaviorWalkthroughsTests.htmlvalidate.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lombiq.Privacy.Tests.UI.Extensions;
using Lombiq.Tests.UI.Extensions;
using Shouldly;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -41,13 +40,14 @@ public async Task ConsentBannerShouldWorkWithRazorAndLiquidBasedThemes()
await ExecuteTestAfterSetupAsync(
context => context.TestConsentBannerWithThemeAsync("TheTheme"),
configuration => configuration.HtmlValidationConfiguration.AssertHtmlValidationResultAsync =
async validationResult =>
validationResult =>
{
// Error filtering due to https://github.com/OrchardCMS/OrchardCore/issues/15222,
// can be removed once it is resolved.
var errors = (await validationResult.GetErrorsAsync())
.Where(error => !error.ContainsOrdinalIgnoreCase("Prefer to use the native <button> element"));
errors.ShouldBeEmpty();
var errors = validationResult.GetParsedErrors()
.Where(error => error.RuleId is not "prefer-native-element");
errors.ShouldBeEmpty(HtmlValidationResultExtensions.GetParsedErrorMessageString(errors));
return Task.CompletedTask;
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.UIKit.Tests.UI.Extensions;
using Shouldly;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -21,15 +20,16 @@ public Task UIKitShowcasePageShouldBeCorrect()
=> ExecuteTestAfterSetupAsync(
context => context.TestUIKitShowcaseBehaviorAsync(),
configuration => configuration.HtmlValidationConfiguration.AssertHtmlValidationResultAsync =
async validationResult =>
{
// Error filtering due to https://github.com/OrchardCMS/OrchardCore/issues/15222,
// can be removed once it is resolved.
var errors = (await validationResult.GetErrorsAsync())
.Where(error =>
!error.ContainsOrdinalIgnoreCase("Prefer to use the native <button> element") &&
!error.ContainsOrdinalIgnoreCase("<button> must have accessible text") &&
!error.ContainsOrdinalIgnoreCase("Redundant role \"button\" on <button>"));
errors.ShouldBeEmpty();
});
validationResult =>
{
// Error filtering due to https://github.com/OrchardCMS/OrchardCore/issues/15222,
// can be removed once it is resolved.
var errors = validationResult.GetParsedErrors()
.Where(error =>
error.RuleId is not "prefer-native-element" and
not "text-content" and
not "no-redundant-role");
errors.ShouldBeEmpty(HtmlValidationResultExtensions.GetParsedErrorMessageString(errors));
return Task.CompletedTask;
});
}
11 changes: 6 additions & 5 deletions test/Lombiq.OSOCE.Tests.UI/Tests/ModuleTests/BehaviorVueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ public BehaviorVueTests(ITestOutputHelper testOutputHelper)
"Failed to load resource: the server responded with a status of 404"))));
});

private static async Task AssertHtmValidationResultAsync(HtmlValidationResult validationResult)
private static Task AssertHtmValidationResultAsync(HtmlValidationResult validationResult)
{
var errors = (await validationResult.GetErrorsAsync())
var errors = validationResult.GetParsedErrors()
.Where(error =>
!error.ContainsOrdinalIgnoreCase("The autoplay attribute is not allowed on <video>")
&& !error.ContainsOrdinalIgnoreCase("title text cannot be longer than 70 characters"));
errors.ShouldBeEmpty();
error.RuleId is not "no-autoplay" and
not "long-title");
errors.ShouldBeEmpty(HtmlValidationResultExtensions.GetParsedErrorMessageString(errors));
return Task.CompletedTask;
}
}

0 comments on commit 227f477

Please sign in to comment.