From 33689034f55024864a85094789e52f7dc0e23008 Mon Sep 17 00:00:00 2001 From: Andrea De Pirro Date: Wed, 4 Nov 2026 16:56:06 +0100 Subject: [PATCH] Snapshot the authorization section tests Three tests in `AuthorizationSectionRenderingTests` checked the same rendered block with 21 `Contain`/`NotContain` assertions. Each now compares against a verified HTML snapshot, plus one targeted assertion that states its intent. The four small tests stay as they are. Co-Authored-By: Claude Sonnet 5.5 --- ...HasNoTabsAndShowsBothSchemes.verified.html | 39 ++++++++++++++ ...sSeparateNamesJoinedWithPlus.verified.html | 29 ++++++++++ ...haresOneTabAndSaysToSendBoth.verified.html | 53 +++++++++++++++++++ .../AuthorizationSectionRenderingTests.cs | 24 +++------ 4 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_OneRequirementWithTwoSchemes_HasNoTabsAndShowsBothSchemes.verified.html create mode 100644 tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_PrivilegesNeededTogether_AreSummarisedAsSeparateNamesJoinedWithPlus.verified.html create mode 100644 tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_RequirementWithTwoSchemes_SharesOneTabAndSaysToSendBoth.verified.html diff --git a/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_OneRequirementWithTwoSchemes_HasNoTabsAndShowsBothSchemes.verified.html b/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_OneRequirementWithTwoSchemes_HasNoTabsAndShowsBothSchemes.verified.html new file mode 100644 index 0000000000..ae7982c115 --- /dev/null +++ b/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_OneRequirementWithTwoSchemes_HasNoTabsAndShowsBothSchemes.verified.html @@ -0,0 +1,39 @@ +
+

+ Authentication + +

+
+
+
+

Send all of these together.

+

Basic

+
+
+
+							Authorization: Basic <credentials>
+						
+
+
+

Api key

+
+
+
+							X-Key: <value>
+						
+
+
+
+
+
+
diff --git a/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_PrivilegesNeededTogether_AreSummarisedAsSeparateNamesJoinedWithPlus.verified.html b/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_PrivilegesNeededTogether_AreSummarisedAsSeparateNamesJoinedWithPlus.verified.html new file mode 100644 index 0000000000..fe2909fe9a --- /dev/null +++ b/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_PrivilegesNeededTogether_AreSummarisedAsSeparateNamesJoinedWithPlus.verified.html @@ -0,0 +1,29 @@ +
+

+ Required privileges + +

+
+
+
+
+ Privileges + integrations-all + and + fleet-agent-policies-all +
+
+
+
+
diff --git a/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_RequirementWithTwoSchemes_SharesOneTabAndSaysToSendBoth.verified.html b/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_RequirementWithTwoSchemes_SharesOneTabAndSaysToSendBoth.verified.html new file mode 100644 index 0000000000..db8af01f5d --- /dev/null +++ b/tests/Elastic.ApiExplorer.Tests/.snapshots/AuthorizationSectionRenderingTests/Render_RequirementWithTwoSchemes_SharesOneTabAndSaysToSendBoth.verified.html @@ -0,0 +1,53 @@ +
+

+ Authentication + +

+
+
+ + +
+

Send all of these together.

+

Basic

+
+
+
+							Authorization: Basic <credentials>
+						
+
+
+

Api key

+
+
+
+							X-Key: <value>
+						
+
+
+
+ + +
+
+
+
+							Authorization: Bearer <token>
+						
+
+
+
+
+
+
diff --git a/tests/Elastic.ApiExplorer.Tests/AuthorizationSectionRenderingTests.cs b/tests/Elastic.ApiExplorer.Tests/AuthorizationSectionRenderingTests.cs index c9947ecfc9..62f499e3c2 100644 --- a/tests/Elastic.ApiExplorer.Tests/AuthorizationSectionRenderingTests.cs +++ b/tests/Elastic.ApiExplorer.Tests/AuthorizationSectionRenderingTests.cs @@ -6,6 +6,7 @@ using Elastic.ApiExplorer.Operations; using Elastic.ApiExplorer.Operations._Partials; using Microsoft.AspNetCore.Html; +using Nullean.Snapshots.Html; using RazorSlices; namespace Elastic.ApiExplorer.Tests; @@ -54,10 +55,8 @@ public async Task Render_RequirementWithTwoSchemes_SharesOneTabAndSaysToSendBoth new AuthRequirement([Scheme("bearer", "Bearer", "Authorization: Bearer ")]) ); - html.Should().Contain(""); - html.Should().Contain(""); + html.Should().MatchHtmlSnapshot(); html.Should().Contain("Send all of these together."); - html.Should().Contain("

Basic

").And.Contain("

Api key

"); } [Test] @@ -68,11 +67,8 @@ public async Task Render_OneRequirementWithTwoSchemes_HasNoTabsAndShowsBothSchem Scheme("key", "Api key", "X-Key: ") ])); - html.Should().NotContain("api-tabs"); - html.Should().NotContain("tabs-label"); - html.Should().Contain("Send all of these together."); - html.Should().Contain("

Basic

").And.Contain("

Api key

"); - html.Should().Contain("Authorization: Basic <credentials>").And.Contain("X-Key: <value>"); + html.Should().MatchHtmlSnapshot(); + html.Should().NotContain("api-tabs", "a single requirement needs no tabs"); } [Test] @@ -80,16 +76,8 @@ public async Task Render_PrivilegesNeededTogether_AreSummarisedAsSeparateNamesJo { var html = await RenderPrivileges(new PrivilegeRow("Privileges", ["integrations-all", "fleet-agent-policies-all"], "and")); - html.Should().Contain("data-param-section"); - html.Should().Contain("id=\"required-privileges\""); - html.Should().Contain(""); - html.Should().Contain(""); - html.Should().Contain("api-param-summary is-all"); - html.Should().Contain("id=\"required-privileges-list\""); - html.Should().Contain("id=\"required-privileges-list\">", "the body has no hidden attribute, so it shows on load"); - html.Should().NotContain("id=\"required-privileges-list\" hidden"); - html.Should().MatchRegex("aria-expanded=\"true\"\\s+aria-controls=\"required-privileges-list\""); - html.Should().Contain("integrations-all", "the rows are still listed in the body"); + html.Should().MatchHtmlSnapshot(); + html.Should().NotContain("id=\"required-privileges-list\" hidden", "the body has no hidden attribute, so it shows on load"); } [Test]