|
Line 0
Link Here
|
| 0 |
- |
1 |
package t::lib::Page::Circulation::Waitingreserves; |
|
|
2 |
|
| 3 |
# Copyright 2015 Open Source Freedom Fighters |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Scalar::Util qw(blessed); |
| 22 |
use Test::More; |
| 23 |
|
| 24 |
use base qw(t::lib::Page::Intra); |
| 25 |
|
| 26 |
use Koha::Exception::BadParameter; |
| 27 |
|
| 28 |
=head NAME t::lib::Page::Circulation::Waitingreserve |
| 29 |
|
| 30 |
=head SYNOPSIS |
| 31 |
|
| 32 |
waitingreserves.pl PageObject providing page functionality as a service! |
| 33 |
|
| 34 |
=cut |
| 35 |
|
| 36 |
=head new |
| 37 |
|
| 38 |
my $circulation = t::lib::Page::Circulation::Waitingreserves->new({borrowernumber => "1"}); |
| 39 |
|
| 40 |
Instantiates a WebDriver and loads the circ/waitingreserves.pl. |
| 41 |
@PARAM1 HASHRef of optional and MANDATORY parameters |
| 42 |
Optional extra parameters: |
| 43 |
allbranches => 1 #Show reserves from all branches |
| 44 |
|
| 45 |
@RETURNS t::lib::Page::Circulation::Waitingreserves, ready for user actions! |
| 46 |
=cut |
| 47 |
|
| 48 |
sub new { |
| 49 |
my ($class, $params) = @_; |
| 50 |
unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { |
| 51 |
$params = {}; |
| 52 |
} |
| 53 |
$params->{resource} = '/cgi-bin/koha/circ/waitingreserves.pl'; |
| 54 |
$params->{type} = 'staff'; |
| 55 |
|
| 56 |
$params->{getParams} = []; |
| 57 |
#Handle optional parameters |
| 58 |
if ($params->{allbranches}) { |
| 59 |
push @{$params->{getParams}}, "allbranches=".$params->{allbranches}; |
| 60 |
} |
| 61 |
|
| 62 |
my $self = $class->SUPER::new($params); |
| 63 |
|
| 64 |
#Set special page-dependent parameters |
| 65 |
$self->{waitingreserves}->{tabDisplayed} = 'waiting'; |
| 66 |
return $self; |
| 67 |
} |
| 68 |
|
| 69 |
################################################################################ |
| 70 |
=head UI Mapping helper subroutines |
| 71 |
See. Selenium documentation best practices for UI element mapping to common language descriptions. |
| 72 |
=cut |
| 73 |
################################################################################ |
| 74 |
|
| 75 |
sub _getTablist { |
| 76 |
my ($self) = @_; |
| 77 |
my $d = $self->getDriver(); |
| 78 |
|
| 79 |
my $holdswaiting_a = $d->find_element("ul a[href*='#holdswaiting']", 'css'); |
| 80 |
my $holdsover_a = $d->find_element("ul a[href*='#holdsover']", 'css'); |
| 81 |
|
| 82 |
my $e = {}; |
| 83 |
$e->{holdswaiting} = $holdswaiting_a; |
| 84 |
$e->{holdsover} = $holdsover_a; |
| 85 |
return $e; |
| 86 |
} |
| 87 |
|
| 88 |
=head _getHoldsRows |
| 89 |
@RETURNS HASHRef of |
| 90 |
HASHRef of HASHes of Selenium::Driver::Webelement-objects matching the table rows and columns. |
| 91 |
Also some special identifiers will be extracted. |
| 92 |
eg. { |
| 93 |
"1" => { |
| 94 |
waitingdate => Selenium::Driver::Webelement, |
| 95 |
lastpickupdate => Selenium::Driver::Webelement, |
| 96 |
... |
| 97 |
barcode => '167N03651343', |
| 98 |
biblionumber => 854323, |
| 99 |
}, |
| 100 |
"2" => { |
| 101 |
... |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
=cut |
| 106 |
sub _getHoldsRows { |
| 107 |
my ($self) = @_; |
| 108 |
my $d = $self->getDriver(); |
| 109 |
|
| 110 |
my $waitingOrOverdue = $self->{waitingreserves}->{tabDisplayed}; |
| 111 |
my $tableId = ($waitingOrOverdue && $waitingOrOverdue eq 'overdue') ? 'holdso' : 'holdst'; |
| 112 |
|
| 113 |
my $holdsRows_tr; |
| 114 |
eval { #We might not have any rows |
| 115 |
$holdsRows_tr = $d->find_elements("table#$tableId tbody tr", 'css'); |
| 116 |
}; |
| 117 |
my %holdsRows; |
| 118 |
for(my $i=0 ; $i<scalar(@$holdsRows_tr) ; $i++) { |
| 119 |
#Iterate every apiKey in the apiKeys table and prefetch the interesting data as text and available action elements. |
| 120 |
my $row = $holdsRows_tr->[$i]; |
| 121 |
$row->{waitingdate} = $d->find_child_element($row, "td.waitingdate", 'css'); |
| 122 |
$row->{lastpickupdate} = $d->find_child_element($row, "td.lastpickupdate", 'css'); |
| 123 |
$row->{resobjects} = $d->find_child_element($row, "td.resobjects", 'css'); |
| 124 |
$row->{borrower} = $d->find_child_element($row, "td.borrower", 'css'); |
| 125 |
$row->{location} = $d->find_child_element($row, "td.location", 'css'); |
| 126 |
$row->{copynumber} = $d->find_child_element($row, "td.copynumber", 'css'); |
| 127 |
$row->{enumchron} = $d->find_child_element($row, "td.enumchron", 'css'); |
| 128 |
$row->{action} = $d->find_child_element($row, "td.action", 'css'); |
| 129 |
$holdsRows{$i} = $row; |
| 130 |
|
| 131 |
#Extract textual identifiers |
| 132 |
my $titleText = $row->{resobjects}->get_text(); |
| 133 |
if ($titleText =~ /Barcode:\s+(\S+)/) { |
| 134 |
$row->{barcode} = $1; |
| 135 |
} |
| 136 |
else { |
| 137 |
warn __PACKAGE__."->assertHoldRowsVisible():> Couldn't extract barcode from title-column '$titleText'\n"; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
return \%holdsRows; |
| 142 |
} |
| 143 |
|
| 144 |
################################################################################ |
| 145 |
=head PageObject Services |
| 146 |
|
| 147 |
=cut |
| 148 |
################################################################################ |
| 149 |
|
| 150 |
sub viewAllLibraries { |
| 151 |
my ($self) = @_; |
| 152 |
my $d = $self->getDriver(); |
| 153 |
$self->debugTakeSessionSnapshot(); |
| 154 |
|
| 155 |
my $view_all_libraries_a = $d->find_element("a[href*='waitingreserves.pl?allbranches=1']", 'css'); |
| 156 |
$view_all_libraries_a->click(); |
| 157 |
|
| 158 |
$self->debugTakeSessionSnapshot(); |
| 159 |
return $self; |
| 160 |
} |
| 161 |
|
| 162 |
sub showHoldsWaiting { |
| 163 |
my ($self) = @_; |
| 164 |
my $d = $self->getDriver(); |
| 165 |
$self->debugTakeSessionSnapshot(); |
| 166 |
|
| 167 |
my $e = $self->_getTablist(); |
| 168 |
my $showWaiting_a = $e->{holdswaiting}; |
| 169 |
$showWaiting_a->click(); |
| 170 |
$self->{waitingreserves}->{tabDisplayed} = 'waiting'; |
| 171 |
|
| 172 |
$self->debugTakeSessionSnapshot(); |
| 173 |
return $self; |
| 174 |
} |
| 175 |
|
| 176 |
sub showHoldsOver { |
| 177 |
my ($self) = @_; |
| 178 |
my $d = $self->getDriver(); |
| 179 |
$self->debugTakeSessionSnapshot(); |
| 180 |
|
| 181 |
my $e = $self->_getTablist(); |
| 182 |
my $showOver_a = $e->{holdsover}; |
| 183 |
$showOver_a->click(); |
| 184 |
$self->{waitingreserves}->{tabDisplayed} = 'overdue'; |
| 185 |
|
| 186 |
$self->debugTakeSessionSnapshot(); |
| 187 |
return $self; |
| 188 |
} |
| 189 |
|
| 190 |
=head assertHoldRowsVisible |
| 191 |
|
| 192 |
@PARAM1 ARRAYref of HASHes. Represents the holds that must be present in the displayed holds table |
| 193 |
eg. [{ |
| 194 |
barcode => '167N0032112', |
| 195 |
}, |
| 196 |
] |
| 197 |
@RETURN t::lib::Page::Circulation::Waitingreserves-object |
| 198 |
=cut |
| 199 |
sub assertHoldRowsVisible { |
| 200 |
my ($self, $holds) = @_; |
| 201 |
my $d = $self->getDriver(); |
| 202 |
$self->debugTakeSessionSnapshot(); |
| 203 |
|
| 204 |
my $holdRows = $self->_getHoldsRows(); |
| 205 |
for (my $i=0 ; $i<scalar(@$holds) ; $i++) { |
| 206 |
my $h = $holds->[$i]; |
| 207 |
my $targetRow = $holdRows->{ $i }; |
| 208 |
is($targetRow->{barcode}, $h->{barcode}, |
| 209 |
"assertHoldRowsVisible: Row ".$i." barcodes '".$targetRow->{barcode}."' and '".$h->{barcode}."' match."); |
| 210 |
} |
| 211 |
|
| 212 |
return $self; |
| 213 |
} |
| 214 |
|
| 215 |
1; |