aboutsummaryrefslogtreecommitdiff
path: root/home-manager/tests/modules/programs/vscode/keybindings.nix
blob: 420b212dce9ef0900763fbbf3a7441937b761b2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Test that keybdinings.json is created correctly.
{ config, lib, pkgs, ... }:

with 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";
    }
  ];

  targetPath = if pkgs.stdenv.hostPlatform.isDarwin then
    "Library/Application Support/Code/User/keybindings.json"
  else
    ".config/Code/User/keybindings.json";

  expectedJson = pkgs.writeText "expected.json" (builtins.toJSON bindings);
in {
  config = {
    programs.vscode = {
      enable = true;
      keybindings = bindings;
    };

    nixpkgs.overlays = [
      (self: super: {
        vscode = pkgs.runCommandLocal "vscode" { pname = "vscode"; } ''
          mkdir -p $out/bin
          touch $out/bin/code
          chmod +x $out/bin/code;
        '';
      })
    ];

    nmt.script = ''
      assertFileExists "home-files/${targetPath}"
      assertFileContent "home-files/${targetPath}" "${expectedJson}"
    '';
  };
}