]> git.sur5r.net Git - i3/i3/blob - testcases/t/132-move-workspace.t
add boilerplate to all testcases with documentation references
[i3/i3] / testcases / t / 132-move-workspace.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Checks if the 'move [window/container] to workspace' command works correctly
18 #
19 use i3test;
20
21 my $i3 = i3(get_socket_path());
22
23 # We move the pointer out of our way to avoid a bug where the focus will
24 # be set to the window under the cursor
25 $x->root->warp_pointer(0, 0);
26
27 sub move_workspace_test {
28     my ($movecmd) = @_;
29
30     my $tmp = get_unused_workspace();
31     my $tmp2 = get_unused_workspace();
32     cmd "workspace $tmp";
33
34     is_num_children($tmp, 0, 'no containers yet');
35
36     my $first = open_empty_con($i3);
37     my $second = open_empty_con($i3);
38     is_num_children($tmp, 2, 'two containers on first ws');
39
40     cmd "workspace $tmp2";
41     is_num_children($tmp2, 0, 'no containers on second ws yet');
42
43     cmd "workspace $tmp";
44
45     cmd "$movecmd $tmp2";
46     is_num_children($tmp, 1, 'one container on first ws anymore');
47     is_num_children($tmp2, 1, 'one container on second ws');
48     my ($nodes, $focus) = get_ws_content($tmp2);
49
50     is($focus->[0], $second, 'same container on different ws');
51
52     ($nodes, $focus) = get_ws_content($tmp);
53     ok($nodes->[0]->{focused}, 'first container focused on first ws');
54 }
55
56 move_workspace_test('move workspace');  # supported for legacy reasons
57 move_workspace_test('move to workspace');
58 # Those are just synonyms and more verbose ways of saying the same thing:
59 move_workspace_test('move window to workspace');
60 move_workspace_test('move container to workspace');
61
62 ################################################################################
63 # Check that 'move to workspace number <number>' works to move a window to
64 # named workspaces which start with <number>.
65 ################################################################################
66
67 cmd 'workspace 13: meh';
68 cmd 'open';
69 is_num_children('13: meh', 1, 'one container on 13: meh');
70
71 ok(!workspace_exists('13'), 'workspace 13 does not exist yet');
72
73 cmd 'workspace 12';
74 cmd 'open';
75
76 cmd 'move to workspace number 13';
77 is_num_children('13: meh', 2, 'one container on 13: meh');
78 is_num_children('12', 0, 'no container on 12 anymore');
79
80 ok(!workspace_exists('13'), 'workspace 13 does still not exist');
81
82 ###################################################################
83 # check if 'move workspace next' and 'move workspace prev' work
84 ###################################################################
85
86 # Open two containers on the first workspace, one container on the second
87 # workspace. Because the workspaces are named, they will be sorted by order of
88 # creation.
89 my $tmp = get_unused_workspace();
90 my $tmp2 = get_unused_workspace();
91 cmd "workspace $tmp";
92 is_num_children($tmp, 0, 'no containers yet');
93 my $first = open_empty_con($i3);
94 my $second = open_empty_con($i3);
95 is_num_children($tmp, 2, 'two containers');
96
97 cmd "workspace $tmp2";
98 is_num_children($tmp2, 0, 'no containers yet');
99 my $third = open_empty_con($i3);
100 is_num_children($tmp2, 1, 'one container on second ws');
101
102 # go back to the first workspace, move one of the containers to the next one
103 cmd "workspace $tmp";
104 cmd 'move workspace next';
105 is_num_children($tmp, 1, 'one container on first ws');
106 is_num_children($tmp2, 2, 'two containers on second ws');
107
108 # go to the second workspace and move two containers to the first one
109 cmd "workspace $tmp2";
110 cmd 'move workspace prev';
111 cmd 'move workspace prev';
112 is_num_children($tmp, 3, 'three containers on first ws');
113 is_num_children($tmp2, 0, 'no containers on second ws');
114
115 ###################################################################
116 # check if 'move workspace current' works
117 ###################################################################
118
119 $tmp = get_unused_workspace();
120 $tmp2 = get_unused_workspace();
121
122 cmd "workspace $tmp";
123 $first = open_window(name => 'win-name');
124 is_num_children($tmp, 1, 'one container on first ws');
125
126 cmd "workspace $tmp2";
127 is_num_children($tmp2, 0, 'no containers yet');
128
129 cmd qq|[title="win-name"] move workspace $tmp2|;
130 is_num_children($tmp2, 1, 'one container on second ws');
131
132 cmd qq|[title="win-name"] move workspace $tmp|;
133 is_num_children($tmp2, 0, 'no containers on second ws');
134
135 ###################################################################
136 # check if floating cons are moved to new workspaces properly
137 # (that is, if they are floating on the target ws, too)
138 ###################################################################
139
140 $tmp = get_unused_workspace();
141 $tmp2 = get_unused_workspace();
142 cmd "workspace $tmp";
143
144 cmd "open";
145 cmd "floating toggle";
146
147 my $ws = get_ws($tmp);
148 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
149 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
150
151 cmd "move workspace $tmp2";
152
153 $ws = get_ws($tmp2);
154 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
155 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
156
157 ################################################################################
158 # Check that 'move workspace number' works correctly.
159 ################################################################################
160
161 $tmp = get_unused_workspace();
162 cmd 'open';
163
164 cmd 'workspace 16';
165 cmd 'open';
166 is_num_children('16', 1, 'one node on ws 16');
167
168 cmd "workspace $tmp";
169 cmd 'open';
170 cmd 'move workspace number 16';
171 is_num_children('16', 2, 'two nodes on ws 16');
172
173 ok(!workspace_exists('17'), 'workspace 17 does not exist yet');
174 cmd 'open';
175 cmd 'move workspace number 17';
176 ok(workspace_exists('17'), 'workspace 17 created by moving');
177 is(@{get_ws('17')->{nodes}}, 1, 'one node on ws 16');
178
179 done_testing;