Skip to content

Commit

Permalink
test: push coverage even more
Browse files Browse the repository at this point in the history
  • Loading branch information
mu88 committed Feb 23, 2025
1 parent d1d2674 commit c8dc266
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion SonarQube.Analysis.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<SonarQubeAnalysisProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
<Property Name="sonar.coverage.exclusions">**/WebApp/Program.cs,**/App.razor,**/WebApp/Shared/*.razor.js</Property>
<Property Name="sonar.coverage.exclusions">**/WebApp/Program.cs,**/App.razor,**/WebApp/Shared/*.razor.js,**/WebApp/wwwroot/js/Shared.js</Property>
<Property Name="sonar.exclusions">**/WebApp/wwwroot/leaflet/**/*.*</Property>
</SonarQubeAnalysisProperties>
48 changes: 31 additions & 17 deletions src/Tests/Unit/WebApp/Shared/FilterLifePointsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -184,16 +198,16 @@ private static IRenderedComponent<FilterLifePoints> CreateTestee(TestContext tes
var existingLocation = TestExistingLocation.Create();

var lifePointServiceMock = Substitute.For<ILifePointService>();
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();
Expand All @@ -209,10 +223,10 @@ private static IRenderedComponent<FilterLifePoints> CreateTestee(TestContext tes
return testee;
}

private static async Task ChangeYearSelectElementAsync(IRenderedComponent<FilterLifePoints> testee, object value) =>
private static async Task ChangeYearSelectElementAsync(IRenderedComponent<FilterLifePoints> testee, object? value) =>
await testee.Find("[id^=\"distinctYear\"]").ChangeAsync(new ChangeEventArgs { Value = value });

private static async Task ChangeCreatorSelectElementAsync(IRenderedComponent<FilterLifePoints> testee, object value) =>
private static async Task ChangeCreatorSelectElementAsync(IRenderedComponent<FilterLifePoints> testee, object? value) =>
await testee.Find("[id^=\"distinctCreator\"]").ChangeAsync(new ChangeEventArgs { Value = value });

private static void DistinctCreatorsShouldBeDisplayed(IRenderedComponent<FilterLifePoints> testee)
Expand Down

0 comments on commit c8dc266

Please sign in to comment.