about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/fcitx5/default.nix
blob: 9b000da48eaf28e96d7b8d6b229aae55cb3a7870 (plain) (blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import ../make-test-python.nix ({ lib, ... }:
rec {
  name = "fcitx5";
  meta.maintainers = with lib.maintainers; [ nevivurn ];

  nodes.machine = { pkgs, ... }:
  {
    imports = [
      ../common/user-account.nix
    ];

    environment.systemPackages = [
      # To avoid clashing with xfce4-terminal
      pkgs.alacritty
    ];

    services.xserver = {
      enable = true;

      displayManager = {
        lightdm.enable = true;
        autoLogin = {
          enable = true;
          user = "alice";
        };
      };

      desktopManager.xfce.enable = true;
    };

    i18n.inputMethod = {
      enabled = "fcitx5";
      fcitx5.addons = [
        pkgs.fcitx5-chinese-addons
        pkgs.fcitx5-hangul
        pkgs.fcitx5-m17n
        pkgs.fcitx5-mozc
      ];
    };
  };

  testScript = { nodes, ... }:
    let
      user = nodes.machine.users.users.alice;
      xauth         = "${user.home}/.Xauthority";
      fcitx_confdir = "${user.home}/.config/fcitx5";
    in
      ''
            start_all()

            machine.wait_for_x()
            machine.wait_for_file("${xauth}")
            machine.succeed("xauth merge ${xauth}")
            machine.sleep(5)

            machine.succeed("su - ${user.name} -c 'kill $(pgrep fcitx5)'")
            machine.sleep(1)

            machine.copy_from_host(
                "${./profile}",
                "${fcitx_confdir}/profile",
            )
            machine.copy_from_host(
                "${./config}",
                "${fcitx_confdir}/config",
            )

            machine.succeed("su - ${user.name} -c 'alacritty >&2 &'")
            machine.succeed("su - ${user.name} -c 'fcitx5 >&2 &'")
            machine.sleep(10)

            ### Type on terminal
            machine.send_chars("echo ")
            machine.sleep(1)

            ### Start fcitx Unicode input
            machine.send_key("ctrl-alt-shift-u")
            machine.sleep(1)

            ### Search for smiling face
            machine.send_chars("smil")
            machine.sleep(1)

            ### Navigate to the second one
            machine.send_key("tab")
            machine.sleep(1)

            ### Choose it
            machine.send_key("\n")
            machine.sleep(1)

            ### Start fcitx language input
            machine.send_key("ctrl-spc")
            machine.sleep(1)

            ### Default wubi, enter 一下
            machine.send_chars("gggh ")
            machine.sleep(1)

            ### Switch to Hangul
            machine.send_key("alt-shift")
            machine.sleep(1)

            ### Enter 한
            machine.send_chars("gks")
            machine.sleep(1)

            ### Switch to Harvard Kyoto
            machine.send_key("alt-shift")
            machine.sleep(1)

            ### Enter क
            machine.send_chars("ka")
            machine.sleep(1)

            ### Switch to Mozc
            machine.send_key("alt-shift")
            machine.sleep(1)

            ### Enter か
            machine.send_chars("ka\n")
            machine.sleep(1)

            ### Turn off Fcitx
            machine.send_key("ctrl-spc")
            machine.sleep(1)

            ### Redirect typed characters to a file
            machine.send_chars(" > fcitx_test.out\n")
            machine.sleep(1)
            machine.screenshot("terminal_chars")

            ### Verify that file contents are as expected
            file_content = machine.succeed("cat ${user.home}/fcitx_test.out")
            assert file_content == "☺一下한कか\n"
      ''
  ;
})