Skip to content

Commit

Permalink
test: add additional test for nested html with for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
scottsauber committed Mar 17, 2024
1 parent be79633 commit 94f6943
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/bunit.web.query.tests/Labels/LabelQueryExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void Test020(string htmlElementWithLabel)
var cut = RenderComponent<Wrapper>(ps =>
ps.AddChildContent($"""
<label>
<p><span>Test Label</p></span>
<p><span>Test Label</span></p>
<{htmlElementWithLabel} id="{htmlElementWithLabel}-wrapped-label" />
</label>
"""));
Expand All @@ -339,4 +339,24 @@ public void Test020(string htmlElementWithLabel)
input.NodeName.ShouldBe(htmlElementWithLabel, StringCompareShould.IgnoreCase);
input.Id.ShouldBe($"{htmlElementWithLabel}-wrapped-label");
}

[Theory(DisplayName = "Should return back associated element with label when using the for attribute with label containing nested html")]
[MemberData(nameof(HtmlElementsThatCanHaveALabel))]
public void Test021(string htmlElementWithLabel)
{
var labelText = $"Label for {htmlElementWithLabel} 1";
var cut = RenderComponent<Wrapper>(ps =>
ps.AddChildContent($"""
<label for="{htmlElementWithLabel}-with-label">
<p><span>{labelText}</span></p>
</label>
<{htmlElementWithLabel} id="{htmlElementWithLabel}-with-label" />
"""));

var input = cut.FindByLabelText(labelText);

input.ShouldNotBeNull();
input.NodeName.ShouldBe(htmlElementWithLabel, StringCompareShould.IgnoreCase);
input.Id.ShouldBe($"{htmlElementWithLabel}-with-label");
}
}

0 comments on commit 94f6943

Please sign in to comment.