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
117 changes: 44 additions & 73 deletions CodeBeam.MudBlazor.Extensions.UnitTests/Components/RenderTests.cs
Original file line number Diff line number Diff line change
@@ -1,86 +1,57 @@
using AwesomeAssertions;
using MudExtensions.Docs.Pages;
using Bunit;
using Microsoft.AspNetCore.Components;
using MudBlazor.Services;
using MudExtensions.Utilities;
using System.Reflection;

namespace MudExtensions.UnitTests.Components
namespace MudExtensions.UnitTests.Components;

[TestFixture]
public class ComponentsRenderTests : BunitTest
{
[TestFixture]
public class RenderTests : BunitTest
public static IEnumerable<Type> ComponentTypes()
{
[Test]
public void ApiPageRenderTest()
{
var comp = Context.Render<ApiPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void AnimatePageRenderTest()
{
var comp = Context.Render<AnimatePage>();
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void ComboBoxPageRenderTest()
{
var comp = Context.Render<ComboBoxPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void WheelDatePickerPageRenderTest()
{
var comp = Context.Render<DateWheelPickerPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void SpeedDialPageRenderTest()
{
var comp = Context.Render<SpeedDialPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void SplitterPageRenderTest()
{
var comp = Context.Render<SplitterPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void StepperPageRenderTest()
{
var comp = Context.Render<StepperExtendedPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}
var assembly = typeof(MudExtensions.MudColorProvider).Assembly;

return assembly
.GetTypes()
.Where(t =>
t.IsClass &&
!t.IsAbstract &&
!t.IsGenericTypeDefinition &&
typeof(IComponent).IsAssignableFrom(t) &&
t.IsPublic &&
t.GetCustomAttribute<ExcludeFromSmokeTest>() == null);
}

[Test]
public void ListExtendedPageRenderTest()
{
var comp = Context.Render<ListExtendedPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}
[SetUp]
public void Setup()
{
Context.Services.AddMudServices();
Context.JSInterop.Mode = JSRuntimeMode.Loose;
}

[Test]
public void SelectExtendedPageRenderTest()
[TestCaseSource(nameof(ComponentTypes))]
public void Component_Should_Render(Type componentType)
{
try
{
var comp = Context.Render<SelectExtendedPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}
var cut = Context.Render(builder =>
{
builder.OpenComponent(0, componentType);
builder.CloseComponent();
});

[Test]
public void TextFieldExtendedPageRenderTest()
{
var comp = Context.Render<TextFieldExtendedPage>();
comp.Markup.Should().NotBeNullOrEmpty();
cut.Should().NotBeNull();
}

[Test]
public void TransferListPageRenderTest()
catch (Exception ex)
{
var comp = Context.Render<TransferListPage>();
comp.Markup.Should().NotBeNullOrEmpty();
Assert.Fail(
$"Component render FAILED: {componentType.FullName}\n" +
$"Exception: {ex.GetType().Name}\n" +
$"Message: {ex.Message}"
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using AwesomeAssertions;
using Bunit;
using Microsoft.AspNetCore.Components;
using MudExtensions.Docs.Pages;
using NUnit.Framework;
using System.Reflection;

namespace MudExtensions.UnitTests.Components;

[TestFixture]
public class DocsPagesRenderTests : BunitTest
{
public static IEnumerable<Type> DocsPages()
{
return typeof(ApiPage).Assembly
.GetTypes()
.Where(t =>
t.IsClass &&
!t.IsAbstract &&
typeof(IComponent).IsAssignableFrom(t) &&
t.Namespace?.StartsWith("MudExtensions.Docs.Pages") == true &&
t.GetCustomAttribute<RouteAttribute>() != null);
}

[TestCaseSource(nameof(DocsPages))]
public void All_Docs_Pages_Should_Render(Type pageType)
{
var cut = Context.Render(builder =>
{
builder.OpenComponent(0, pageType);
builder.CloseComponent();
});

cut.Markup.Should().NotBeNullOrWhiteSpace();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
using MudBlazor.Utilities;
using MudExtensions.Utilities;

namespace MudExtensions
{
/// <summary>
///
/// </summary>
[ExcludeFromSmokeTest]
public partial class MudStepExtended : MudComponentBase, IDisposable
{
/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions CodeBeam.MudBlazor.Extensions/Utilities/ExcludeFromSmokeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

namespace MudExtensions.Utilities
{
/// <summary>
/// Indicates that a class should be excluded from automated test discovery and execution.
/// </summary>
/// <remarks>Apply this attribute to classes that should not be considered by test frameworks or test
/// runners. This can be useful for utility, base, or helper classes that are not intended to be executed as
/// tests.
/// </remarks>
[AttributeUsage(AttributeTargets.Class)]
public sealed class ExcludeFromSmokeTest : Attribute
{

}
}
Loading