File Coverage

blib/lib/Weasel/Widgets/Dojo/Option.pm
Criterion Covered Total %
statement 15 41 36.5
branch 0 8 0.0
condition 0 6 0.0
subroutine 5 10 50.0
pod 2 2 100.0
total 22 67 32.8


line stmt bran cond sub pod time code
1              
2             package Weasel::Widgets::Dojo::Option;
3              
4 1     1   1042 use strict;
  1         3  
  1         26  
5 1     1   5 use warnings;
  1         1  
  1         21  
6              
7 1     1   4 use Moose;
  1         1  
  1         4  
8 1     1   5941 use Weasel::Widgets::HTML::Selectable;
  1         31867  
  1         45  
9             extends 'Weasel::Widgets::HTML::Selectable';
10              
11 1     1   19 use Weasel::WidgetHandlers qw/ register_widget_handler /;
  1         2  
  1         383  
12              
13             register_widget_handler(__PACKAGE__, 'Dojo',
14             tag_name => 'tr',
15             attributes => {
16             role => 'option',
17             });
18              
19              
20             sub _option_popup {
21 0     0     my ($self) = @_;
22              
23             # Note, this assumes there are no pop-ups nested in the DOM,
24             # which from experimentation I believe to be true at this point
25 0           my $popup = $self->find('ancestor::*[@dijitpopupparent]');
26              
27 0           return $popup;
28             }
29              
30             sub click {
31 0     0 1   my ($self) = @_;
32 0           my $popup = $self->_option_popup;
33              
34 0           my $id = $popup->get_attribute('dijitpopupparent');
35 0           my $selector = $self->find("//*[\@id='$id']");
36 0 0         if (! $popup->is_displayed) {
37 0           $selector->click; # pop up the selector
38             $self->session->wait_for(
39             # Wait till popup opens
40             sub {
41 0     0     my $class = $selector->get_attribute('class');
42 0           return scalar( grep { $_ eq 'dijitHasDropDownOpen' }
  0            
43             split /\s+/, $class);
44 0           });
45             }
46 0           $self->SUPER::click;
47             $self->session->wait_for(
48             # Wait till popup closes
49             sub {
50 0     0     my $class = $selector->get_attribute('class');
51 0           return !scalar( grep { $_ eq 'dijitHasDropDownOpen' }
  0            
52             split /\s+/, $class) ;
53 0           });
54              
55 0           return;
56             }
57              
58             sub selected {
59 0     0 1   my ($self, $new_value) = @_;
60              
61 0 0         if (defined $new_value) {
62 0           my $selected = $self->get_attribute('aria-selected') eq 'true';
63 0 0 0       if ($new_value && ! $selected) {
    0 0        
64 0           $self->click; # select
65             }
66             elsif (! $new_value && $selected) {
67 0           $self->click; # unselect
68             }
69             }
70              
71 0           return $self->get_attribute('aria-selected') eq 'true';
72             }
73              
74              
75             1;