From dbf07b8cd3143660449cc49d855d2ceca56a42fe Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 9 Nov 2023 10:45:32 +0100 Subject: [PATCH] Bug 35284: Fix tests This fix patrons_search.t but other selenium tests certainly need adjustements Signed-off-by: David Cook Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 2 +- t/db_dependent/selenium/patrons_search.t | 47 ++++++++++--------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 84ca9d83d7..564edbba4b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -916,7 +916,7 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) { .column( i ) .search( val ) .draw(); - }, 1000 ); + }, 500); $( input_type, this ).on( 'keyup change', function () { if ( table_dt.column(i).search() !== this.value ) { diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t index e34fa52952..0fde7f7c03 100755 --- a/t/db_dependent/selenium/patrons_search.t +++ b/t/db_dependent/selenium/patrons_search.t @@ -22,6 +22,7 @@ my $original_DefaultPatronSearchFields = C4::Context->preference('DefaultPatronS my $original_DefaultPatronSearchMethod = C4::Context->preference('DefaultPatronSearchMethod'); my $original_PatronsPerPage = C4::Context->preference('PatronsPerPage'); our @cleanup; +our $DT_delay = 1; END { unless ( @cleanup ) { say "WARNING: Cleanup failed!" } @@ -196,7 +197,7 @@ subtest 'Search patrons' => sub { $s->submit_form; 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'); like ($td[2]->get_text, qr[\Q$firstname\E], '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" ); $s->fill_form( { search_patron_filter => 'test_patron' } ); $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->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' ); $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' ); # Reset the filters $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); $s->submit_form; - $s->wait_for_ajax; + sleep $DT_delay && $s->wait_for_ajax; # 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' ); @@ -253,16 +254,16 @@ subtest 'Search patrons' => sub { $s->fill_form( { search_patron_filter => 'test patron' } ); $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) ); $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); $s->submit_form; - $s->wait_for_ajax; + sleep $DT_delay && $s->wait_for_ajax; # Search on non-searchable attribute, we expect no result! $s->fill_form( { search_patron_filter => 'test_attr_1' } ); $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' ); @@ -272,20 +273,20 @@ subtest 'Search patrons' => sub { # Search on searchable attribute, we expect 2 patrons $s->fill_form( { search_patron_filter => 'test_attr_2' } ); $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' ); # Refine search and search for test_patron in all the data using the DT global search # No change in result expected, still 2 patrons $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' ); # Adding the surname of the first patron in the "Name" column # We expect only 1 result $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' ); subtest 'remember_search' => sub { @@ -296,7 +297,7 @@ subtest 'Search patrons' => sub { $driver->get( $base_url . "/members/members-home.pl" ); $s->fill_form( { search_patron_filter => 'test_patron' } ); $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; 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" ); $driver->find_element('//*[@id="memberresultst_next"]')->click; - $s->wait_for_ajax; + sleep $DT_delay && $s->wait_for_ajax; @checkboxes = $driver->find_elements( '//input[@type="checkbox"][@name="borrowernumber"]'); $checkboxes[0]->click; @@ -322,7 +323,7 @@ subtest 'Search patrons' => sub { $driver->get( $base_url . "/members/members-home.pl" ); $s->fill_form( { search_patron_filter => 'test_patron' } ); $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; 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"; $driver->find_element('//input[@id="new_patron_list"]')->send_keys($patron_list_name); $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." ); 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 ); @@ -349,44 +350,44 @@ subtest 'Search patrons' => sub { $driver->get( $base_url . "/members/members-home.pl" ); $s->fill_form( { search_patron_filter => 'test_patron' } ); $s->submit_form; - $s->wait_for_ajax; + sleep $DT_delay && $s->wait_for_ajax; $s->show_all_entries( '//div[@id="' . $table_id . '_wrapper"]' ); my $dob_search_filter = $s->driver->find_element( '//table[@id="' . $table_id . '"]//input[@placeholder="Date of birth search"]' ); $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' ); $dob_search_filter->clear; $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' ); $dob_search_filter->clear; $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' ); $dob_search_filter->clear; $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' ); $dob_search_filter->clear; $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' ); $dob_search_filter->clear; $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' ); $dob_search_filter->clear; $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' ); $dob_search_filter->clear; }; -- 2.39.5