Skip to content

Commit

Permalink
fix(Tests): correctly display next scheduled date
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Oct 1, 2024
1 parent 98f9786 commit e8f1b95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion includes/models/class-test-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public static function get_calculated_status( $test_run ) {
return 'has-alerts';
}

if ( ! empty( $test_run->started_at && empty( $test_run->finished_at ) ) ) {
if ( ! empty( $test_run->started_at ) && empty( $test_run->finished_at ) ) {
return 'running';
}

Expand Down Expand Up @@ -531,4 +531,17 @@ public static function get_trigger_note( $test_run ) {
return $test_run->trigger_notes ?? '';
}
}

public static function get_next_scheduled_run() {
global $wpdb;

$test_runs_table = Test_Runs_Table::get_table_name();

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- It's ok.
$test_run = $wpdb->get_row(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- It's ok.
"SELECT * FROM $test_runs_table WHERE finished_at IS NULL AND scheduled_at IS NOT NULL ORDER BY scheduled_at ASC LIMIT 1",
);
return empty( $test_run ) ? null : static::cast_values( $test_run );
}
}
5 changes: 3 additions & 2 deletions includes/models/class-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,9 @@ public static function get_status_data( $test ) {
case 'scheduled':
$class = 'waiting';
$text = esc_html__( 'Scheduled', 'visual-regression-tests' );
if ( $test->next_run_date ) {
$instructions = Date_Time_Helpers::get_formatted_relative_date_time( $test->next_run_date );
$next_run = Test_Run::get_next_scheduled_run();
if ( $next_run ) {
$instructions = Date_Time_Helpers::get_formatted_relative_date_time( $next_run->scheduled_at );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required here.
if ( $has_subscription && isset( $_GET['page'] ) && 'vrts-tests' === $_GET['page'] ) {
Expand Down

0 comments on commit e8f1b95

Please sign in to comment.