Commit | Line | Data |
7adfd53f |
1 | package RTest::UI::FocusStack; |
2 | |
3 | use base qw/Test::Class/; |
4 | use Reaction::Class; |
5 | use Reaction::UI::FocusStack; |
6 | use aliased "Reaction::UI::ViewPort"; |
7 | use Test::More (); |
8 | use Test::Memory::Cycle; |
9 | |
10 | has 'stack' => (isa => 'Reaction::UI::FocusStack', is => 'rw', set_or_lazy_build('stack')); |
11 | |
12 | sub build_stack { |
13 | return Reaction::UI::FocusStack->new; |
14 | } |
15 | |
16 | sub test_stack :Tests { |
17 | my $self = shift; |
18 | my $stack = $self->build_stack; |
19 | my $ctx = bless({}, 'Catalyst'); |
20 | Test::More::ok(!$stack->has_loc_prefix, 'No location prefix'); |
21 | Test::More::cmp_ok($stack->vp_count, '==', 0, 'Empty viewport stack'); |
22 | my $vp = $stack->push_viewport(ViewPort, ctx => $ctx); |
23 | Test::More::is($vp->location, '0', 'New vp has location 0'); |
24 | Test::More::cmp_ok($stack->vp_count, '==', 1, 'Viewport count 1'); |
25 | Test::More::is($stack->vp_head, $vp, 'Head set ok'); |
26 | Test::More::is($stack->vp_tail, $vp, 'Tail set ok'); |
27 | my $vp2 = $stack->push_viewport(ViewPort, ctx => $ctx); |
28 | Test::More::is($vp2->location, '1', 'New vp has location 1'); |
29 | Test::More::cmp_ok($stack->vp_count, '==', 2, 'Viewport count 2'); |
30 | Test::More::is($stack->vp_head, $vp, 'Head set ok'); |
31 | Test::More::is($stack->vp_tail, $vp2, 'Tail set ok'); |
32 | Test::More::is($vp->inner, $vp2, 'Inner ok on head'); |
33 | Test::More::is($vp2->outer, $vp, 'Outer ok on tail'); |
34 | Test::More::is($vp->focus_stack, $stack, 'Head focus_stack ok'); |
35 | Test::More::is($vp2->focus_stack, $stack, 'Tail focus_stack ok'); |
36 | memory_cycle_ok($stack, 'No cycles in the stack'); |
37 | my $vp3 = $stack->push_viewport(ViewPort, ctx => $ctx); |
38 | my $vp4 = $stack->push_viewport(ViewPort, ctx => $ctx); |
39 | Test::More::is($stack->vp_tail, $vp4, 'Tail still ok'); |
40 | Test::More::cmp_ok($stack->vp_count, '==', 4, 'Count still ok'); |
41 | $stack->pop_viewports_to($vp3); |
42 | Test::More::is($stack->vp_tail, $vp2, 'Correct pop to'); |
43 | Test::More::cmp_ok($stack->vp_count, '==', 2, 'Count after pop to'); |
44 | Test::More::is($stack->vp_head, $vp, 'Head unchanged'); |
45 | Test::More::is($stack->vp_tail, $vp2, 'Tail back to vp2'); |
46 | my $pop_ret = $stack->pop_viewport; |
47 | Test::More::is($vp2, $pop_ret, 'Correct viewport popped'); |
48 | Test::More::is($stack->vp_head, $vp, 'Head unchanged'); |
49 | Test::More::is($stack->vp_tail, $vp, 'Tail now head'); |
50 | $stack->pop_viewport; |
51 | Test::More::ok(!defined($stack->vp_head), 'Head cleared'); |
52 | Test::More::ok(!defined($stack->vp_tail), 'Tail cleared'); |
53 | Test::More::cmp_ok($stack->vp_count, '==', 0, 'Count Zero'); |
54 | } |
55 | |
56 | 1; |