Skip to content

Commit

Permalink
Add example test for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoWakelin committed Feb 19, 2024
1 parent bcc5753 commit ccb2c15
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions samples/BlazorServer/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
_toastParameters = new ToastParameters();
_toastParameters.Add(nameof(MyToastComponent.Title), "I'm a custom toast component with parameters");
_toastParameters.Add(nameof(MyToastComponent.ToastParam), "I'm a parameter");
_toastParameters.Add(nameof(MyToastComponent.Status), ToastLevel.Info);
}

private void OnShowHtml()
Expand Down
1 change: 1 addition & 0 deletions samples/BlazorServer/Pages/MyToastComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ else
@code{
[Parameter] public string Title { get; set; }
[Parameter] public string ToastParam { get; set; }
[Parameter] public ToastLevel Status { get; set; }
}
3 changes: 2 additions & 1 deletion samples/BlazorWebAssembly/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
{
_toastParameters = new ToastParameters()
.Add(nameof(MyToastComponent.Title), "I'm a custom toast component with parameters")
.Add(nameof(MyToastComponent.ToastParam), "I'm a parameter");
.Add(nameof(MyToastComponent.ToastParam), "I'm a parameter")
.Add(nameof(MyToastComponent.Status), ToastLevel.Info);
}

private void OnShowHtml()
Expand Down
1 change: 1 addition & 0 deletions samples/BlazorWebAssembly/Pages/MyToastComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ else

[Parameter] public string? Title { get; set; }
[Parameter] public string? ToastParam { get; set; }
[Parameter] public ToastLevel? Status { get; set; }
}
15 changes: 14 additions & 1 deletion samples/bUnitExample/BlazoredToastTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Blazored.Toast;
using Blazored.Toast.Services;
using BlazorWebAssembly.Pages;
using Bunit;
Expand Down Expand Up @@ -109,5 +108,19 @@ public void DisplaysToastComponent()
// Assert
Assert.Equal(1, toastService.Toasts.Count(_ => _.ToastType == typeof(MyToastComponent)));
}

[Fact]
public void DisplaysToastComponentWithLevel()
{
// Arrange
var toastService = this.AddBlazoredToast();
var cut = RenderComponent<Index>();

// Act
cut.Find("#CustomButton").Click();

// Assert
Assert.Equal(ToastLevel.Info, toastService.Toasts.Single().ToastParameters!.TryGet<ToastLevel>(nameof(MyToastComponent.Status)));
}
}
}

0 comments on commit ccb2c15

Please sign in to comment.