Skip to content

Commit

Permalink
IMP: Improve country service testability, add test for chart list com…
Browse files Browse the repository at this point in the history
…ponent.
  • Loading branch information
Mehdi-Aghaei committed Jul 26, 2024
1 parent bc49bc6 commit 58fa3f5
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 11 deletions.
32 changes: 32 additions & 0 deletions Pandemic.Tracker.Web.Unit.Tests/Components/Pages/ChartListTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ---------------------------------------------------------------
// Copyright (c) Coalition of the Good-Hearted Engineers
// FREE TO USE TO CONNECT THE WORLD
// ---------------------------------------------------------------

using Bunit;
using FluentAssertions;
using Pandemic.Tracker.Web.Components.Pages;

namespace Pandemic.Tracker.Web.Unit.Tests.Components.Pages;

public class ChartListTests : TestContext
{
[Fact]
public void ChartList_ShouldRenderCorrectly()
{
// Act
var unitUnderTest = RenderComponent<ChartList>();

// Assert
unitUnderTest.Find("h1").MarkupMatches("<h1 class=\"mb-4\">Charts</h1>");

var links = unitUnderTest.FindAll("a.list-group-item");
links.Count.Should().Be(5);

links[0].MarkupMatches("<a href=\"/bar-chart\" class=\"list-group-item list-group-item-action bg-primary text-white mb-2\">Bar Chart: Total Cases, Deaths, and Recovered</a>");
links[1].MarkupMatches("<a href=\"/line-chart\" class=\"list-group-item list-group-item-action bg-success text-white mb-2\">Line Chart: Cases, Deaths, and Recovered Over Time</a>");
links[2].MarkupMatches("<a href=\"/pie-chart\" class=\"list-group-item list-group-item-action bg-info text-white mb-2\">Pie Chart: Countries recovered per one million </a>");
links[3].MarkupMatches("<a href=\"/heat-map\" class=\"list-group-item list-group-item-action bg-warning text-dark mb-2\">Heat Map: Cases per One Million</a>");
links[4].MarkupMatches("<a href=\"/scatter-plot\" class=\"list-group-item list-group-item-action bg-danger text-white mb-2\">Scatter Plot: Cases vs. Population</a>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="bunit" Version="1.30.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Pandemic.Tracker.Web/Components/Pages/BarChart.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/bar-chart"
@rendermode InteractiveServer
@inject CountryService CountryService
@inject ICountryService CountryService

<ApexChart TItem="Country" Title="Country Data">
<ApexPointSeries TItem="Country"
Expand Down
2 changes: 1 addition & 1 deletion Pandemic.Tracker.Web/Components/Pages/HeatMap.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/heat-map"
@rendermode InteractiveServer
@inject CountryService CountryService
@inject ICountryService CountryService

<ApexChart TItem="Country">
<ApexPointSeries TItem="Country"
Expand Down
2 changes: 1 addition & 1 deletion Pandemic.Tracker.Web/Components/Pages/LineChart.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/line-chart"
@rendermode InteractiveServer
@inject CountryService CountryService
@inject ICountryService CountryService


<ApexChart TItem="Country">
Expand Down
2 changes: 1 addition & 1 deletion Pandemic.Tracker.Web/Components/Pages/PieChart.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/pie-chart"
@rendermode InteractiveServer
@inject CountryService CountryService
@inject ICountryService CountryService

<ApexChart TItem="Country" Title="Countries recovered per one million">

Expand Down
2 changes: 1 addition & 1 deletion Pandemic.Tracker.Web/Components/Pages/ScatterPlot.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/scatter-plot"
@rendermode InteractiveServer
@inject CountryService CountryService
@inject ICountryService CountryService

<ApexChart TItem="Country">
<ApexPointSeries TItem="Country"
Expand Down
2 changes: 1 addition & 1 deletion Pandemic.Tracker.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.AddInteractiveServerComponents();

builder.Services.AddHttpClient();
builder.Services.AddScoped<CountryService>();
builder.Services.AddSingleton<ICountryService, CountryService>();

var app = builder.Build();

Expand Down
2 changes: 1 addition & 1 deletion Pandemic.Tracker.Web/Services/CountryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Pandemic.Tracker.Web.Services;

public class CountryService
public class CountryService : ICountryService
{
private readonly HttpClient _httpClient;

Expand Down
14 changes: 14 additions & 0 deletions Pandemic.Tracker.Web/Services/ICountryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ---------------------------------------------------------------
// Copyright (c) Coalition of the Good-Hearted Engineers
// FREE TO USE TO CONNECT THE WORLD
// ---------------------------------------------------------------

using Pandemic.Tracker.Web.Models;

namespace Pandemic.Tracker.Web.Services;

public interface ICountryService
{
List<Country> GetCountries();
List<Country> GetCountriesStatic();
}

0 comments on commit 58fa3f5

Please sign in to comment.