use i3test;
my $i3 = i3(get_socket_path());
+$i3->connect()->recv;
################################
# Workspaces requests and events
################################
-my $workspaces = $i3->get_workspaces->recv;
-
-ok(@{$workspaces} > 0, "More than zero workspaces found");
-
-# my $name_exists = all { defined($_->{name}) } @{$workspaces};
-# ok($name_exists, "All workspaces have a name");
-
-# Focused workspace
-my $focused;
-foreach (@{$workspaces}) {
- $focused = $_ if $_->{focused};
-}
-ok($focused, "At least one workspace is focused");
+my $old_ws = get_ws(focused_ws());
# Events
workspace => sub {
my ($event) = @_;
if ($event->{change} eq 'init') {
- $init->send(1);
+ $init->send($event);
} elsif ($event->{change} eq 'focus') {
- # Check that we have the old and new workspace
- $focus->send(
- $event->{current}->{name} == '2' &&
- $event->{old}->{name} == $focused->{name}
- );
+ $focus->send($event);
} elsif ($event->{change} eq 'empty') {
- $empty->send(1);
+ $empty->send($event);
}
}
})->recv;
}
);
-ok($init->recv, 'Workspace "init" event received');
-ok($focus->recv, 'Workspace "focus" event received');
-ok($empty->recv, 'Workspace "empty" event received');
+my $init_event = $init->recv;
+my $focus_event = $focus->recv;
+my $empty_event = $empty->recv;
+
+my $current_ws = get_ws(focused_ws());
+
+ok($init_event, 'workspace "init" event received');
+is($init_event->{current}->{id}, $current_ws->{id}, 'the "current" property should contain the initted workspace con');
+
+ok($focus_event, 'workspace "focus" event received');
+is($focus_event->{current}->{id}, $current_ws->{id}, 'the "current" property should contain the focused workspace con');
+is($focus_event->{old}->{id}, $old_ws->{id}, 'the "old" property should contain the workspace con that was focused last');
+
+ok($empty_event, 'workspace "empty" event received');
+is($empty_event->{current}->{id}, $old_ws->{id}, 'the "current" property should contain the emptied workspace con');
done_testing;