Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable compact condition #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions PrettyBlazor.Tests/Conditions/ConditionTests.Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,38 @@ public void ShouldRenderMatchComponentIfEvaluationIsTrue()
this.renderedConditionComponent.FindComponent<SomeNoMatchComponent>());
}

[Fact]
public void ShouldRenderChildContentIfEvaluationIsTrueAndNoMatchComponentWasGiven()
{
// given
var expectedMatchFragment = CreateRenderFragment(typeof(SomeMatchComponent));

var componentParameters = new ComponentParameter[]
{
ComponentParameter.CreateParameter(
name: nameof(Condition.Evaluation),
value: true),

ComponentParameter.CreateParameter(
name: nameof(Condition.ChildContent),
value: expectedMatchFragment),
};

// when
this.renderedConditionComponent =
RenderComponent<Condition>(componentParameters);

// then
this.renderedConditionComponent.Instance.Evaluation
.Should().BeTrue();

this.renderedConditionComponent.Instance.ChildContent
.Should().BeEquivalentTo(expectedMatchFragment);

this.renderedConditionComponent.FindComponent<SomeMatchComponent>().Instance
.Should().NotBeNull();
}

[Fact]
public void ShouldRenderNoMatchComponentIfEvaluationIsFalse()
{
Expand Down
13 changes: 10 additions & 3 deletions PrettyBlazor/Condition.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
@if (Evaluation is true)
@if (Evaluation)
{
@Match
@if (Match is null)
{
@ChildContent
}
else
{
@Match
}
}
else
{
@NotMatch
}
}
6 changes: 6 additions & 0 deletions PrettyBlazor/Condition.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ public partial class Condition : ComponentBase

[Parameter]
public RenderFragment NotMatch { get; set; }

/// <summary>
/// Only shown if <see cref="Evaluation"/> is <see cref="true"/> and <see cref="Match"/> is not set.
/// </summary>
[Parameter]
public RenderFragment ChildContent { get; set; }
}
}
1 change: 0 additions & 1 deletion PrettyBlazor/PrettyBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<Content Include="License.txt" />
</ItemGroup>


<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>
Expand Down