From 193e5733bf1493929f85469ffe5919b8d32fcb53 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 1 May 2024 17:36:31 -0700 Subject: [PATCH] fix remaining tests --- .../KeyBindingsTests.cpp | 64 ++++++++--------- .../SerializationTests.cpp | 69 +++++++++++-------- 2 files changed, 71 insertions(+), 62 deletions(-) diff --git a/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp b/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp index 3ee569e1620..a11970b3253 100644 --- a/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp @@ -271,32 +271,32 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); - actionMap->LayerJson(bindings0Json, OriginTag::None); + actionMap->LayerJson(bindings0Json, OriginTag::User); VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); - actionMap->LayerJson(bindings1Json, OriginTag::None); + actionMap->LayerJson(bindings1Json, OriginTag::User); VERIFY_IS_TRUE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); - actionMap->LayerJson(bindings2Json, OriginTag::None); + actionMap->LayerJson(bindings2Json, OriginTag::User); VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); } void KeyBindingsTests::TestArbitraryArgs() { const std::string bindings0String{ R"([ - { "command": "copy", "keys": ["ctrl+c"] }, - { "command": { "action": "copy", "singleLine": false }, "keys": ["ctrl+shift+c"] }, - { "command": { "action": "copy", "singleLine": true }, "keys": ["alt+shift+c"] }, + { "command": "copy", "id": "Test.CopyNoArgs", "keys": ["ctrl+c"] }, + { "command": { "action": "copy", "singleLine": false }, "id": "Test.CopyMultiline", "keys": ["ctrl+shift+c"] }, + { "command": { "action": "copy", "singleLine": true }, "id": "Test.CopySingleline", "keys": ["alt+shift+c"] }, - { "command": "newTab", "keys": ["ctrl+t"] }, - { "command": { "action": "newTab", "index": 0 }, "keys": ["ctrl+shift+t"] }, - { "command": { "action": "newTab", "index": 11 }, "keys": ["ctrl+shift+y"] }, + { "command": "newTab", "id": "Test.NewTabNoArgs", "keys": ["ctrl+t"] }, + { "command": { "action": "newTab", "index": 0 }, "id": "Test.NewTab0", "keys": ["ctrl+shift+t"] }, + { "command": { "action": "newTab", "index": 11 }, "id": "Test.NewTab11", "keys": ["ctrl+shift+y"] }, - { "command": { "action": "copy", "madeUpBool": true }, "keys": ["ctrl+b"] }, - { "command": { "action": "copy" }, "keys": ["ctrl+shift+b"] }, + { "command": { "action": "copy", "madeUpBool": true }, "id": "Test.CopyFakeArgs", "keys": ["ctrl+b"] }, + { "command": { "action": "copy" }, "id": "Test.CopyNullArgs", "keys": ["ctrl+shift+b"] }, - { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": ["ctrl+f"] }, - { "command": { "action": "adjustFontSize", "delta": -1 }, "keys": ["ctrl+g"] } + { "command": { "action": "adjustFontSize", "delta": 1 }, "id": "Test.EnlargeFont", "keys": ["ctrl+f"] }, + { "command": { "action": "adjustFontSize", "delta": -1 }, "id": "Test.ReduceFont", "keys": ["ctrl+g"] } ])" }; @@ -428,10 +428,10 @@ namespace SettingsModelUnitTests void KeyBindingsTests::TestSplitPaneArgs() { const std::string bindings0String{ R"([ - { "keys": ["ctrl+d"], "command": { "action": "splitPane", "split": "vertical" } }, - { "keys": ["ctrl+e"], "command": { "action": "splitPane", "split": "horizontal" } }, - { "keys": ["ctrl+g"], "command": { "action": "splitPane" } }, - { "keys": ["ctrl+h"], "command": { "action": "splitPane", "split": "auto" } } + { "keys": ["ctrl+d"], "id": "Test.SplitPaneVertical", "command": { "action": "splitPane", "split": "vertical" } }, + { "keys": ["ctrl+e"], "id": "Test.SplitPaneHorizontal", "command": { "action": "splitPane", "split": "horizontal" } }, + { "keys": ["ctrl+g"], "id": "Test.SplitPane", "command": { "action": "splitPane" } }, + { "keys": ["ctrl+h"], "id": "Test.SplitPaneAuto", "command": { "action": "splitPane", "split": "auto" } } ])" }; const auto bindings0Json = VerifyParseSucceeded(bindings0String); @@ -478,9 +478,9 @@ namespace SettingsModelUnitTests void KeyBindingsTests::TestSetTabColorArgs() { const std::string bindings0String{ R"([ - { "keys": ["ctrl+c"], "command": { "action": "setTabColor", "color": null } }, - { "keys": ["ctrl+d"], "command": { "action": "setTabColor", "color": "#123456" } }, - { "keys": ["ctrl+f"], "command": "setTabColor" }, + { "keys": ["ctrl+c"], "id": "Test.SetTabColorNull", "command": { "action": "setTabColor", "color": null } }, + { "keys": ["ctrl+d"], "id": "Test.SetTabColor", "command": { "action": "setTabColor", "color": "#123456" } }, + { "keys": ["ctrl+f"], "id": "Test.SetTabColorNoArgs", "command": "setTabColor" }, ])" }; const auto bindings0Json = VerifyParseSucceeded(bindings0String); @@ -521,7 +521,7 @@ namespace SettingsModelUnitTests void KeyBindingsTests::TestStringOverload() { const std::string bindings0String{ R"([ - { "command": "copy", "keys": "ctrl+c" } + { "command": "copy", "id": "Test.Copy", "keys": "ctrl+c" } ])" }; const auto bindings0Json = VerifyParseSucceeded(bindings0String); @@ -543,12 +543,12 @@ namespace SettingsModelUnitTests void KeyBindingsTests::TestScrollArgs() { const std::string bindings0String{ R"([ - { "keys": ["up"], "command": "scrollUp" }, - { "keys": ["down"], "command": "scrollDown" }, - { "keys": ["ctrl+up"], "command": { "action": "scrollUp" } }, - { "keys": ["ctrl+down"], "command": { "action": "scrollDown" } }, - { "keys": ["ctrl+shift+up"], "command": { "action": "scrollUp", "rowsToScroll": 10 } }, - { "keys": ["ctrl+shift+down"], "command": { "action": "scrollDown", "rowsToScroll": 10 } } + { "keys": ["up"], "id": "Test.ScrollUp0", "command": "scrollUp" }, + { "keys": ["down"], "id": "Test.ScrollDown0", "command": "scrollDown" }, + { "keys": ["ctrl+up"], "id": "Test.ScrollUp1", "command": { "action": "scrollUp" } }, + { "keys": ["ctrl+down"], "id": "Test.ScrollDown1", "command": { "action": "scrollDown" } }, + { "keys": ["ctrl+shift+up"], "id": "Test.ScrollUp2", "command": { "action": "scrollUp", "rowsToScroll": 10 } }, + { "keys": ["ctrl+shift+down"], "id": "Test.ScrollDown2", "command": { "action": "scrollDown", "rowsToScroll": 10 } } ])" }; const auto bindings0Json = VerifyParseSucceeded(bindings0String); @@ -620,8 +620,8 @@ namespace SettingsModelUnitTests void KeyBindingsTests::TestMoveTabArgs() { const std::string bindings0String{ R"([ - { "keys": ["up"], "command": { "action": "moveTab", "direction": "forward" } }, - { "keys": ["down"], "command": { "action": "moveTab", "direction": "backward" } } + { "keys": ["up"], "id": "Test.MoveTabUp", "command": { "action": "moveTab", "direction": "forward" } }, + { "keys": ["down"], "id": "Test.MoveTabDown", "command": { "action": "moveTab", "direction": "backward" } } ])" }; const auto bindings0Json = VerifyParseSucceeded(bindings0String); @@ -665,9 +665,9 @@ namespace SettingsModelUnitTests void KeyBindingsTests::TestToggleCommandPaletteArgs() { const std::string bindings0String{ R"([ - { "keys": ["up"], "command": "commandPalette" }, - { "keys": ["ctrl+up"], "command": { "action": "commandPalette", "launchMode" : "action" } }, - { "keys": ["ctrl+shift+up"], "command": { "action": "commandPalette", "launchMode" : "commandLine" } } + { "keys": ["up"], "id": "Test.CmdPal", "command": "commandPalette" }, + { "keys": ["ctrl+up"], "id": "Test.CmdPalActionMode", "command": { "action": "commandPalette", "launchMode" : "action" } }, + { "keys": ["ctrl+shift+up"], "id": "Test.CmdPalLineMode", "command": { "action": "commandPalette", "launchMode" : "commandLine" } } ])" }; const auto bindings0Json = VerifyParseSucceeded(bindings0String); diff --git a/src/cascadia/UnitTests_SettingsModel/SerializationTests.cpp b/src/cascadia/UnitTests_SettingsModel/SerializationTests.cpp index 20357656638..0e1cab1ddc9 100644 --- a/src/cascadia/UnitTests_SettingsModel/SerializationTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/SerializationTests.cpp @@ -120,13 +120,15 @@ namespace SettingsModelUnitTests "experimental.input.forceVT": false, - "actions": [] + "actions": [], + "keybindings": [] })" }; static constexpr std::string_view smallGlobalsString{ R"( { "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", - "actions": [] + "actions": [], + "keybindings": [] })" }; RoundtripTest(globalsString); @@ -275,47 +277,50 @@ namespace SettingsModelUnitTests { // simple command static constexpr std::string_view actionsString1{ R"([ - { "command": "paste" } + { "command": "paste", "id": "Test.Paste" } ])" }; // complex command static constexpr std::string_view actionsString2A{ R"([ - { "command": { "action": "setTabColor" } } + { "command": { "action": "setTabColor" }, "id": "Test.SetTabColor" } ])" }; static constexpr std::string_view actionsString2B{ R"([ - { "command": { "action": "setTabColor", "color": "#112233" } } + { "command": { "action": "setTabColor", "color": "#112233" }, "id": "Test.SetTabColor112233" } ])" }; static constexpr std::string_view actionsString2C{ R"([ - { "command": { "action": "copy" } }, - { "command": { "action": "copy", "singleLine": true, "copyFormatting": "html" } } + { "command": { "action": "copy" }, "id": "Test.Copy" }, + { "command": { "action": "copy", "singleLine": true, "copyFormatting": "html" }, "id": "Test.CopyWithArgs" } ])" }; // simple command with key chords - static constexpr std::string_view actionsString3{ R"([ - { "command": "toggleAlwaysOnTop", "keys": "ctrl+a" }, - { "command": "toggleAlwaysOnTop", "keys": "ctrl+b" } - ])" }; + static constexpr std::string_view actionsString3{ R"({ "actions": [ + { "command": "toggleAlwaysOnTop", "id": "Test.ToggleAlwaysOnTop" } ], + "keybindings": [ + { "keys": "ctrl+a", "id": "Test.ToggleAlwaysOnTop" }, + { "keys": "ctrl+b", "id": "Test.ToggleAlwaysOnTop" } ]})" }; // complex command with key chords - static constexpr std::string_view actionsString4A{ R"([ - { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+c" }, - { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+d" } - ])" }; + static constexpr std::string_view actionsString4A{ R"({ "actions":[ + { "command": { "action": "adjustFontSize", "delta": 1 }, "id": "Test.EnlargeFont" } ], + "keybindings": [ + { "keys": "ctrl+c", "id": "Test.EnlargeFont" }, + { "keys": "ctrl+d", "id": "Test.EnlargeFont" } ]})" }; // command with name and icon and multiple key chords - static constexpr std::string_view actionsString5{ R"([ - { "icon": "image.png", "name": "Scroll To Top Name", "command": "scrollToTop", "keys": "ctrl+e" }, - { "command": "scrollToTop", "keys": "ctrl+f" } - ])" }; + static constexpr std::string_view actionsString5{ R"({ "actions":[ + { "icon": "image.png", "name": "Scroll To Top Name", "command": "scrollToTop", "id": "Test.ScrollToTop" } ], + "keybindings": [ + { "id": "Test.ScrollToTop", "keys": "ctrl+f" }, + { "id": "Test.ScrollToTop", "keys": "ctrl+e" } ]})" }; // complex command with new terminal args static constexpr std::string_view actionsString6{ R"([ - { "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+g" }, + { "command": { "action": "newTab", "index": 0 }, "id": "Test.NewTerminal" }, ])" }; // complex command with meaningful null arg static constexpr std::string_view actionsString7{ R"([ - { "command": { "action": "renameWindow", "name": null }, "keys": "ctrl+h" } + { "command": { "action": "renameWindow", "name": null }, "id": "Test.MeaningfulNull" } ])" }; // nested command @@ -397,9 +402,9 @@ namespace SettingsModelUnitTests ])"" }; // unbound command - static constexpr std::string_view actionsString10{ R"([ - { "command": "unbound", "keys": "ctrl+c" } - ])" }; + static constexpr std::string_view actionsString10{ R"({ "actions": [], + "keybindings": [ + { "id": null, "keys": "ctrl+c" } ]})" }; Log::Comment(L"simple command"); RoundtripTest(actionsString1); @@ -409,14 +414,16 @@ namespace SettingsModelUnitTests RoundtripTest(actionsString2B); RoundtripTest(actionsString2C); + // ActionMap has effectively 2 "to json" calls we need to make, one for the actions and one for the keybindings + // So we cannot use RoundtripTest for actions + keychords, just use RoundTripTest Log::Comment(L"simple command with key chords"); - RoundtripTest(actionsString3); + RoundtripTest(actionsString3); Log::Comment(L"complex commands with key chords"); - RoundtripTest(actionsString4A); + RoundtripTest(actionsString4A); Log::Comment(L"command with name and icon and multiple key chords"); - RoundtripTest(actionsString5); + RoundtripTest(actionsString5); Log::Comment(L"complex command with new terminal args"); RoundtripTest(actionsString6); @@ -434,7 +441,7 @@ namespace SettingsModelUnitTests RoundtripTest(actionsString9D); Log::Comment(L"unbound command"); - RoundtripTest(actionsString10); + RoundtripTest(actionsString10); } void SerializationTests::CascadiaSettings() @@ -503,7 +510,10 @@ namespace SettingsModelUnitTests } ], "actions": [ - { "command": { "action": "sendInput", "input": "VT Griese Mode" }, "id": "User.sendInput.E02B3DF9", "keys": "ctrl+k" } + { "command": { "action": "sendInput", "input": "VT Griese Mode" }, "id": "Test.SendInput" } + ], + "keybindings": [ + { "id": "Test.SendInput", "keys": "ctrl+k" } ], "theme": "system", "themes": [] @@ -995,7 +1005,6 @@ namespace SettingsModelUnitTests { "name": "foo", "command": "closePane", - "keys": "ctrl+shift+w", "id": "thisIsMyClosePane" }, {