]> git.sur5r.net Git - i3/i3/blob - testcases/t/227-ipc-workspace-empty.t
Implement the tick event
[i3/i3] / testcases / t / 227-ipc-workspace-empty.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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 the workspace "empty" event semantics.
18 #
19 use i3test;
20
21 ################################################################################
22 # check that the workspace empty event is sent upon workspace switch when the
23 # old workspace is empty
24 ################################################################################
25 subtest 'Workspace empty event upon switch', sub {
26     my $ws2 = fresh_workspace;
27     my $w2 = open_window();
28     my $ws1 = fresh_workspace;
29     my $w1 = open_window();
30
31     cmd '[id="' . $w1->id . '"] kill';
32
33     my $cond = AnyEvent->condvar;
34     my @events = events_for(
35         sub { cmd "workspace $ws2" },
36         'workspace');
37
38     is(scalar @events, 2, 'Received 2 event');
39     is($events[1]->{change}, 'empty', '"Empty" event received upon workspace switch');
40     is($events[1]->{current}->{name}, $ws1, '"current" property should be set to the workspace con');
41 };
42
43 ################################################################################
44 # check that no workspace empty event is sent upon workspace switch if the
45 # workspace is not empty
46 ################################################################################
47 subtest 'No workspace empty event', sub {
48     my $ws2 = fresh_workspace;
49     my $w2 = open_window();
50     my $ws1 = fresh_workspace;
51     my $w1 = open_window();
52
53     my @events = events_for(
54         sub { cmd "workspace $ws2" },
55         'workspace');
56
57     is(scalar @events, 1, 'Received 1 event');
58     is($events[0]->{change}, 'focus', 'Event change is "focus"');
59 };
60
61 ################################################################################
62 # check that workspace empty event is sent when the last window has been closed
63 # on invisible workspace
64 ################################################################################
65 subtest 'Workspace empty event upon window close', sub {
66     my $ws1 = fresh_workspace;
67     my $w1 = open_window();
68     my $ws2 = fresh_workspace;
69     my $w2 = open_window();
70
71     my @events = events_for(
72         sub {
73             $w1->unmap;
74             sync_with_i3;
75         },
76         'workspace');
77
78     is(scalar @events, 1, 'Received 1 event');
79     is($events[0]->{change}, 'empty', '"Empty" event received upon window close');
80     is($events[0]->{current}->{name}, $ws1, '"current" property should be set to the workspace con');
81 };
82
83 done_testing;