Skip to content

Commit 7d7f2fa

Browse files
committed
Component Render Test
1 parent c1c2332 commit 7d7f2fa

3 files changed

Lines changed: 75 additions & 86 deletions

File tree

Lines changed: 57 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,57 @@
1-
//using AwesomeAssertions;
2-
//using MudExtensions.Docs.Pages;
3-
4-
//namespace MudExtensions.UnitTests.Components
5-
//{
6-
// [TestFixture]
7-
// public class RenderTests : BunitTest
8-
// {
9-
// [Test]
10-
// public void ApiPageRenderTest()
11-
// {
12-
// var comp = Context.Render<ApiPage>();
13-
// comp.Markup.Should().NotBeNullOrEmpty();
14-
// }
15-
16-
// [Test]
17-
// public void AnimatePageRenderTest()
18-
// {
19-
// var comp = Context.Render<AnimatePage>();
20-
// comp.Markup.Should().NotBeNullOrEmpty();
21-
// }
22-
23-
// [Test]
24-
// public void ComboBoxPageRenderTest()
25-
// {
26-
// var comp = Context.Render<ComboBoxPage>();
27-
// comp.Markup.Should().NotBeNullOrEmpty();
28-
// }
29-
30-
// [Test]
31-
// public void WheelDatePickerPageRenderTest()
32-
// {
33-
// var comp = Context.Render<DateWheelPickerPage>();
34-
// comp.Markup.Should().NotBeNullOrEmpty();
35-
// }
36-
37-
// [Test]
38-
// public void SpeedDialPageRenderTest()
39-
// {
40-
// var comp = Context.Render<SpeedDialPage>();
41-
// comp.Markup.Should().NotBeNullOrEmpty();
42-
// }
43-
44-
// [Test]
45-
// public void SplitterPageRenderTest()
46-
// {
47-
// var comp = Context.Render<SplitterPage>();
48-
// comp.Markup.Should().NotBeNullOrEmpty();
49-
// }
50-
51-
// [Test]
52-
// public void StepperPageRenderTest()
53-
// {
54-
// var comp = Context.Render<StepperExtendedPage>();
55-
// comp.Markup.Should().NotBeNullOrEmpty();
56-
// }
57-
58-
// [Test]
59-
// public void ListExtendedPageRenderTest()
60-
// {
61-
// var comp = Context.Render<ListExtendedPage>();
62-
// comp.Markup.Should().NotBeNullOrEmpty();
63-
// }
64-
65-
// [Test]
66-
// public void SelectExtendedPageRenderTest()
67-
// {
68-
// var comp = Context.Render<SelectExtendedPage>();
69-
// comp.Markup.Should().NotBeNullOrEmpty();
70-
// }
71-
72-
// [Test]
73-
// public void TextFieldExtendedPageRenderTest()
74-
// {
75-
// var comp = Context.Render<TextFieldExtendedPage>();
76-
// comp.Markup.Should().NotBeNullOrEmpty();
77-
// }
78-
79-
// [Test]
80-
// public void TransferListPageRenderTest()
81-
// {
82-
// var comp = Context.Render<TransferListPage>();
83-
// comp.Markup.Should().NotBeNullOrEmpty();
84-
// }
85-
// }
86-
//}
1+
using AwesomeAssertions;
2+
using Bunit;
3+
using Microsoft.AspNetCore.Components;
4+
using MudBlazor.Services;
5+
using MudExtensions.Utilities;
6+
using System.Reflection;
7+
8+
namespace MudExtensions.UnitTests.Components;
9+
10+
[TestFixture]
11+
public class ComponentsRenderTests : BunitTest
12+
{
13+
public static IEnumerable<Type> ComponentTypes()
14+
{
15+
var assembly = typeof(MudExtensions.MudColorProvider).Assembly;
16+
17+
return assembly
18+
.GetTypes()
19+
.Where(t =>
20+
t.IsClass &&
21+
!t.IsAbstract &&
22+
!t.IsGenericTypeDefinition &&
23+
typeof(IComponent).IsAssignableFrom(t) &&
24+
t.IsPublic &&
25+
t.GetCustomAttribute<ExcludeFromSmokeTest>() == null);
26+
}
27+
28+
[SetUp]
29+
public void Setup()
30+
{
31+
Context.Services.AddMudServices();
32+
Context.JSInterop.Mode = JSRuntimeMode.Loose;
33+
}
34+
35+
[TestCaseSource(nameof(ComponentTypes))]
36+
public void Component_Should_Render(Type componentType)
37+
{
38+
try
39+
{
40+
var cut = Context.Render(builder =>
41+
{
42+
builder.OpenComponent(0, componentType);
43+
builder.CloseComponent();
44+
});
45+
46+
cut.Should().NotBeNull();
47+
}
48+
catch (Exception ex)
49+
{
50+
Assert.Fail(
51+
$"Component render FAILED: {componentType.FullName}\n" +
52+
$"Exception: {ex.GetType().Name}\n" +
53+
$"Message: {ex.Message}"
54+
);
55+
}
56+
}
57+
}

CodeBeam.MudBlazor.Extensions/Components/StepperExtended/MudStepExtended.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using Microsoft.AspNetCore.Components;
22
using MudBlazor;
33
using MudBlazor.Utilities;
4+
using MudExtensions.Utilities;
45

56
namespace MudExtensions
67
{
78
/// <summary>
89
///
910
/// </summary>
11+
[ExcludeFromSmokeTest]
1012
public partial class MudStepExtended : MudComponentBase, IDisposable
1113
{
1214
/// <summary>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+

2+
namespace MudExtensions.Utilities
3+
{
4+
/// <summary>
5+
/// Indicates that a class should be excluded from automated test discovery and execution.
6+
/// </summary>
7+
/// <remarks>Apply this attribute to classes that should not be considered by test frameworks or test
8+
/// runners. This can be useful for utility, base, or helper classes that are not intended to be executed as
9+
/// tests.
10+
/// </remarks>
11+
[AttributeUsage(AttributeTargets.Class)]
12+
public sealed class ExcludeFromSmokeTest : Attribute
13+
{
14+
15+
}
16+
}

0 commit comments

Comments
 (0)