Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ All notable changes to **bUnit** will be documented in this file. The project ad

## [Unreleased]

## [1.39.5] - 2025-04-04

### Fixed

- Do not set the `Uri` or `BaseUri` property on the `FakeNavigationManager` if navigation is prevented by a handler on `net7.0` or greater. Reported and fixed by [@ayyron-dev](https://github.com/ayyron-dev) in [#1647](https://github.com/bUnit-dev/bUnit/issues/1647)
- Use default renderer properties for AngleSharp. Reported by [@jtleaming](https://github.com/jtleaming) in [#1692].
- `FindComponents` throws an exception, when a base and derived class was searched for. Reported by [@BlueDragon709](https://github.com/BlueDragon709) in [#1691].

## [1.38.5] - 2025-01-12

Expand Down Expand Up @@ -1443,7 +1447,8 @@ The latest version of the library is availble on NuGet:
- **Wrong casing on keyboard event dispatch helpers.**
The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`.

[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.38.5...HEAD
[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.39.5...HEAD
[1.39.5]: https://github.com/bUnit-dev/bUnit/compare/v1.38.5...1.39.5
[1.38.5]: https://github.com/bUnit-dev/bUnit/compare/v1.37.7...v1.38.5
[1.37.7]: https://github.com/bUnit-dev/bUnit/compare/v1.36.0...1.37.7
[1.36.0]: https://github.com/bUnit-dev/bUnit/compare/v1.35.3...v1.36.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). T
<table border="0">
<tr>
<td align="center" width="120">
<a href="https://github.com/syncfusion">
<a href="https://www.syncfusion.com/blazor-components?utm_source=bunit&utm_medium=cpc&utm_campaign=bunit_blazor_bancy25">
<img class="avatar" src="https://avatars.githubusercontent.com/u/1699795?s=460" width="72" height="72" alt="@syncfusion" />
<br />
Syncfusion
Expand Down
2 changes: 1 addition & 1 deletion docs/site/docs/verification/semantic-html-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Here are the customization options you have available to you:
```html
<header>
<h1 id="head-1" diff:ignoreCase>HeLLo <em>world</em></h1>
</header
</header>
```

To perform case insensitive comparison of the text inside the `id` attribute, do the following:
Expand Down
7 changes: 6 additions & 1 deletion docs/site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ bUnit is available on NuGet in various incarnations. Most users should just pick
A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). The higher tier sponsors are:

<div class="d-flex flex-row mb-3">
<a href="https://github.com/syncfusion" class="d-block p-3 text-center">
<a href="https://www.syncfusion.com/blazor-components?utm_source=bunit&utm_medium=cpc&utm_campaign=bunit_blazor_bancy25" class="d-block p-3 text-center">
<img class="avatar avatar rounded-circle" src="https://avatars.githubusercontent.com/u/1699795?s=460" width="72" height="72" alt="@syncfusion" />
<br />
Syncfusion
</a>
<a href="https://github.com/JetBrainsOfficial" class="d-block p-3 text-center">
<img class="avatar avatar rounded-circle" src="https://avatars.githubusercontent.com/u/60931315?v=4" width="72" height="72" alt="@JetBrainsOfficial" />
<br />
JetBrains
</a>
</div>

## Contributors
Expand Down
12 changes: 10 additions & 2 deletions src/bunit/Rendering/BunitHtmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections;
using System.Diagnostics;
using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
using Bunit.Diffing;
Expand Down Expand Up @@ -28,7 +29,8 @@ public sealed class BunitHtmlParser : IDisposable
/// with a AngleSharp context without a <see cref="BunitRenderer"/> registered.
/// </summary>
public BunitHtmlParser()
: this(Configuration.Default.WithCss().With(new HtmlComparer())) { }
: this(Configuration.Default.WithCss()
.With(new HtmlComparer())) { }

/// <summary>
/// Initializes a new instance of the <see cref="BunitHtmlParser"/> class
Expand All @@ -43,7 +45,13 @@ public BunitHtmlParser(HtmlComparer htmlComparer, BunitContext bunitContext)

private BunitHtmlParser(IConfiguration angleSharpConfiguration)
{
var config = angleSharpConfiguration.With(this);
var config = angleSharpConfiguration
.With(this)
.WithRenderDevice(new DefaultRenderDevice
{
ViewPortWidth = 1920,
ViewPortHeight = 1080,
});
context = BrowsingContext.New(config);
var parseOptions = new HtmlParserOptions
{
Expand Down
34 changes: 0 additions & 34 deletions src/bunit/Rendering/BunitRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,40 +634,6 @@ private IRenderedComponent<TComponent> GetRenderedComponent<TComponent>(int comp
return (IRenderedComponent<TComponent>)result;
}

/// <summary>
/// Populates the <paramref name="framesCollection"/> with <see cref="ArrayRange{RenderTreeFrame}"/>
/// starting with the one that belongs to the component with ID <paramref name="componentId"/>.
/// </summary>
private void LoadRenderTreeFrames(int componentId, RenderTreeFrameDictionary framesCollection)
{
var frames = GetOrLoadRenderTreeFrame(framesCollection, componentId);

for (var i = 0; i < frames.Count; i++)
{
ref var frame = ref frames.Array[i];

if (frame.FrameType == RenderTreeFrameType.Component && !framesCollection.Contains(frame.ComponentId))
{
LoadRenderTreeFrames(frame.ComponentId, framesCollection);
}
}
}

/// <summary>
/// Gets the <see cref="ArrayRange{RenderTreeFrame}"/> from the <paramref name="framesCollection"/>.
/// If the <paramref name="framesCollection"/> does not contain the frames, they are loaded into it first.
/// </summary>
private ArrayRange<RenderTreeFrame> GetOrLoadRenderTreeFrame(RenderTreeFrameDictionary framesCollection, int componentId)
{
if (!framesCollection.TryGetValue(componentId, out var frames))
{
frames = GetCurrentRenderTreeFrames(componentId);
framesCollection.Add(componentId, frames);
}

return frames;
}

/// <inheritdoc/>
protected override void HandleException(Exception exception)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="my-component" style="width: 5%">
</div>
41 changes: 41 additions & 0 deletions tests/bunit.tests/Rendering/RenderedComponentTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AngleSharp.Dom;
using Bunit.Rendering;

namespace Bunit;
Expand Down Expand Up @@ -219,4 +220,44 @@ public void Test022()

Should.Throw<ComponentDisposedException>(() => target.Markup);
}

[Fact(DisplayName = "Searching first for derived component and then base component finds correct (#1691)")]
public void Test023()
{
var cut = Render<Wrapper>(
ps => ps.AddChildContent<BaseComponent>()
.AddChildContent<DerivedComponent>());

Should.NotThrow(() =>
{
cut.FindComponents<BaseComponent>();
cut.FindComponents<DerivedComponent>();
});
}

[Fact(DisplayName = "Using relative units in style attribute can be retrieved")]
public void Test024()
{
var cut = Render<ComponentWithRelativeUnitAsWidth>();

var text = cut.Find(".my-component").GetInnerText();

text.ShouldNotBeNull();
}

private class BaseComponent : ComponentBase
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddContent(0, "base");
}
}

private sealed class DerivedComponent : BaseComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddContent(0, "derived");
}
}
}