1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-02 23:21:02 +01:00
home-manager/tests/modules/programs/vscode/keybindings.nix

155 lines
3.6 KiB
Nix

# Test that keybindings.json is created correctly.
package:
{
config,
pkgs,
lib,
...
}:
let
cfg = config.programs.vscode;
willUseIfd = package.pname != "vscode";
bindings = [
{
key = "ctrl+c";
command = "editor.action.clipboardCopyAction";
when = "textInputFocus && false";
}
{
key = "ctrl+c";
command = "deleteFile";
when = "";
}
{
key = "d";
command = "deleteFile";
when = "explorerViewletVisible";
}
{
key = "ctrl+r";
command = "run";
args = {
command = "echo file";
};
}
];
keybindingsPath =
name:
if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/${cfg.nameShort}/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}keybindings.json"
else
".config/${cfg.nameShort}/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}keybindings.json";
settingsPath =
name:
if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/${cfg.nameShort}/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}settings.json"
else
".config/${cfg.nameShort}/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}settings.json";
content = ''
[
// Order doesn't change
{
"command": "deleteFile",
"key": "ctrl+c",
"when": ""
},
{
"command": "deleteFile",
"key": "ctrl+c",
"when": ""
},
{
"args": {
"command": "echo file"
},
"command": "run",
"key": "ctrl+r"
},
// Comments should be preserved
{
"command": "editor.action.clipboardCopyAction",
"key": "ctrl+c",
"when": "textInputFocus && false"
},
{
"command": "deleteFile",
"key": "d",
"when": "explorerViewletVisible"
}
]
'';
customBindingsPath = pkgs.writeText "custom.json" content;
expectedKeybindings = pkgs.writeText "expected.json" ''
[
{
"command": "editor.action.clipboardCopyAction",
"key": "ctrl+c",
"when": "textInputFocus && false"
},
{
"command": "deleteFile",
"key": "ctrl+c",
"when": ""
},
{
"command": "deleteFile",
"key": "d",
"when": "explorerViewletVisible"
},
{
"args": {
"command": "echo file"
},
"command": "run",
"key": "ctrl+r"
}
]
'';
expectedCustomKeybindings = pkgs.writeText "custom-expected.json" content;
in
lib.mkIf (willUseIfd -> config.test.enableLegacyIfd) {
programs.vscode = {
enable = true;
profiles = {
default.keybindings = bindings;
test.keybindings = bindings;
custom.keybindings = customBindingsPath;
};
inherit package;
};
nmt.script = ''
assertFileExists "home-files/${keybindingsPath "default"}"
assertFileContent "home-files/${keybindingsPath "default"}" "${expectedKeybindings}"
assertPathNotExists "home-files/${settingsPath "default"}"
assertFileExists "home-files/${keybindingsPath "test"}"
assertFileContent "home-files/${keybindingsPath "test"}" "${expectedKeybindings}"
assertPathNotExists "home-files/${settingsPath "test"}"
assertFileExists "home-files/${keybindingsPath "custom"}"
assertFileContent "home-files/${keybindingsPath "custom"}" "${expectedCustomKeybindings}"
assertPathNotExists "home-files/${settingsPath "custom"}"
'';
}