Skip to content

Commit

Permalink
Add tests and have language colors be dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen-Krueger committed Nov 21, 2023
1 parent ecf2500 commit 5c92396
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/azure-static-web-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
# Runs rm package.json package-lock.json to avoid conflicts with the Azure Static Web Apps build, which
# Removes node files after generating tailwind file to avoid conflicts with the Azure Static Web Apps build, which
# will detect the package.json file and not run the dotnet build command.
- name: Install Dependencies and Generate Tailwind CSS
run: |
Expand Down
9 changes: 9 additions & 0 deletions PersonalWebsite.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{5C1BD6EE-E
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0E1DCD8B-741E-4F88-82B6-CDFC23764950}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonalWebsite.Tests", "tests\PersonalWebsite.Tests\PersonalWebsite.Tests.csproj", "{B332051A-A249-44BD-98B5-2EA196F0E1BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,6 +34,10 @@ Global
{FF3F22B1-516B-4987-8704-3A3916D7B7D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF3F22B1-516B-4987-8704-3A3916D7B7D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF3F22B1-516B-4987-8704-3A3916D7B7D1}.Release|Any CPU.Build.0 = Release|Any CPU
{B332051A-A249-44BD-98B5-2EA196F0E1BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B332051A-A249-44BD-98B5-2EA196F0E1BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B332051A-A249-44BD-98B5-2EA196F0E1BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B332051A-A249-44BD-98B5-2EA196F0E1BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -40,5 +48,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{FF3F22B1-516B-4987-8704-3A3916D7B7D1} = {14AD5ADA-948B-4058-A8E8-78E0AAECE583}
{8AA58461-338C-4993-8609-7A1DB7E30129} = {9DD78E52-82A3-44DD-A2D4-C610B9EFAC82}
{B332051A-A249-44BD-98B5-2EA196F0E1BE} = {0E1DCD8B-741E-4F88-82B6-CDFC23764950}
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion src/Components/Portfolio/PortfolioLanguages.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<div class="mb-2 flex flex-col gap-2">
<p class="font-bold @language.Language.GetColor()">@language.Language.GetFormattedString()</p>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div class="bg-cyan-500 h-2.5 rounded-full" style="width: @language.Proficiency%"></div>
@*text-purple-500*@
<div class="@language.Language.GetColor("bg") h-2.5 rounded-full" style="width: @language.Proficiency%"></div>
</div>
</div>
}
Expand Down
4 changes: 2 additions & 2 deletions src/Models/ProgrammingLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static string GetFormattedString(this ProgrammingLanguage programmingLang
/// <summary>
/// Gets the color to display for a <see cref="ProgrammingLanguage"/>.
/// </summary>
public static string GetColor(this ProgrammingLanguage programmingLanguage)
public static string GetColor(this ProgrammingLanguage programmingLanguage, string? start = null)
{
var color = programmingLanguage switch
{
Expand All @@ -60,6 +60,6 @@ public static string GetColor(this ProgrammingLanguage programmingLanguage)
_ => "green"
};

return $"text-{color}-500";
return $"{start ?? "text"}-{color}-500";
}
}
8 changes: 8 additions & 0 deletions src/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ module.exports = {
extend: {},
},
plugins: [],
safelist: [
{
pattern: /bg-(red|green|blue|sky|purple)-500/
},
{
pattern: /text-(red|green|blue|sky|purple)-500/
}
]
}
1 change: 1 addition & 0 deletions tests/PersonalWebsite.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
39 changes: 39 additions & 0 deletions tests/PersonalWebsite.Tests/Models/ProgrammingLanguageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using PersonalWebsite.Models;

namespace PersonalWebsite.Tests.Models;

public class ProgrammingLanguageTests
{
[TestCase(ProgrammingLanguage.CSharp, "C#")]
[TestCase(ProgrammingLanguage.CPlusPlus, "C++")]
[TestCase(ProgrammingLanguage.Rust, "Rust")]
[TestCase(ProgrammingLanguage.Python, "Python")]
[TestCase((ProgrammingLanguage)10, "")]
public void GetFormattedString_VariousInputs_ExpectedResponse(ProgrammingLanguage language, string expectedString)
{
var response = language.GetFormattedString();
Assert.That(response, Is.EqualTo(expectedString));
}

[TestCase(ProgrammingLanguage.CSharp, "text-purple-500")]
[TestCase(ProgrammingLanguage.CPlusPlus, "text-sky-500")]
[TestCase(ProgrammingLanguage.Rust, "text-red-500")]
[TestCase(ProgrammingLanguage.Python, "text-blue-500")]
[TestCase((ProgrammingLanguage)10, "text-green-500")]
public void GetColor_StartNotProvided_TextReturned(ProgrammingLanguage language, string expectedColorClass)
{
var color = language.GetColor();
Assert.That(color, Is.EqualTo(expectedColorClass));
}

[TestCase(ProgrammingLanguage.CSharp, "bg-purple-500")]
[TestCase(ProgrammingLanguage.CPlusPlus, "bg-sky-500")]
[TestCase(ProgrammingLanguage.Rust, "bg-red-500")]
[TestCase(ProgrammingLanguage.Python, "bg-blue-500")]
[TestCase((ProgrammingLanguage)10, "bg-green-500")]
public void GetColor_StartProvided_TextReturned(ProgrammingLanguage language, string expectedColorClass)
{
var color = language.GetColor("bg");
Assert.That(color, Is.EqualTo(expectedColorClass));
}
}
24 changes: 24 additions & 0 deletions tests/PersonalWebsite.Tests/PersonalWebsite.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"/>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\PersonalWebsite.csproj" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions tests/PersonalWebsite.Tests/Utilities/DateOnlyExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using PersonalWebsite.Utilities;

namespace PersonalWebsite.Tests.Utilities;

public class DateOnlyExtensionTests
{
[Test]
public void GetDateString_EndDateProvided_DateRangeStringReturned()
{
DateOnly
startDate = new(2000, 1, 1),
endDate = new(2001, 12, 31);
var response = DateOnlyExtensions.GetDateString(startDate, endDate);

Assert.That(response, Is.EqualTo("(2000-01-01 - 2001-12-31)"));
}

[Test]
public void GetDateString_EndDateNotProvided_PresentStringReturned()
{
var startDate = new DateOnly(2000, 1, 1);
var response = DateOnlyExtensions.GetDateString(startDate, null);

Assert.That(response, Is.EqualTo("(2000-01-01 - Present)"));
}
}

0 comments on commit 5c92396

Please sign in to comment.