-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for unit testing of components (#27)
* working on: fixing unit testing generator component * working on generator unit testing * fixed unit testig for components --------- Co-authored-by: blfuentes <[email protected]>
- Loading branch information
Showing
10 changed files
with
94 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@using GuitarStringTensionCalculator.Components.Pages | ||
@using MudBlazor | ||
|
||
<MudPopoverProvider /> | ||
|
||
<Generator /> | ||
|
||
@code { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,71 @@ | ||
using Bunit; | ||
using _pages = GuitarStringTensionCalculator.Components.Pages; | ||
using Xunit; | ||
using GSTC.bUnit.Components; | ||
using MudBlazor; | ||
using MudBlazor.Services; | ||
using Shouldly; | ||
using Microsoft.AspNetCore.Components; | ||
using Xunit; | ||
|
||
namespace GSTC.bUnit | ||
{ | ||
public class GeneratorComponentTest : TestContext | ||
{ | ||
[Fact] | ||
public void InitialHtmlIsCorrect() | ||
{ | ||
// Arrange - renders the Generator component | ||
var cut = RenderComponent<_pages.Generator>(); | ||
cut.Find("#_result_numberofstrings").GetAttribute("value").ShouldBe("0"); | ||
cut.Find("select").Change(new ChangeEventArgs() { Value = "6" }); | ||
cut.Find("#_result_numberofstrings").GetAttribute("value").ShouldBe("6"); | ||
cut.Find("select").Change(new ChangeEventArgs() { Value = "" }); | ||
cut.Find("#_result_numberofstrings").GetAttribute("value").ShouldBe("6"); | ||
// Arrange | ||
using var ctx = new Bunit.TestContext(); | ||
|
||
ctx.JSInterop.Mode = JSRuntimeMode.Loose; | ||
ctx.Services.AddMudServices(config => | ||
{ | ||
config.SnackbarConfiguration.PreventDuplicates = true; | ||
config.SnackbarConfiguration.NewestOnTop = false; | ||
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.TopCenter; | ||
config.PopoverOptions.ThrowOnDuplicateProvider = false; | ||
}); | ||
|
||
// Act | ||
var component = ctx.RenderComponent<GeneratorTestWrapper>(); | ||
var numOfStringsSelect = component.FindAll("#select-numofstrings"); | ||
var scaleLengthSelect = component.FindAll("#select-scalelength"); | ||
var semitonesSelect = component.FindAll("#select-semitones"); | ||
var tuningSelect = component.FindAll("#select-tuning"); | ||
|
||
// Assert | ||
component.ShouldNotBeNull(); | ||
numOfStringsSelect.Count.ShouldBe(1); | ||
scaleLengthSelect.Count.ShouldBe(1); | ||
semitonesSelect.Count.ShouldBe(1); | ||
tuningSelect.ShouldBeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void SelectNumOfStrings() | ||
{ | ||
// Arrange | ||
using var ctx = new Bunit.TestContext(); | ||
|
||
ctx.JSInterop.Mode = JSRuntimeMode.Loose; | ||
ctx.Services.AddMudServices(config => | ||
{ | ||
config.SnackbarConfiguration.PreventDuplicates = true; | ||
config.SnackbarConfiguration.NewestOnTop = false; | ||
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.TopCenter; | ||
config.PopoverOptions.ThrowOnDuplicateProvider = false; | ||
}); | ||
|
||
// Act & Assert | ||
var component = ctx.RenderComponent<GeneratorTestWrapper>(); | ||
var select = component.FindComponents<MudSelect<string>>()[0]; | ||
select.Instance.Value.ShouldBeNull(); | ||
|
||
var input = component.Find("div.mud-input-control"); | ||
input.Click(); | ||
|
||
var items = component.FindAll("div.mud-list-item"); | ||
items.Count.ShouldBeGreaterThan(0); | ||
items[1].Click(); | ||
select.Instance.Value.ShouldBe("7"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters