Skip to content

Commit

Permalink
fix(Runs): correctly show alerts and receipt with deleted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Oct 24, 2024
1 parent e603f68 commit 943bb9b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
17 changes: 7 additions & 10 deletions components/emails/test-run/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,15 @@
</tr>
<?php

$alerts_post_ids = wp_list_pluck( $data['alerts'], 'post_id' );
$tests_post_ids = wp_list_pluck( $data['tests'], 'post_id' );

foreach ( $data['tests'] as $test ) :
$alert = array_values( array_filter( $data['alerts'], static function( $alert ) use ( $test ) {
return $alert->post_id === $test->post_id;
foreach ( $data['test_post_ids'] as $post_id ) :
$alert = array_values( array_filter( $data['alerts'], static function( $alert ) use ( $post_id ) {
return $alert->post_id === $post_id;
} ) );
$difference = $alert ? ceil( $alert[0]->differences ) : 0;
?>
<tr>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #2C3338; mso-line-height-rule: exactly; text-align: left;">
<a style="color: #2C3338; text-decoration: none" href="<?php echo esc_url( get_permalink( $test->post_id ) ); ?>"><?php echo esc_html( Url_Helpers::get_relative_permalink( $test->post_id ) ); ?></a>
<a style="color: #2C3338; text-decoration: none" href="<?php echo esc_url( get_permalink( $post_id ) ); ?>"><?php echo esc_html( Url_Helpers::get_relative_permalink( $post_id ) ); ?></a>
</td>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #2C3338; mso-line-height-rule: exactly; text-align: right;">
<?php $difference_url = $difference ? Url_Helpers::get_alert_page( $alert[0]->id, $data['run']->id ) : Url_Helpers::get_alerts_page( $data['run']->id ); ?>
Expand Down Expand Up @@ -207,17 +204,17 @@
<?php
printf(
/* translators: %s. Number of tests */
esc_html( _n( '%s Test', '%s Tests', count( $data['tests'] ), 'visual-regression-tests' ) ), count( $data['tests'] )
esc_html( _n( '%s Test', '%s Tests', count( $data['test_post_ids'] ), 'visual-regression-tests' ) ), count( $data['test_post_ids'] )
); ?>
</th>
</tr>
<tr>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #4ab866; mso-line-height-rule: exactly; text-align: left;"><?php esc_html_e( 'Passed', 'visual-regression-tests' ); ?></td>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #4ab866; mso-line-height-rule: exactly; text-align: right;"><?php echo esc_html( count( $tests_post_ids ) - count( $alerts_post_ids ) ); ?></td>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #4ab866; mso-line-height-rule: exactly; text-align: right;"><?php echo esc_html( count( $data['test_post_ids'] ) - count( $data['alerts'] ) ); ?></td>
</tr>
<tr>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #b32d2e; mso-line-height-rule: exactly; text-align: left;"><?php esc_html_e( 'Changes Detected', 'visual-regression-tests' ); ?></td>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #b32d2e; mso-line-height-rule: exactly; text-align: right;"><?php echo esc_html( count( $alerts_post_ids ) ); ?></td>
<td style="padding-top: 2px; padding-bottom: 2px; vertical-align: top; font-size: 12px; line-height: 16px; color: #b32d2e; mso-line-height-rule: exactly; text-align: right;"><?php echo esc_html( count( $data['alerts'] ) ); ?></td>
</tr>
</table>
</td>
Expand Down
17 changes: 7 additions & 10 deletions components/test-run-receipt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Models\Test_Run;

$alerts_post_ids = wp_list_pluck( $data['alerts'], 'post_id' );
$tests_post_ids = wp_list_pluck( $data['tests'], 'post_id' );

$trigger_note = Test_Run::get_trigger_note( $data['run'] );

?>
Expand Down Expand Up @@ -38,14 +35,14 @@
<span><?php esc_html_e( 'Difference', 'visual-regression-tests' ); ?></span>
</div>
<?php
foreach ( $data['tests'] as $test ) :
$alert = array_values( array_filter( $data['alerts'], static function( $alert ) use ( $test ) {
return $alert->post_id === $test->post_id;
foreach ( $data['test_post_ids'] as $post_id ) :
$alert = array_values( array_filter( $data['alerts'], static function( $alert ) use ( $post_id ) {
return $alert->post_id === $post_id;
} ) );
$difference = $alert ? ceil( $alert[0]->differences ) : 0;
?>
<div class="vrts-test-run-receipt__pages-status-row">
<a href="<?php echo esc_url( get_permalink( $test->post_id ) ); ?>"><?php echo esc_html( Url_Helpers::get_relative_permalink( $test->post_id ) ); ?></a>
<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>"><?php echo esc_html( Url_Helpers::get_relative_permalink( $post_id ) ); ?></a>
<span>
<?php
printf(
Expand All @@ -65,7 +62,7 @@
<?php
printf(
/* translators: %s. Number of tests */
esc_html( _n( '%s Test', '%s Tests', count( $data['tests'] ), 'visual-regression-tests' ) ), count( $data['tests'] )
esc_html( _n( '%s Test', '%s Tests', count( $data['test_post_ids'] ), 'visual-regression-tests' ) ), count( $data['test_post_ids'] )
);
?>
</span>
Expand All @@ -74,7 +71,7 @@
<span><?php esc_html_e( 'Passed', 'visual-regression-tests' ); ?></span>
<span>
<?php
$passed_tests_count = count( $tests_post_ids ) - count( $alerts_post_ids );
$passed_tests_count = count( $data['test_post_ids'] ) - count( $data['alerts'] );
printf(
/* translators: %s. Number of tests */
esc_html( _n( '%s Test', '%s Tests', $passed_tests_count, 'visual-regression-tests' ) ), esc_html( $passed_tests_count )
Expand All @@ -86,7 +83,7 @@
<span><?php esc_html_e( 'Changes detected', 'visual-regression-tests' ); ?></span>
<span>
<?php
$changed_detected_count = count( $alerts_post_ids );
$changed_detected_count = count( $data['alerts'] );
printf(
/* translators: %s. Number of tests */
esc_html( _n( '%s Test', '%s Tests', $changed_detected_count, 'visual-regression-tests' ) ), esc_html( $changed_detected_count )
Expand Down
4 changes: 2 additions & 2 deletions includes/features/class-test-runs-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function render_page() {
$service->update_latest_alert_for_all_tests( $run );

$test = $alert ? Test::get_item_by_post_id( $alert->post_id ) : null;
$tests = Test::get_items_by_ids( maybe_unserialize( $run->tests ) );
$test_post_ids = maybe_unserialize( $run->tests );

$is_receipt = 'receipt' === $alert_id;

Expand Down Expand Up @@ -117,7 +117,7 @@ public function render_page() {
'current' => $current_pagination,
'total' => count( $alerts ),
],
'tests' => $tests,
'test_post_ids' => $test_post_ids,
'test_settings' => [
'test_id' => isset( $test->id ) ? $test->id : null,
'hide_css_selectors' => isset( $test->hide_css_selectors ) ? $test->hide_css_selectors : null,
Expand Down
2 changes: 1 addition & 1 deletion includes/models/class-alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static function get_items_by_test_run( $id = 0 ) {
return $wpdb->get_results(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- It's ok.
"SELECT a.* FROM $alerts_table a JOIN $tests_table t ON a.post_id = t.post_id WHERE a.test_run_id = %d ORDER BY t.id DESC",
"SELECT a.* FROM $alerts_table a LEFT JOIN $tests_table t ON a.post_id = t.post_id WHERE a.test_run_id = %d ORDER BY t.id DESC",
$id
)
);
Expand Down
4 changes: 2 additions & 2 deletions includes/services/class-email-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ private function get_test_run_emails( $run ) {
*/
private function get_test_run_email_data( $run_id ) {
$run = Test_Run::get_item( $run_id );
$tests = Test::get_items_by_ids( maybe_unserialize( $run->tests ) );
$test_post_ids = maybe_unserialize( $run->tests );
$alerts = Alert::get_items_by_test_run( $run_id );

$data = [
'run' => $run,
'tests' => $tests,
'test_post_ids' => $test_post_ids,
'alerts' => $alerts,
];

Expand Down

0 comments on commit 943bb9b

Please sign in to comment.