This is a test for #13943

This commit is contained in:
Mike Griese
2022-09-08 16:02:37 -05:00
parent 1ef4a42762
commit b3c491bfe2
2 changed files with 86 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ namespace SettingsModelLocalTests
TEST_METHOD(TestMoveTabArgs);
TEST_METHOD(TestGetKeyBindingForAction);
TEST_METHOD(KeybindingsWithoutVkey);
TEST_METHOD(TestUnbindReverseLookup);
};
void KeyBindingsTests::KeyChords()
@@ -795,4 +796,36 @@ namespace SettingsModelLocalTests
const auto action = actionMap->GetActionByKeyChord({ VirtualKeyModifiers::Shift, 0, 255 });
VERIFY_IS_NOT_NULL(action);
}
void KeyBindingsTests::TestUnbindReverseLookup()
{
Log::Comment(L"TODO!");
// Wrap the first one in `R"!(...)!"` because it has `()` internally.
const std::string bindings0String{ R"!([ { "command": { "action": "newTab", "index": 0 }, "keys":"ctrl+a" } ])!" };
const std::string bindings1String{ R"([ { "keys": "ctrl+a", "command": null } ])" };
const auto bindings0Json = VerifyParseSucceeded(bindings0String);
const auto bindings1Json = VerifyParseSucceeded(bindings1String);
auto actionMap = winrt::make_self<implementation::ActionMap>();
VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size());
actionMap->LayerJson(bindings0Json);
VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size());
NewTerminalArgs newTerminalArgs{ 0 };
NewTabArgs newTabArgs{ newTerminalArgs };
{
auto keyChord{ actionMap->GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
VERIFY_IS_NOT_NULL(keyChord);
}
actionMap->LayerJson(bindings1Json);
{
auto keyChord{ actionMap->GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
VERIFY_IS_NULL(keyChord);
}
}
}

View File

@@ -71,6 +71,8 @@ namespace TerminalAppLocalTests
TEST_METHOD(TestElevateArg);
TEST_METHOD(TestUnbindReverseLookup);
TEST_CLASS_SETUP(ClassSetup)
{
return true;
@@ -1528,5 +1530,56 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(true, termSettings.Elevate());
}
}
void SettingsTests::TestUnbindReverseLookup()
{
Log::Comment(L"Test that unbinding a key also prevents us from looking it up by action");
// note: if you don't put a profile in here, we'll throw an exception during validate.
static constexpr std::wstring_view defaults{ LR"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles":[
{
"name": "profile0",
"guid": "{6239a42c-c2c6-49a3-80bd-e8fdd045185c}",
"commandline": "cmd.exe"
}
],
"actions": [
{ "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+shift+1" }
]
})" };
static constexpr std::wstring_view settingsJson{ LR"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles":[
{
"name": "profile0",
"guid": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
"commandline": "cmd.exe"
}
],
"actions": [
{ "keys": "ctrl+shift+1", "command": null }
]
})" };
NewTerminalArgs newTerminalArgs{ 0 };
NewTabArgs newTabArgs{ newTerminalArgs };
{
Log::Comment(L"The defaults should have a keybinding for this action");
CascadiaSettings settings{ {}, defaults };
auto keyChord{ settings.ActionMap().GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
VERIFY_IS_NOT_NULL(keyChord);
}
{
Log::Comment(L"But these settings shouldn't");
CascadiaSettings settings{ settingsJson, defaults };
auto keyChord{ settings.ActionMap().GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
VERIFY_IS_NULL(keyChord);
}
}
}