]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/115-ipc-workspaces.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 115-ipc-workspaces.t
index 1dd12417c15e5675b3a8fb03c019849241e496b6..2bcc6d602f7ec4b57c317f111926a29c81926235 100644 (file)
 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
 
@@ -47,15 +36,11 @@ $i3->subscribe({
     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;
@@ -72,8 +57,20 @@ $t = AnyEvent->timer(
     }
 );
 
-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;