|
Line 0
Link Here
|
| 0 |
- |
1 |
package t::lib::Page::Members::Notices; |
|
|
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 t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation); |
| 25 |
|
| 26 |
use Koha::Exception::BadParameter; |
| 27 |
|
| 28 |
use t::lib::Page::Circulation::Circulation; |
| 29 |
|
| 30 |
|
| 31 |
sub new { |
| 32 |
my ($class, $params) = @_; |
| 33 |
unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { |
| 34 |
$params = {}; |
| 35 |
} |
| 36 |
$params->{resource} = '/cgi-bin/koha/members/notices.pl'; |
| 37 |
$params->{type} = 'staff'; |
| 38 |
|
| 39 |
$params->{getParams} = []; |
| 40 |
#Handle MANDATORY parameters |
| 41 |
if ($params->{borrowernumber}) { |
| 42 |
push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber}; |
| 43 |
} |
| 44 |
else { |
| 45 |
Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing."); |
| 46 |
} |
| 47 |
my $self = $class->SUPER::new($params); |
| 48 |
|
| 49 |
return $self; |
| 50 |
} |
| 51 |
|
| 52 |
################################################################################ |
| 53 |
=head UI Mapping helper subroutines |
| 54 |
See. Selenium documentation best practices for UI element mapping to common language descriptions. |
| 55 |
=cut |
| 56 |
################################################################################ |
| 57 |
|
| 58 |
sub _getNoticesTable { |
| 59 |
my ($self) = @_; |
| 60 |
my $d = $self->getDriver(); |
| 61 |
|
| 62 |
my $e = {}; |
| 63 |
|
| 64 |
eval { |
| 65 |
$e->{noticestable_headers} = $d->find_elements("#noticestable th", 'css'); |
| 66 |
}; |
| 67 |
eval { |
| 68 |
$e->{noticestable_cells} = $d->find_elements("#noticestable td", 'css'); |
| 69 |
}; |
| 70 |
eval { |
| 71 |
$e->{noticestable_rows} = $d->find_elements("#noticestable tr", 'css'); |
| 72 |
}; |
| 73 |
|
| 74 |
return $e; |
| 75 |
} |
| 76 |
|
| 77 |
################################################################################ |
| 78 |
=head PageObject Services |
| 79 |
|
| 80 |
=cut |
| 81 |
################################################################################ |
| 82 |
|
| 83 |
|
| 84 |
# column and row first index is 1 |
| 85 |
sub getTextInColumnAtRow { |
| 86 |
my ($self, $searchText, $params) = @_; |
| 87 |
my $d = $self->getDriver(); |
| 88 |
$self->debugTakeSessionSnapshot(); |
| 89 |
|
| 90 |
if (not exists $params->{column} or not exists $params->{row} or |
| 91 |
not $params->{column} or not $params->{row}) { |
| 92 |
warn "t::lib::Page::Members::Notices->getColumnAtRow must be called with column and row numbers, e.g. {column => 1, row=1}"; |
| 93 |
} |
| 94 |
|
| 95 |
my $col = $params->{column}; |
| 96 |
my $row = $params->{row}; |
| 97 |
|
| 98 |
my $cell = $d->find_element("#noticestable tr:nth-child($row) td:nth-child($col)"); |
| 99 |
|
| 100 |
ok(($cell->get_text() =~ /^(.*)$searchText(.*)$/), "Intra Notices Text \"$searchText\" found at column ". |
| 101 |
$params->{column}." row ".$params->{row}." matches \"".$cell->get_text()."\"."); |
| 102 |
|
| 103 |
return $self; |
| 104 |
} |
| 105 |
|
| 106 |
sub hasDeliveryNoteColumnInNoticesTable { |
| 107 |
my ($self) = @_; |
| 108 |
my $d = $self->getDriver(); |
| 109 |
$self->debugTakeSessionSnapshot(); |
| 110 |
|
| 111 |
my $elements = $self->_getNoticesTable(); |
| 112 |
|
| 113 |
my $headers = $elements->{noticestable_headers}; |
| 114 |
|
| 115 |
my $hasDeliveryNote = 0; |
| 116 |
|
| 117 |
foreach my $header(@$headers){ |
| 118 |
$hasDeliveryNote = 1 if ($header->get_text() =~ /^Delivery note$/); |
| 119 |
} |
| 120 |
|
| 121 |
ok($hasDeliveryNote, "Intra Notices Table has all headings"); |
| 122 |
|
| 123 |
return $self; |
| 124 |
} |
| 125 |
|
| 126 |
sub hasTextInTableCell { |
| 127 |
my ($self, $txt) = @_; |
| 128 |
my $d = $self->getDriver(); |
| 129 |
$self->debugTakeSessionSnapshot(); |
| 130 |
|
| 131 |
my $elements = $self->_getNoticesTable(); |
| 132 |
|
| 133 |
my $cells = $elements->{noticestable_cells}; |
| 134 |
|
| 135 |
my $hasText = 0; |
| 136 |
|
| 137 |
foreach my $cell(@$cells){ |
| 138 |
$hasText = 1 if ($cell->get_text() =~ /^(.*)$txt(.*)$/); |
| 139 |
} |
| 140 |
|
| 141 |
ok($hasText, "Intra Notices Found text '$txt' from table"); |
| 142 |
|
| 143 |
return $self; |
| 144 |
} |
| 145 |
|
| 146 |
sub verifyNoMessages { |
| 147 |
my ($self, $note) = @_; |
| 148 |
my $d = $self->getDriver(); |
| 149 |
$self->debugTakeSessionSnapshot(); |
| 150 |
|
| 151 |
my $dialog = $d->find_element("div.yui-b div.dialog", 'css')->get_text(); |
| 152 |
|
| 153 |
ok($dialog =~ /^There is no record of any(.*)$/, "Intra Notices No messages sent"); |
| 154 |
|
| 155 |
return $self; |
| 156 |
} |
| 157 |
|
| 158 |
sub openNotice { |
| 159 |
my ($self, $titleText) = @_; |
| 160 |
my $d = $self->getDriver(); |
| 161 |
$self->debugTakeSessionSnapshot(); |
| 162 |
|
| 163 |
my @titles = $d->find_elements(".notice-title", 'css'); |
| 164 |
|
| 165 |
my $opened = 0; |
| 166 |
foreach my $title (@titles){ |
| 167 |
if ($title->get_text() eq $titleText) { |
| 168 |
$title->click(); |
| 169 |
$opened++; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
ok(($opened > 0), "Opened ". $opened ." notices '".$titleText."' successfully."); |
| 174 |
|
| 175 |
return $self; |
| 176 |
} |
| 177 |
|
| 178 |
sub resendMessage { |
| 179 |
my ($self, $titleText, $shouldSucceed) = @_; |
| 180 |
my $d = $self->getDriver(); |
| 181 |
$self->debugTakeSessionSnapshot(); |
| 182 |
|
| 183 |
my @resendLinks = $d->find_elements('//tr/td[a//text()[contains(.,\''.$titleText.'\')]]/following-sibling::td[2]/div/a[text()=\'Resend\']', 'xpath'); |
| 184 |
|
| 185 |
my $resent = 0; |
| 186 |
foreach my $link (@resendLinks){ |
| 187 |
$link->click(); |
| 188 |
$resent++; |
| 189 |
} |
| 190 |
is(($resent > 0) ? 1:0, $shouldSucceed, "Resent ". $resent ." notices '".$titleText."' successfully."); |
| 191 |
|
| 192 |
return $self; |
| 193 |
} |
| 194 |
|
| 195 |
1; |