From c8dc266f8a908229da46aa4d27c941765c27d654 Mon Sep 17 00:00:00 2001 From: mu88 <4560672+mu88@users.noreply.github.com> Date: Sun, 23 Feb 2025 17:22:15 +0100 Subject: [PATCH] test: push coverage even more --- SonarQube.Analysis.xml | 2 +- .../WebApp/Shared/FilterLifePointsTests.cs | 48 ++++++++++++------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/SonarQube.Analysis.xml b/SonarQube.Analysis.xml index b6bfb70..b9330a6 100644 --- a/SonarQube.Analysis.xml +++ b/SonarQube.Analysis.xml @@ -1,5 +1,5 @@ - **/WebApp/Program.cs,**/App.razor,**/WebApp/Shared/*.razor.js + **/WebApp/Program.cs,**/App.razor,**/WebApp/Shared/*.razor.js,**/WebApp/wwwroot/js/Shared.js **/WebApp/wwwroot/leaflet/**/*.* diff --git a/src/Tests/Unit/WebApp/Shared/FilterLifePointsTests.cs b/src/Tests/Unit/WebApp/Shared/FilterLifePointsTests.cs index 853c37d..3c60b63 100644 --- a/src/Tests/Unit/WebApp/Shared/FilterLifePointsTests.cs +++ b/src/Tests/Unit/WebApp/Shared/FilterLifePointsTests.cs @@ -65,14 +65,15 @@ public async Task FilterByYear_ShouldShowAllMarkers_WhenChoosingDefaultYear() MarkersShouldBeDisplayed(testContext, 2); } - [Test] - public async Task FilterByYear_ShouldNotFail_WhenInputIsNoYear() + [TestCase("tralala")] + [TestCase(null)] + public async Task FilterByYear_ShouldNotFail_WhenInputIsNoYear(object? changedValue) { using var testContext = new TestContext(); using var testee = CreateTestee(testContext); ClickFilterButton(testee); - var testAction = async () => await ChangeYearSelectElementAsync(testee, "tralala"); + var testAction = async () => await ChangeYearSelectElementAsync(testee, changedValue); await testAction.Should().NotThrowAsync(); } @@ -114,14 +115,27 @@ public async Task FilterByCreator_ShouldDisableYearFiltering() YearFilteringShouldBeDisabled(testee); } + [TestCase(1953)] + [TestCase(null)] + public async Task FilterByCreator_ShouldNotFail_WhenInputIsNoCreator(object? changedValue) + { + using var testContext = new TestContext(); + using var testee = CreateTestee(testContext); + ClickFilterButton(testee); + + var testAction = async () => await ChangeCreatorSelectElementAsync(testee, changedValue); + + await testAction.Should().NotThrowAsync(); + } + [Test] - public async Task FilterByCreator_ShouldNotFail_WhenInputIsNoCreator() + public async Task FilterByCreator_ShouldDoNothing_WhenGuidsMatch() { using var testContext = new TestContext(); using var testee = CreateTestee(testContext); ClickFilterButton(testee); - var testAction = async () => await ChangeCreatorSelectElementAsync(testee, 1953); + var testAction = async () => await ChangeCreatorSelectElementAsync(testee, Guid.Empty); await testAction.Should().NotThrowAsync(); } @@ -184,16 +198,16 @@ private static IRenderedComponent CreateTestee(TestContext tes var existingLocation = TestExistingLocation.Create(); var lifePointServiceMock = Substitute.For(); - lifePointServiceMock.GetDistinctCreators().Returns(new[] { existingPerson1, existingPerson2 }); - lifePointServiceMock.GetDistinctCreators(1953).Returns(new[] { existingPerson1 }); - lifePointServiceMock.GetDistinctCreators(1954).Returns(new[] { existingPerson2 }); - lifePointServiceMock.GetDistinctYears().Returns(new[] { 1953, 1954 }); - lifePointServiceMock.GetDistinctYears(existingPerson1.Id).Returns(new[] { 1953 }); - lifePointServiceMock.GetDistinctYears(existingPerson2.Id).Returns(new[] { 1954 }); - lifePointServiceMock.GetAllLocations().Returns(new[] { existingLocation }); - lifePointServiceMock.GetAllLocations(1953).Returns(new[] { existingLocation }); - lifePointServiceMock.GetAllLocations(null, existingPerson1.Id).Returns(new[] { existingLocation }); - lifePointServiceMock.GetAllLocations(1953, existingPerson1.Id).Returns(new[] { existingLocation }); + lifePointServiceMock.GetDistinctCreators().Returns([existingPerson1, existingPerson2]); + lifePointServiceMock.GetDistinctCreators(1953).Returns([existingPerson1]); + lifePointServiceMock.GetDistinctCreators(1954).Returns([existingPerson2]); + lifePointServiceMock.GetDistinctYears().Returns([1953, 1954]); + lifePointServiceMock.GetDistinctYears(existingPerson1.Id).Returns([1953]); + lifePointServiceMock.GetDistinctYears(existingPerson2.Id).Returns([1954]); + lifePointServiceMock.GetAllLocations().Returns([existingLocation]); + lifePointServiceMock.GetAllLocations(1953).Returns([existingLocation]); + lifePointServiceMock.GetAllLocations(null, existingPerson1.Id).Returns([existingLocation]); + lifePointServiceMock.GetAllLocations(1953, existingPerson1.Id).Returns([existingLocation]); testContext.Services.AddSingleton(lifePointServiceMock); testContext.Services.AddLocalization(); @@ -209,10 +223,10 @@ private static IRenderedComponent CreateTestee(TestContext tes return testee; } - private static async Task ChangeYearSelectElementAsync(IRenderedComponent testee, object value) => + private static async Task ChangeYearSelectElementAsync(IRenderedComponent testee, object? value) => await testee.Find("[id^=\"distinctYear\"]").ChangeAsync(new ChangeEventArgs { Value = value }); - private static async Task ChangeCreatorSelectElementAsync(IRenderedComponent testee, object value) => + private static async Task ChangeCreatorSelectElementAsync(IRenderedComponent testee, object? value) => await testee.Find("[id^=\"distinctCreator\"]").ChangeAsync(new ChangeEventArgs { Value = value }); private static void DistinctCreatorsShouldBeDisplayed(IRenderedComponent testee)