]> git.sur5r.net Git - i3/i3/blob - testcases/t/243-move-to-mark.t
Added testcases for 'move window|container to mark <str>'
[i3/i3] / testcases / t / 243-move-to-mark.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 # Tests for the 'move [window|container] to mark' command
18 # Ticket: #1643
19 use i3test;
20
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.
24
25 my ($A, $B, $S, $M, $F, $source_ws, $target_ws, $ws);
26 my ($nodes, $focus);
27 my $cmd_result;
28
29 ###############################################################################
30 # Given 'M' and 'S' in a horizontal split, when 'S' is moved to 'M', then
31 # verify that nothing changed.
32 ###############################################################################
33
34 $ws = fresh_workspace;
35 $M = open_window;
36 cmd 'mark target';
37 $S = open_window;
38
39 cmd 'move container to mark target';
40 sync_with_i3;
41
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');
46
47 ###############################################################################
48 # Given 'S' and 'M' in a horizontal split, when 'S' is moved to 'M', then
49 # both containers switch places.
50 ###############################################################################
51
52 $ws = fresh_workspace;
53 $S = open_window;
54 $M = open_window;
55 cmd 'mark target';
56 cmd 'focus left';
57
58 cmd 'move container to mark target';
59 sync_with_i3;
60
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');
65
66 ###############################################################################
67 # Given 'S' and no container 'M' exists, when 'S' is moved to 'M', then
68 # the command is unsuccessful.
69 ###############################################################################
70
71 $ws = fresh_workspace;
72 $S = open_window;
73
74 $cmd_result = cmd 'move container to mark absent';
75
76 is($cmd_result->[0]->{success}, 0, 'command was unsuccessful');
77
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 ###############################################################################
82
83 $source_ws = fresh_workspace;
84 $S = open_window;
85 $target_ws = fresh_workspace;
86 $M = open_window;
87 cmd 'mark target';
88
89 cmd '[id="' . $S->{id} . '"] move container to mark target';
90 sync_with_i3;
91
92 ($nodes, $focus) = get_ws_content($source_ws);
93 is(@{$nodes}, 0, 'source workspace is empty');
94
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');
99
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 ###############################################################################
104
105 # TODO
106
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 ###############################################################################
111
112 $source_ws = fresh_workspace;
113 $S = open_window;
114
115 # open tabbed container ['A' 'M' 'B']
116 $target_ws = fresh_workspace;
117 cmd 'layout tabbed';
118 $A = open_window;
119 $M = open_window;
120 cmd 'mark target';
121 $B = open_window;
122
123 cmd '[id="' . $S->{id} . '"] move container to mark target';
124 sync_with_i3;
125
126 ($nodes, $focus) = get_ws_content($target_ws);
127 is(@{$nodes}, 1, 'there is a tabbed container');
128
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');
135
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
139 # within 'M'.
140 ###############################################################################
141
142 $source_ws = fresh_workspace;
143 $S = open_window;
144
145 $target_ws = fresh_workspace;
146 cmd 'layout tabbed';
147 $A = open_window;
148 cmd 'focus parent';
149 cmd 'mark target';
150 cmd 'focus child';
151 $B = open_window;
152 cmd 'split h';
153 $F = open_window;
154
155 cmd '[id="' . $S->{id} . '"] move container to mark target';
156 sync_with_i3;
157
158 ($nodes, $focus) = get_ws_content($target_ws);
159 is(@{$nodes}, 1, 'there is a tabbed container');
160
161 $nodes = $nodes->[0]->{nodes};
162 is(@{$nodes}, 3, 'there are three tabs');
163
164 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
165 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
166
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 ###############################################################################
172
173 $source_ws = fresh_workspace;
174 $S = open_window;
175
176 # open tabbed container ['A'['B' 'M']]
177 $target_ws = fresh_workspace;
178 cmd 'layout tabbed';
179 $A = open_window;
180 $B = open_window;
181 cmd 'split h';
182 $M = open_window;
183 cmd 'mark target';
184
185 cmd '[id="' . $S->{id} . '"] move container to mark target';
186 sync_with_i3;
187
188 ($nodes, $focus) = get_ws_content($target_ws);
189 is(@{$nodes}, 1, 'there is a tabbed container');
190
191 $nodes = $nodes->[0]->{nodes};
192 is(@{$nodes}, 2, 'there are two tabs');
193
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');
199
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 ###############################################################################
204
205 $source_ws = fresh_workspace;
206 $S = open_window;
207 $target_ws = fresh_workspace;
208 cmd 'layout tabbed';
209 $A = open_window;
210 $B = open_window;
211 cmd 'focus parent';
212 cmd 'mark target';
213 cmd 'focus child';
214
215 cmd '[id="' . $S->{id} . '"] move container to mark target';
216 sync_with_i3;
217
218 ($nodes, $focus) = get_ws_content($target_ws);
219 is(@{$nodes}, 1, 'there is a tabbed container');
220
221 $nodes = $nodes->[0]->{nodes};
222 is(@{$nodes}, 3, 'there are three tabs');
223
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');
227
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 ###############################################################################
233
234 # TODO needs to be clarified whether this is the behavior we want
235
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
239 # workspaces as 'M'.
240 ###############################################################################
241
242 $source_ws = fresh_workspace;
243 $S = open_floating_window;
244 $target_ws = fresh_workspace;
245 $M = open_window;
246 cmd 'mark target';
247
248 cmd '[id="' . $S->{id} . '"] move container to mark target';
249 sync_with_i3;
250
251 is(@{get_ws($target_ws)->{floating_nodes}}, 1, 'target workspace has the container now');
252
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 ###############################################################################
258
259 $source_ws = fresh_workspace;
260 $S = open_window;
261 $target_ws = fresh_workspace;
262 $M = open_floating_window;
263 cmd 'mark target';
264
265 cmd '[id="' . $S->{id} . '"] move container to mark target';
266 sync_with_i3;
267
268 ($nodes, $focus) = get_ws_content($target_ws);
269 is(@{$nodes}, 1, 'tiling container moved to the target workspace');
270
271 ###############################################################################
272
273 done_testing;