File: 21-tab-activate.t

package info (click to toggle)
libtickit-widget-tabbed-perl 0.028-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 260 kB
  • sloc: perl: 1,851; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 961 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl

use v5.26;
use warnings;

use Test::More;
use Test::Identity;

use Tickit::Widget::Static;
use Tickit::Widget::Tabbed;

my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" );

my @tabs = map {
        $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_" ), label => "tab$_" )
} 0 .. 2;

my $activated_self;
my $activated = 0;
$tabs[1]->set_on_activated( sub {
        ( $activated_self ) = @_;
        $activated++
} );

is( $activated, 0, '$activated initially' );

$widget->activate_tab( 1 );

is( $activated, 1, '$activated after ->activate_tab' );
identical( $activated_self, $tabs[1], '$activate_self' );

$widget->activate_tab( 0 );

is( $activated, 1, '$activated unchanged after ->activate_tab on a different tab' );

my $deactivated = 0;
$tabs[0]->set_on_deactivated( sub { $deactivated++ } );

$widget->activate_tab( 1 );

is( $deactivated, 1, '$deactivated after ->activate_tab elsewhere' );

done_testing;