Implement the tick event

This makes our tests less flaky, shorter, and more readable.

fixes #2988
This commit is contained in:
Michael Stapelberg
2017-09-24 15:40:30 +02:00
parent 14c8cf8622
commit ce21de8dde
29 changed files with 457 additions and 734 deletions

View File

@ -27,51 +27,29 @@ workspace ws-left output fake-0
workspace ws-right output fake-1
EOT
my $i3 = i3(get_socket_path());
$i3->connect()->recv;
# subscribe to the 'focus' ipc event
my $focus = AnyEvent->condvar;
$i3->subscribe({
workspace => sub {
my ($event) = @_;
if ($event->{change} eq 'focus') {
$focus->send($event);
}
}
})->recv;
# give up after 0.5 seconds
my $timer = AnyEvent->timer(
after => 0.5,
cb => sub {
$focus->send(0);
}
);
# open two windows on the left output
cmd 'workspace ws-left';
open_window;
open_window;
sub focus_subtest {
my ($cmd, $want) = @_;
my @events = events_for(
sub { cmd $cmd },
'workspace');
my @focus = grep { $_->{change} eq 'focus' } @events;
is(scalar @focus, 1, 'Received 1 workspace::focus event');
is($focus[0]->{current}->{name}, 'ws-right', 'focus event gave the right workspace');
is(@{$focus[0]->{current}->{nodes}}, $want, 'focus event gave the right number of windows on the workspace');
}
# move a window over to the right output
cmd 'move right';
my $event = $focus->recv;
subtest 'move right (1)', \&focus_subtest, 'move right', 1;
ok($event, 'moving from workspace with two windows triggered focus ipc event');
is($event->{current}->{name}, 'ws-right', 'focus event gave the right workspace');
is(@{$event->{current}->{nodes}}, 1, 'focus event gave the right number of windows on the workspace');
# reset and try again
$focus = AnyEvent->condvar;
# move another window
cmd 'workspace ws-left';
$focus->recv;
$focus = AnyEvent->condvar;
cmd 'move right';
$event = $focus->recv;
ok($event, 'moving from workspace with one window triggered focus ipc event');
is($event->{current}->{name}, 'ws-right', 'focus event gave the right workspace');
is(@{$event->{current}->{nodes}}, 2, 'focus event gave the right number of windows on the workspace');
subtest 'move right (2)', \&focus_subtest, 'move right', 2;
done_testing;