2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests for the 'move [window|container] to mark' command
21 # In the following tests descriptions, we will always use the following names:
22 # * 'S' for the source container which is going to be moved,
23 # * 'M' for the marked target container to which 'S' will be moved.
25 my ($A, $B, $S, $M, $F, $source_ws, $target_ws, $ws);
29 ###############################################################################
30 # Given 'M' and 'S' in a horizontal split, when 'S' is moved to 'M', then
31 # verify that nothing changed.
32 ###############################################################################
34 $ws = fresh_workspace;
39 cmd 'move container to mark target';
42 ($nodes, $focus) = get_ws_content($ws);
43 is(@{$nodes}, 2, 'there are two containers');
44 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
45 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
47 ###############################################################################
48 # Given 'S' and 'M' in a horizontal split, when 'S' is moved to 'M', then
49 # both containers switch places.
50 ###############################################################################
52 $ws = fresh_workspace;
58 cmd 'move container to mark target';
61 ($nodes, $focus) = get_ws_content($ws);
62 is(@{$nodes}, 2, 'there are two containers');
63 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
64 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
66 ###############################################################################
67 # Given 'S' and no container 'M' exists, when 'S' is moved to 'M', then
68 # the command is unsuccessful.
69 ###############################################################################
71 $ws = fresh_workspace;
74 $cmd_result = cmd 'move container to mark absent';
76 is($cmd_result->[0]->{success}, 0, 'command was unsuccessful');
78 ###############################################################################
79 # Given 'S' and 'M' on different workspaces, when 'S' is moved to 'M', then
80 # 'S' ends up on the same workspace as 'M'.
81 ###############################################################################
83 $source_ws = fresh_workspace;
85 $target_ws = fresh_workspace;
89 cmd '[id="' . $S->{id} . '"] move container to mark target';
92 ($nodes, $focus) = get_ws_content($source_ws);
93 is(@{$nodes}, 0, 'source workspace is empty');
95 ($nodes, $focus) = get_ws_content($target_ws);
96 is(@{$nodes}, 2, 'both containers are on the target workspace');
97 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
98 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
100 ###############################################################################
101 # Given 'S' and 'M' on different workspaces and 'S' is urgent, when 'S' is
102 # moved to 'M', then the urgency flag is transferred to the target workspace.
103 ###############################################################################
107 ###############################################################################
108 # Given 'S' and 'M' where 'M' is inside a tabbed container, when 'S' is moved
109 # to 'M', then 'S' ends up as a new tab.
110 ###############################################################################
112 $source_ws = fresh_workspace;
115 # open tabbed container ['A' 'M' 'B']
116 $target_ws = fresh_workspace;
123 cmd '[id="' . $S->{id} . '"] move container to mark target';
126 ($nodes, $focus) = get_ws_content($target_ws);
127 is(@{$nodes}, 1, 'there is a tabbed container');
129 $nodes = $nodes->[0]->{nodes};
130 is(@{$nodes}, 4, 'all four containers are on the target workspace');
131 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
132 is($nodes->[1]->{window}, $M->{id}, 'M is the second tab');
133 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
134 is($nodes->[3]->{window}, $B->{id}, 'B is the fourth tab');
136 ###############################################################################
137 # Given 'S' and 'M' where 'M' is a tabbed container where the currently focused
138 # tab is a nested layout, when 'S' is moved to 'M', then 'S' is a new tab
140 ###############################################################################
142 $source_ws = fresh_workspace;
145 $target_ws = fresh_workspace;
155 cmd '[id="' . $S->{id} . '"] move container to mark target';
158 ($nodes, $focus) = get_ws_content($target_ws);
159 is(@{$nodes}, 1, 'there is a tabbed container');
161 $nodes = $nodes->[0]->{nodes};
162 is(@{$nodes}, 3, 'there are three tabs');
164 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
165 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
167 ###############################################################################
168 # Given 'S' and 'M' where 'M' is inside a split container inside a tabbed
169 # container, when 'S' is moved to 'M', then 'S' ends up as a container
170 # within the same tab as 'M'.
171 ###############################################################################
173 $source_ws = fresh_workspace;
176 # open tabbed container ['A'['B' 'M']]
177 $target_ws = fresh_workspace;
185 cmd '[id="' . $S->{id} . '"] move container to mark target';
188 ($nodes, $focus) = get_ws_content($target_ws);
189 is(@{$nodes}, 1, 'there is a tabbed container');
191 $nodes = $nodes->[0]->{nodes};
192 is(@{$nodes}, 2, 'there are two tabs');
194 $nodes = $nodes->[1]->{nodes};
195 is(@{$nodes}, 3, 'the tab with the marked children has three children');
196 is($nodes->[0]->{window}, $B->{id}, 'B is the first tab');
197 is($nodes->[1]->{window}, $M->{id}, 'M is the second tab');
198 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
200 ###############################################################################
201 # Given 'S', 'A' and 'B' where 'A' and 'B' are inside the tabbed container 'M',
202 # when 'S' is moved to 'M', then 'S' ends up as a new tab in 'M'.
203 ###############################################################################
205 $source_ws = fresh_workspace;
207 $target_ws = fresh_workspace;
215 cmd '[id="' . $S->{id} . '"] move container to mark target';
218 ($nodes, $focus) = get_ws_content($target_ws);
219 is(@{$nodes}, 1, 'there is a tabbed container');
221 $nodes = $nodes->[0]->{nodes};
222 is(@{$nodes}, 3, 'there are three tabs');
224 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
225 is($nodes->[1]->{window}, $B->{id}, 'B is the second tab');
226 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
228 ###############################################################################
229 # Given 'S', 'F' and 'M' where 'F' and 'M' are containers inside the same
230 # tabbed container and where 'F' has the focus within that container, when
231 # 'S' is moved to 'M', then 'S' ends up behind 'F'.
232 ###############################################################################
234 # TODO needs to be clarified whether this is the behavior we want
236 ###############################################################################
237 # Given 'S' and 'M' where 'S' is floating and 'M' on a different workspace,
238 # when 'S' is moved to 'M', then 'S' is a floating container on the same
240 ###############################################################################
242 $source_ws = fresh_workspace;
243 $S = open_floating_window;
244 $target_ws = fresh_workspace;
248 cmd '[id="' . $S->{id} . '"] move container to mark target';
251 is(@{get_ws($target_ws)->{floating_nodes}}, 1, 'target workspace has the container now');
253 ###############################################################################
254 # Given 'S' and 'M' where 'M' is floating and on a different workspace,
255 # when 'S' is moved to 'M', then 'S' ends up as a tiling container on the
256 # same workspace as 'M'.
257 ###############################################################################
259 $source_ws = fresh_workspace;
261 $target_ws = fresh_workspace;
262 $M = open_floating_window;
265 cmd '[id="' . $S->{id} . '"] move container to mark target';
268 ($nodes, $focus) = get_ws_content($target_ws);
269 is(@{$nodes}, 1, 'tiling container moved to the target workspace');
271 ###############################################################################
272 # Given 'S' and 'M' are the same container, when 'S' is moved to 'M', then
273 # the command is ignored.
274 ###############################################################################
276 $ws = fresh_workspace;
281 cmd '[id="' . $S->{id} . '"] move container to mark target';
286 ###############################################################################