1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-02 16:09:46 +01:00
home-manager/tests/modules/programs/vscode/keybindings.nix
Reputable2722 c802fa310e
tests: add tests for vscode profiles
Signed-off-by: Reputable2722 <153411261+Reputable2772@users.noreply.github.com>
2024-07-17 22:32:10 +05:30

101 lines
2.4 KiB
Nix

# Test that keybindings.json is created correctly.
{ pkgs, lib, ... }:
let
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/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}keybindings.json"
else
".config/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}keybindings.json";
settingsPath = name:
if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}settings.json"
else
".config/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}settings.json";
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"
}
]
'';
in {
programs.vscode = {
enable = true;
defaultProfile.keybindings = bindings;
profiles = [{
name = "test";
keybindings = bindings;
}];
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
};
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"}"
'';
}