From ea17bc10f29fcd52b99300ce80dab26bb74aa66c Mon Sep 17 00:00:00 2001 From: snixtho Date: Wed, 6 Dec 2023 14:13:40 +0100 Subject: [PATCH] fix tests and more comments --- .../Util/FontManialinkHelper.cs | 51 ++++++++++++++++++- .../Util/GlobalManialinkUtils.cs | 10 ++++ .../Themes/ThemeManagerTests.cs | 2 +- .../FastestCp.Tests/FastestCpManialinkTest.cs | 45 ---------------- .../FastestCp.Tests/FastestCpServiceTest.cs | 6 +-- 5 files changed, 64 insertions(+), 50 deletions(-) delete mode 100644 tests/Modules/FastestCp.Tests/FastestCpManialinkTest.cs diff --git a/src/EvoSC.Manialinks/Util/FontManialinkHelper.cs b/src/EvoSC.Manialinks/Util/FontManialinkHelper.cs index 9a82feca4..b229c851c 100644 --- a/src/EvoSC.Manialinks/Util/FontManialinkHelper.cs +++ b/src/EvoSC.Manialinks/Util/FontManialinkHelper.cs @@ -6,10 +6,29 @@ public class FontManialinkHelper { private readonly dynamic _theme; + /// + /// Thin thickness of the current font. + /// public string Thin => ToThin(_theme.UI_Font); + + /// + /// Regular thickness of the current font. + /// public string Regular => ToRegular(_theme.UI_Font); + + /// + /// Bold thickness of the current font. + /// public string Bold => ToBold(_theme.UI_Font); + + /// + /// Extra bold thickness of the current font. + /// public string ExtraBold => ToExtraBold(_theme.UI_Font); + + /// + /// Mono version of the current font. + /// public string Mono => ToExtraBold(_theme.UI_Font); public FontManialinkHelper(IThemeManager theme) @@ -17,6 +36,12 @@ public FontManialinkHelper(IThemeManager theme) _theme = theme.Theme; } + /// + /// Convert the provided font to it's regular thickness version. + /// + /// Font to convert. + /// + /// public string ToRegular(string font) => font switch { _ when font.StartsWith("GameFont") => "GameFontSemiBold", @@ -26,12 +51,24 @@ _ when font.StartsWith("Roboto") => "RobotoCondensed", _ => throw new InvalidOperationException("Invalid font.") }; + /// + /// Convert the provided font to it's thin thickness version. + /// + /// Font to convert. + /// + /// public string ToThin(string font) => font switch { _ when font.StartsWith("GameFont") => "GameFontSemiRegular", _ => ToRegular(font) }; + /// + /// Convert the provided font to it's bold thickness version. + /// + /// Font to convert. + /// + /// public string ToBold(string font) => font switch { _ when font.StartsWith("GameFont") => "GameFontExtraBold", @@ -39,12 +76,24 @@ _ when font.StartsWith("Roboto") => "RobotoCondensedBold", _ => ToRegular(font) }; + /// + /// Convert the provided font to it's extra bold thickness version. + /// + /// Font to convert. + /// + /// public string ToExtraBold(string font) => font switch { _ when font.StartsWith("GameFont") => "GameFontBlack", _ => ToBold(font) }; - + + /// + /// Convert the provided font to it's mono version. + /// + /// Font to convert. + /// + /// public string ToMono(string font) => font switch { _ when font.StartsWith("Rajdhani") => "RajdhaniMono", diff --git a/src/EvoSC.Manialinks/Util/GlobalManialinkUtils.cs b/src/EvoSC.Manialinks/Util/GlobalManialinkUtils.cs index ebe49a4d2..b5c55be0e 100644 --- a/src/EvoSC.Manialinks/Util/GlobalManialinkUtils.cs +++ b/src/EvoSC.Manialinks/Util/GlobalManialinkUtils.cs @@ -12,6 +12,11 @@ public GlobalManialinkUtils(IThemeManager themeManager) _theme = themeManager.Theme; } + /// + /// Status type to a color. + /// + /// Name of the status. + /// public string TypeToColorBg(string type) => type.ToLower() switch { "info" => _theme.Teal, @@ -23,6 +28,11 @@ public GlobalManialinkUtils(IThemeManager themeManager) _ => _theme.UI_BgPrimary }; + /// + /// Status type to an icon. + /// + /// Name of the status. + /// public string TypeToIcon(string type) => type.ToLower() switch { "info" => _icons.InfoCircle, diff --git a/tests/EvoSC.Common.Tests/Themes/ThemeManagerTests.cs b/tests/EvoSC.Common.Tests/Themes/ThemeManagerTests.cs index 6fff0a053..426077a1c 100644 --- a/tests/EvoSC.Common.Tests/Themes/ThemeManagerTests.cs +++ b/tests/EvoSC.Common.Tests/Themes/ThemeManagerTests.cs @@ -151,7 +151,7 @@ public async Task Available_Themes_Property_Returns_All_Themes() var themes = mock.ThemeManager.AvailableThemes.Select(t => t.Name).ToArray(); Assert.NotEmpty(themes); - Assert.Equal(new[]{"Default", "MyTheme", "MyTheme2", "MyTheme3"}, themes); + Assert.Equal(new[]{"MyTheme", "MyTheme2", "MyTheme3"}, themes); Assert.Equal("MyThemeOptionValue", mock.ThemeManager.Theme.MyThemeOption); Assert.Equal("MyThemeOptionValue2", mock.ThemeManager.Theme.MyThemeOption2); Assert.Equal("MyThemeOptionValue3", mock.ThemeManager.Theme.MyThemeOption3); diff --git a/tests/Modules/FastestCp.Tests/FastestCpManialinkTest.cs b/tests/Modules/FastestCp.Tests/FastestCpManialinkTest.cs deleted file mode 100644 index ab84a8731..000000000 --- a/tests/Modules/FastestCp.Tests/FastestCpManialinkTest.cs +++ /dev/null @@ -1,45 +0,0 @@ -using EvoSC.Modules.Official.FastestCpModule.Models; -using ManiaTemplates; - -namespace EvoSC.Modules.Official.FastestCpModule.Tests; - -public class FastestCpManialinkTest -{ - private const string Key = "FastestCpModule.FastestCpModule"; - - private readonly ManiaTemplateEngine _maniaTemplateEngine = new(); - - public FastestCpManialinkTest() - { - var file = typeof(FastestCpModule).Assembly.GetManifestResourceStream("EvoSC.Modules.Official.FastestCpModule.Templates.FastestCpModule.mt"); - var reader = new StreamReader(file!); - _maniaTemplateEngine.AddTemplateFromString(Key, reader.ReadToEnd()); - } - - [Fact] - public async void Should_Render_Empty_Widget() - { - var result = await _maniaTemplateEngine.RenderAsync(Key, new { times = Array.Empty() }, - new[] { typeof(FastestCpModule).Assembly }); - var expected = await File.ReadAllTextAsync("Manialinks/Empty.xml"); - - Assert.Equal(result, expected, ignoreLineEndingDifferences: true); - } - - [Fact] - public async void Should_Render_Filled_Widget() - { - var result = await _maniaTemplateEngine.RenderAsync(Key, new { times = GetCpData() }, - new[] { typeof(FastestCpModule).Assembly }); - var expected = await File.ReadAllTextAsync("Manialinks/Filled.xml"); - - Assert.Equal(result, expected, ignoreLineEndingDifferences: true); - } - - private static PlayerCpTime[] GetCpData() - { - const string Name = "VeryLongName"; - return Enumerable.Range(0, 7) - .Select(i => new PlayerCpTime(Name[..i], i + 1, TimeSpan.FromSeconds(13 * i))).ToArray(); - } -} diff --git a/tests/Modules/FastestCp.Tests/FastestCpServiceTest.cs b/tests/Modules/FastestCp.Tests/FastestCpServiceTest.cs index 60a6392a9..fa409d76d 100644 --- a/tests/Modules/FastestCp.Tests/FastestCpServiceTest.cs +++ b/tests/Modules/FastestCp.Tests/FastestCpServiceTest.cs @@ -56,7 +56,7 @@ await _fastestCpService.RegisterCpTimeAsync(new WayPointEventArgs var actualData = new List(); _manialinkManagerMock.Verify( - manager => manager.SendPersistentManialinkAsync("FastestCpModule.FastestCpModule", Capture.In(actualData)), Times.Once); + manager => manager.SendPersistentManialinkAsync("FastestCpModule.FastestCp", Capture.In(actualData)), Times.Once); Assert.NotEmpty(actualData); Assert.Equivalent( new { times = new List { new("NickName1", 0, TimeSpan.FromMilliseconds(10)) } }, @@ -87,7 +87,7 @@ await _fastestCpService.RegisterCpTimeAsync(new WayPointEventArgs }); _manialinkManagerMock.Verify( - manager => manager.SendPersistentManialinkAsync("FastestCpModule.FastestCpModule", It.IsAny()), Times.Never); + manager => manager.SendPersistentManialinkAsync("FastestCpModule.FastestCp", It.IsAny()), Times.Never); } [Fact] @@ -102,7 +102,7 @@ public async void Should_Reset_Store() var after = fieldInfo?.GetValue(_fastestCpService); - _manialinkManagerMock.Verify(manager => manager.HideManialinkAsync("FastestCpModule.FastestCpModule"), Times.Once); + _manialinkManagerMock.Verify(manager => manager.HideManialinkAsync("FastestCpModule.FastestCp"), Times.Once); Assert.NotNull(before); Assert.NotNull(after);