From 32ccd24194030ab55b203b252fadb5344b8a4f2e Mon Sep 17 00:00:00 2001 From: Invvard <7305493+Invvard@users.noreply.github.com> Date: Fri, 14 Jun 2019 12:40:04 -0400 Subject: [PATCH 1/2] Fix the color displayed on keys and layers --- .../Helper/EZLayoutMaker.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/InvvardDev.EZLayoutDisplay.Desktop/Helper/EZLayoutMaker.cs b/src/InvvardDev.EZLayoutDisplay.Desktop/Helper/EZLayoutMaker.cs index f349a5f9..548a733a 100644 --- a/src/InvvardDev.EZLayoutDisplay.Desktop/Helper/EZLayoutMaker.cs +++ b/src/InvvardDev.EZLayoutDisplay.Desktop/Helper/EZLayoutMaker.cs @@ -56,7 +56,7 @@ private EZLayer PrepareEZLayer(ErgodoxLayer ergodoxLayer) foreach (var ergodoxKey in ergodoxLayer.Keys) { - EZKey key = PrepareKeyLabels(ergodoxKey); + EZKey key = PrepareKeyLabels(ergodoxKey, layer.Color); layer.EZKeys.Add(key); } @@ -66,7 +66,7 @@ private EZLayer PrepareEZLayer(ErgodoxLayer ergodoxLayer) return layer; } - private EZKey PrepareKeyLabels(ErgodoxKey ergodoxKey) + private EZKey PrepareKeyLabels(ErgodoxKey ergodoxKey, string layerColor) { Logger.TraceMethod(); Logger.DebugInputParam(nameof(ergodoxKey), ergodoxKey); @@ -91,7 +91,7 @@ private EZKey PrepareKeyLabels(ErgodoxKey ergodoxKey) EZKey key = new EZKey { KeyCategory = keyDefinition.KeyCategory, Label = new KeyLabel(keyDefinition.Label, keyDefinition.IsGlyph), - Color = GetColor(ergodoxKey.GlowColor), + Color = GetColor(ergodoxKey.GlowColor, layerColor), DisplayType = KeyDisplayType.SimpleLabel }; @@ -175,9 +175,9 @@ private EZKey PrepareKeyLabels(ErgodoxKey ergodoxKey) return key; } - private static string GetColor(string keyColor) + private static string GetColor(string keyColor, string defaultColor = "#777") { - var fontColor = string.IsNullOrWhiteSpace(keyColor) ? "#777" : keyColor; + var fontColor = string.IsNullOrWhiteSpace(keyColor) ? defaultColor : keyColor; return fontColor; } From 5ea67e4b7bbf109013f706e1184e6a4cb8b4d044 Mon Sep 17 00:00:00 2001 From: Invvard <7305493+Invvard@users.noreply.github.com> Date: Fri, 14 Jun 2019 13:00:28 -0400 Subject: [PATCH 2/2] Add unit tests for key color pick --- .../Helper/EZLayoutMakerTest.cs | 179 ++++++++---------- 1 file changed, 78 insertions(+), 101 deletions(-) diff --git a/src/InvvardDev.EZLayoutDisplay.Tests/Helper/EZLayoutMakerTest.cs b/src/InvvardDev.EZLayoutDisplay.Tests/Helper/EZLayoutMakerTest.cs index d0d72a1a..bb135f16 100644 --- a/src/InvvardDev.EZLayoutDisplay.Tests/Helper/EZLayoutMakerTest.cs +++ b/src/InvvardDev.EZLayoutDisplay.Tests/Helper/EZLayoutMakerTest.cs @@ -12,22 +12,15 @@ public class EZLayoutMakerTest { private static ErgodoxLayout InitializeDataTree() { - return new ErgodoxLayout { - Title = "", - HashId = "", - Revisions = new List { - new Revision { - Layers = new List { - new ErgodoxLayer() { - Color = "", - Title = "", - Position = 0, - Keys = new List() - } - } - } - } - }; + return new ErgodoxLayout + { + Title = "", + HashId = "", + Revisions = new List + { + new Revision { Layers = new List { new ErgodoxLayer() { Color = "", Title = "", Position = 0, Keys = new List() } } } + } + }; } [ Theory ] @@ -35,14 +28,8 @@ [ InlineData("expectedTitle", "expectedHashId") ] public void PrepareEZLayout_InitializeEZLayout(string expectedTitle, string expectedHashId) { // Arrange - var revision = new Revision { - Layers = new List() - }; - ErgodoxLayout ergodoxLayout = new ErgodoxLayout { - Title = expectedTitle, - HashId = expectedHashId, - Revisions = new List() - }; + var revision = new Revision { Layers = new List() }; + ErgodoxLayout ergodoxLayout = new ErgodoxLayout { Title = expectedTitle, HashId = expectedHashId, Revisions = new List() }; ergodoxLayout.Revisions.Add(revision); EZLayout ezLayoutResult; @@ -60,23 +47,8 @@ [ InlineData(0, "expectedTitle", "expectedColor") ] public void PrepareEZLayout_InitializeEZLayer(int expectedIndex, string expectedTitle, string expectedColor) { // Arrange - var ergodoxLayer = new ErgodoxLayer() { - Color = expectedColor, - Title = expectedTitle, - Position = expectedIndex, - Keys = new List() - }; - ErgodoxLayout ergodoxLayout = new ErgodoxLayout { - Title = "", - HashId = "", - Revisions = new List { - new Revision { - Layers = new List { - ergodoxLayer - } - } - } - }; + var ergodoxLayer = new ErgodoxLayer() { Color = expectedColor, Title = expectedTitle, Position = expectedIndex, Keys = new List() }; + ErgodoxLayout ergodoxLayout = new ErgodoxLayout { Title = "", HashId = "", Revisions = new List { new Revision { Layers = new List { ergodoxLayer } } } }; EZLayout ezLayoutResult; @@ -91,14 +63,35 @@ public void PrepareEZLayout_InitializeEZLayer(int expectedIndex, string expected Assert.Equal(expectedColor, ezLayoutResult.EZLayers.First().Color); } + [ Theory ] + [ InlineData(null, null, "#777") ] + [ InlineData("", "", "#777") ] + [ InlineData("layerColor", null, "layerColor") ] + [ InlineData("layerColor", "", "layerColor") ] + [ InlineData(null, "keyColor", "keyColor") ] + [ InlineData("", "keyColor", "keyColor") ] + [ InlineData("layerColor", "keyColor", "keyColor") ] + public void PrepareEZLayout_ColorKey(string layerColor, string keyColor, string expectedColor) + { + // Arrange + var ergodoxLayer = new ErgodoxLayer { Color = layerColor, Keys = new List { new ErgodoxKey { GlowColor = keyColor } } }; + ErgodoxLayout ergodoxLayout = new ErgodoxLayout { Title = "", HashId = "", Revisions = new List { new Revision { Layers = new List { ergodoxLayer } } } }; + + EZLayout ezLayoutResult; + + // Act + var ezLayoutMaker = new EZLayoutMaker(); + ezLayoutResult = ezLayoutMaker.PrepareEZLayout(ergodoxLayout); + + // Assert + Assert.Equal(expectedColor, ezLayoutResult.EZLayers.First().EZKeys.First().Color); + } + [ Fact ] public void PrepareEZLayout_KeyCodeUnknown() { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = "KC_UNKNOWN_ADSLKFJ" - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = "KC_UNKNOWN_ADSLKFJ" }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -120,10 +113,7 @@ [ InlineData("KC_TRANSPARENT", "expectedColor") ] public void PrepareEZLayout_InitializeEZKey(string expectedKeyCode, string expectedColor) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = expectedColor, - Code = expectedKeyCode - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = expectedColor, Code = expectedKeyCode }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -159,10 +149,7 @@ [ InlineData("ES_PLUS", "+", KeyCategory.Spanish) ] public void PrepareEZLayout_KeyCategoryWithSimpleLabel(string keyCode, string expectedLabel, KeyCategory expectedCategory) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = keyCode - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -188,12 +175,7 @@ [ InlineData("OSM", "MOD_LSFT", "OSM", "\u21e7", KeyDisplayType.ModifierOnTop, K public void PrepareEZLayout_KeyCategoryOSM(string keyCode, string command, string expectedLabel, string expectedSubLabel, KeyDisplayType expectedDisplayType, KeyCategory expectedCategory) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = keyCode, - Command = command, - Layer = 1 - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode, Command = command, Layer = 1 }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -209,6 +191,7 @@ public void PrepareEZLayout_KeyCategoryOSM(string keyCode, string command, strin var keyResult = ezLayoutResult.EZLayers.First().EZKeys.First(); Assert.Equal(expectedLabel, keyResult.Label.Content); + if (expectedDisplayType == KeyDisplayType.SimpleLabel) { Assert.Null(keyResult.Modifier); @@ -218,6 +201,7 @@ public void PrepareEZLayout_KeyCategoryOSM(string keyCode, string command, strin Assert.Equal(expectedSubLabel, keyResult.Modifier.Content); Assert.False(keyResult.Modifier.IsGlyph); } + Assert.Equal(expectedDisplayType, keyResult.DisplayType); Assert.Equal(expectedCategory, keyResult.KeyCategory); } @@ -231,11 +215,7 @@ [ InlineData("TT", "TT 1", KeyCategory.Layer) ] public void PrepareEZLayout_KeyCategoryLayer(string keyCode, string expectedLabel, KeyCategory expectedCategory) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = keyCode, - Layer = 1 - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode, Layer = 1 }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -256,15 +236,15 @@ public void PrepareEZLayout_KeyCategoryLayer(string keyCode, string expectedLabe [ Theory ] [ InlineData("LT", "", "LT → 1", "", KeyDisplayType.SimpleLabel, KeyCategory.LayerShortcuts) ] [ InlineData("LT", "KC_0", "0", "LT → 1", KeyDisplayType.ModifierUnder, KeyCategory.LayerShortcuts) ] - public void PrepareEZLayout_KeyCategoryLayerShortcut(string keyCode, string command, string expectedLabel, string expectedSubLabel, KeyDisplayType expectedDisplayType, KeyCategory expectedCategory) + public void PrepareEZLayout_KeyCategoryLayerShortcut(string keyCode, + string command, + string expectedLabel, + string expectedSubLabel, + KeyDisplayType expectedDisplayType, + KeyCategory expectedCategory) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = keyCode, - Command = command, - Layer = 1 - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode, Command = command, Layer = 1 }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -279,6 +259,7 @@ public void PrepareEZLayout_KeyCategoryLayerShortcut(string keyCode, string comm Assert.Single(ezLayoutResult.EZLayers.First().EZKeys); var keyResult = ezLayoutResult.EZLayers.First().EZKeys.First(); Assert.Equal(expectedLabel, keyResult.Label.Content); + if (expectedDisplayType == KeyDisplayType.SimpleLabel) { Assert.Null(keyResult.Modifier); @@ -288,6 +269,7 @@ public void PrepareEZLayout_KeyCategoryLayerShortcut(string keyCode, string comm Assert.Equal(expectedSubLabel, keyResult.Modifier.Content); Assert.False(keyResult.Modifier.IsGlyph); } + Assert.Equal(expectedCategory, keyResult.KeyCategory); } @@ -304,10 +286,7 @@ [ InlineData("RGB_MOD", "\ue916", KeyDisplayType.SimpleLabel, KeyCategory.Shine, public void PrepareEZLayout_KeyCategoryWithGlyphs(string keyCode, string expectedLabel, KeyDisplayType expectedDisplayType, KeyCategory expectedCategory, bool expectedIsGlyph) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = keyCode - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -330,14 +309,15 @@ public void PrepareEZLayout_KeyCategoryWithGlyphs(string keyCode, string expecte [ Theory ] [ InlineData("ALL_T", "KC_6", "6", "Hyper", KeyCategory.DualFunction, KeyDisplayType.ModifierUnder) ] [ InlineData("ALL_T", "", "Hyper", "", KeyCategory.Modifier, KeyDisplayType.SimpleLabel) ] - public void PrepareEZLayout_KeyCategoryDualFunction(string keyCode, string command, string expectedLabel, string expectedSubLabel, KeyCategory expectedCategory, KeyDisplayType expectedDisplayType) + public void PrepareEZLayout_KeyCategoryDualFunction(string keyCode, + string command, + string expectedLabel, + string expectedSubLabel, + KeyCategory expectedCategory, + KeyDisplayType expectedDisplayType) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = keyCode, - Command = command - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode, Command = command }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -352,6 +332,7 @@ public void PrepareEZLayout_KeyCategoryDualFunction(string keyCode, string comma Assert.Single(ezLayoutResult.EZLayers.First().EZKeys); var keyResult = ezLayoutResult.EZLayers.First().EZKeys.First(); Assert.Equal(expectedLabel, keyResult.Label.Content); + if (expectedDisplayType == KeyDisplayType.SimpleLabel) { Assert.Null(keyResult.Modifier); @@ -360,6 +341,7 @@ public void PrepareEZLayout_KeyCategoryDualFunction(string keyCode, string comma { Assert.Equal(expectedSubLabel, keyResult.Modifier.Content); } + Assert.Equal(expectedCategory, keyResult.KeyCategory); } @@ -369,11 +351,7 @@ [ InlineData("LALT", "", "Alt", KeyCategory.Shortcuts) ] public void PrepareEZLayout_KeyCategoryShortcuts(string keyCode, string command, string expectedLabel, KeyCategory expectedCategory) { // Arrange - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = keyCode, - Command = command - }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = keyCode, Command = command }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -431,21 +409,18 @@ public void PrepareEZLayout_ProcessModifiers(bool leftAlt, KeyDisplayType expectedDisplayType) { // Arrange - var modifiers = new ErgodoxModifiers { - LeftAlt = leftAlt, - LeftCtrl = leftCtrl, - LeftShift = leftShift, - LeftWin = leftWin, - RightAlt = rightAlt, - RightCtrl = rightCtrl, - RightShift = rightShift, - RightWin = rightWin - }; - var ergodoxKey = new ErgodoxKey() { - GlowColor = "", - Code = "KC_A", - Modifiers = modifiers - }; + var modifiers = new ErgodoxModifiers + { + LeftAlt = leftAlt, + LeftCtrl = leftCtrl, + LeftShift = leftShift, + LeftWin = leftWin, + RightAlt = rightAlt, + RightCtrl = rightCtrl, + RightShift = rightShift, + RightWin = rightWin + }; + var ergodoxKey = new ErgodoxKey() { GlowColor = "", Code = "KC_A", Modifiers = modifiers }; ErgodoxLayout ergodoxLayout = InitializeDataTree(); ergodoxLayout.Revisions.First().Layers.First().Keys.Add(ergodoxKey); @@ -460,6 +435,7 @@ public void PrepareEZLayout_ProcessModifiers(bool leftAlt, Assert.Single(ezLayoutResult.EZLayers.First().EZKeys); var keyResult = ezLayoutResult.EZLayers.First().EZKeys.First(); Assert.Equal("A", keyResult.Label.Content); + if (expectedDisplayType == KeyDisplayType.SimpleLabel) { Assert.Null(keyResult.Modifier); @@ -469,6 +445,7 @@ public void PrepareEZLayout_ProcessModifiers(bool leftAlt, Assert.Equal(expectedSubLabel, keyResult.Modifier.Content); Assert.False(keyResult.Modifier.IsGlyph); } + Assert.Equal(expectedDisplayType, keyResult.DisplayType); } }