Bug 35284: Fix tests

This fix patrons_search.t but other selenium tests certainly need
adjustements

Signed-off-by: David Cook <dcook@prosentient.com.au>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-11-09 10:45:32 +01:00 committed by Tomas Cohen Arazi
parent 5220dd6004
commit dbf07b8cd3
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 25 additions and 24 deletions

View file

@ -916,7 +916,7 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) {
.column( i ) .column( i )
.search( val ) .search( val )
.draw(); .draw();
}, 1000 ); }, 500);
$( input_type, this ).on( 'keyup change', function () { $( input_type, this ).on( 'keyup change', function () {
if ( table_dt.column(i).search() !== this.value ) { if ( table_dt.column(i).search() !== this.value ) {

View file

@ -22,6 +22,7 @@ my $original_DefaultPatronSearchFields = C4::Context->preference('DefaultPatronS
my $original_DefaultPatronSearchMethod = C4::Context->preference('DefaultPatronSearchMethod'); my $original_DefaultPatronSearchMethod = C4::Context->preference('DefaultPatronSearchMethod');
my $original_PatronsPerPage = C4::Context->preference('PatronsPerPage'); my $original_PatronsPerPage = C4::Context->preference('PatronsPerPage');
our @cleanup; our @cleanup;
our $DT_delay = 1;
END { END {
unless ( @cleanup ) { say "WARNING: Cleanup failed!" } unless ( @cleanup ) { say "WARNING: Cleanup failed!" }
@ -196,7 +197,7 @@ subtest 'Search patrons' => sub {
$s->submit_form; $s->submit_form;
my $first_patron = $patrons[0]; my $first_patron = $patrons[0];
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
my @td = $driver->find_elements('//table[@id="'.$table_id.'"]/tbody/tr/td'); my @td = $driver->find_elements('//table[@id="'.$table_id.'"]/tbody/tr/td');
like ($td[2]->get_text, qr[\Q$firstname\E], like ($td[2]->get_text, qr[\Q$firstname\E],
'Column "Name" should be the 3rd and contain the firstname correctly filtered' 'Column "Name" should be the 3rd and contain the firstname correctly filtered'
@ -231,20 +232,20 @@ subtest 'Search patrons' => sub {
$driver->get( $base_url . "/members/members-home.pl" ); $driver->get( $base_url . "/members/members-home.pl" );
$s->fill_form( { search_patron_filter => 'test_patron' } ); $s->fill_form( { search_patron_filter => 'test_patron' } );
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
$s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron'); $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons), 'Searching in standard brings back correct results' ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons), 'Searching in standard brings back correct results' );
$s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$library->branchcode.'"]')->click; $s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$library->branchcode.'"]')->click;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 25, $total_number_of_patrons), 'Filtering on library works in combination with main search' ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 25, $total_number_of_patrons), 'Filtering on library works in combination with main search' );
# Reset the filters # Reset the filters
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click();
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
# And make sure all the patrons are present # And make sure all the patrons are present
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons), 'Resetting filters works as expected' ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons), 'Resetting filters works as expected' );
@ -253,16 +254,16 @@ subtest 'Search patrons' => sub {
$s->fill_form( { search_patron_filter => 'test patron' } ); $s->fill_form( { search_patron_filter => 'test patron' } );
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons) ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons) );
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click();
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
# Search on non-searchable attribute, we expect no result! # Search on non-searchable attribute, we expect no result!
$s->fill_form( { search_patron_filter => 'test_attr_1' } ); $s->fill_form( { search_patron_filter => 'test_attr_1' } );
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('No entries to show (filtered from %s total entries)', $total_number_of_patrons), 'Searching on a non-searchable attribute returns no results' ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('No entries to show (filtered from %s total entries)', $total_number_of_patrons), 'Searching on a non-searchable attribute returns no results' );
@ -272,20 +273,20 @@ subtest 'Search patrons' => sub {
# Search on searchable attribute, we expect 2 patrons # Search on searchable attribute, we expect 2 patrons
$s->fill_form( { search_patron_filter => 'test_attr_2' } ); $s->fill_form( { search_patron_filter => 'test_attr_2' } );
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons), 'Searching on a searchable attribute returns correct results' ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons), 'Searching on a searchable attribute returns correct results' );
# Refine search and search for test_patron in all the data using the DT global search # Refine search and search for test_patron in all the data using the DT global search
# No change in result expected, still 2 patrons # No change in result expected, still 2 patrons
$s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron'); $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons), 'Refining with DataTables search works to further filter the original query' ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons), 'Refining with DataTables search works to further filter the original query' );
# Adding the surname of the first patron in the "Name" column # Adding the surname of the first patron in the "Name" column
# We expect only 1 result # We expect only 1 result
$s->driver->find_element('//table[@id="'.$table_id.'"]//input[@placeholder="Name search"]')->send_keys($patrons[0]->surname); $s->driver->find_element('//table[@id="'.$table_id.'"]//input[@placeholder="Name search"]')->send_keys($patrons[0]->surname);
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 1, 1, $total_number_of_patrons), 'Refining with header filters works to further filter the original query' ); is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 1, 1, $total_number_of_patrons), 'Refining with header filters works to further filter the original query' );
subtest 'remember_search' => sub { subtest 'remember_search' => sub {
@ -296,7 +297,7 @@ subtest 'Search patrons' => sub {
$driver->get( $base_url . "/members/members-home.pl" ); $driver->get( $base_url . "/members/members-home.pl" );
$s->fill_form( { search_patron_filter => 'test_patron' } ); $s->fill_form( { search_patron_filter => 'test_patron' } );
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
my $patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text; my $patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text;
is( $patron_selected_text, "", "Patrons selected is not displayed" ); is( $patron_selected_text, "", "Patrons selected is not displayed" );
@ -311,7 +312,7 @@ subtest 'Search patrons' => sub {
is( $patron_selected_text, "Patrons selected: 2", "Two patrons are selected" ); is( $patron_selected_text, "Patrons selected: 2", "Two patrons are selected" );
$driver->find_element('//*[@id="memberresultst_next"]')->click; $driver->find_element('//*[@id="memberresultst_next"]')->click;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
@checkboxes = $driver->find_elements( @checkboxes = $driver->find_elements(
'//input[@type="checkbox"][@name="borrowernumber"]'); '//input[@type="checkbox"][@name="borrowernumber"]');
$checkboxes[0]->click; $checkboxes[0]->click;
@ -322,7 +323,7 @@ subtest 'Search patrons' => sub {
$driver->get( $base_url . "/members/members-home.pl" ); $driver->get( $base_url . "/members/members-home.pl" );
$s->fill_form( { search_patron_filter => 'test_patron' } ); $s->fill_form( { search_patron_filter => 'test_patron' } );
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
$patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text; $patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text;
is( $patron_selected_text, "Patrons selected: 3", "Three patrons still selected" ); is( $patron_selected_text, "Patrons selected: 3", "Three patrons still selected" );
@ -331,7 +332,7 @@ subtest 'Search patrons' => sub {
my $patron_list_name = "my new list"; my $patron_list_name = "my new list";
$driver->find_element('//input[@id="new_patron_list"]')->send_keys($patron_list_name); $driver->find_element('//input[@id="new_patron_list"]')->send_keys($patron_list_name);
$driver->find_element('//button[@id="add_to_patron_list_submit"]')->click; $driver->find_element('//button[@id="add_to_patron_list_submit"]')->click;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( $driver->find_element('//*[@id="patron_list_dialog"]')->get_text, "Added 3 patrons to $patron_list_name." ); is( $driver->find_element('//*[@id="patron_list_dialog"]')->get_text, "Added 3 patrons to $patron_list_name." );
my $patron_list = $schema->resultset('PatronList')->search({ name => $patron_list_name })->next; my $patron_list = $schema->resultset('PatronList')->search({ name => $patron_list_name })->next;
is( $schema->resultset('PatronListPatron')->search({ patron_list_id => $patron_list->patron_list_id })->count, 3 ); is( $schema->resultset('PatronListPatron')->search({ patron_list_id => $patron_list->patron_list_id })->count, 3 );
@ -349,44 +350,44 @@ subtest 'Search patrons' => sub {
$driver->get( $base_url . "/members/members-home.pl" ); $driver->get( $base_url . "/members/members-home.pl" );
$s->fill_form( { search_patron_filter => 'test_patron' } ); $s->fill_form( { search_patron_filter => 'test_patron' } );
$s->submit_form; $s->submit_form;
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
$s->show_all_entries( '//div[@id="' . $table_id . '_wrapper"]' ); $s->show_all_entries( '//div[@id="' . $table_id . '_wrapper"]' );
my $dob_search_filter = my $dob_search_filter =
$s->driver->find_element( '//table[@id="' . $table_id . '"]//input[@placeholder="Date of birth search"]' ); $s->driver->find_element( '//table[@id="' . $table_id . '"]//input[@placeholder="Date of birth search"]' );
$dob_search_filter->send_keys('1980'); $dob_search_filter->send_keys('1980');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( is_patron_shown($patron_27), 1, 'search by correct year shows the patron' ); is( is_patron_shown($patron_27), 1, 'search by correct year shows the patron' );
$dob_search_filter->clear; $dob_search_filter->clear;
$dob_search_filter->send_keys('1986'); $dob_search_filter->send_keys('1986');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( is_patron_shown($patron_27), 0, 'search by incorrect year does not show the patron' ); is( is_patron_shown($patron_27), 0, 'search by incorrect year does not show the patron' );
$dob_search_filter->clear; $dob_search_filter->clear;
$dob_search_filter->send_keys('1980-06'); $dob_search_filter->send_keys('1980-06');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( is_patron_shown($patron_27), 1, 'search by correct year-month shows the patron' ); is( is_patron_shown($patron_27), 1, 'search by correct year-month shows the patron' );
$dob_search_filter->clear; $dob_search_filter->clear;
$dob_search_filter->send_keys('1980-06-17'); $dob_search_filter->send_keys('1980-06-17');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( is_patron_shown($patron_27), 1, 'search by correct full iso date shows the patron' ); is( is_patron_shown($patron_27), 1, 'search by correct full iso date shows the patron' );
$dob_search_filter->clear; $dob_search_filter->clear;
$dob_search_filter->send_keys('1986-06-17'); $dob_search_filter->send_keys('1986-06-17');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( is_patron_shown($patron_27), 0, 'search by incorrect full iso date does not show the patron' ); is( is_patron_shown($patron_27), 0, 'search by incorrect full iso date does not show the patron' );
$dob_search_filter->clear; $dob_search_filter->clear;
$dob_search_filter->send_keys('17/06/1980'); $dob_search_filter->send_keys('17/06/1980');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( is_patron_shown($patron_27), 1, 'search by correct full formatted date shows the patron' ); is( is_patron_shown($patron_27), 1, 'search by correct full formatted date shows the patron' );
$dob_search_filter->clear; $dob_search_filter->clear;
$dob_search_filter->send_keys('17/06/1986'); $dob_search_filter->send_keys('17/06/1986');
$s->wait_for_ajax; sleep $DT_delay && $s->wait_for_ajax;
is( is_patron_shown($patron_27), 0, 'search by incorrect full formatted date does not show the patron' ); is( is_patron_shown($patron_27), 0, 'search by incorrect full formatted date does not show the patron' );
$dob_search_filter->clear; $dob_search_filter->clear;
}; };