Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harun/test run #67

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/test-runs-page/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@
}
}
}

.vrts-test-run-view-alerts {
display: inline-flex;
align-items: center;
gap: 4px;
}
}

.vrts-test-runs-list-queue-table {
Expand Down
2 changes: 2 additions & 0 deletions components/test-runs-page/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$list_table->display();
?>

<form id="vrts-filter-alerts-form" action="<?php echo esc_url( admin_url( 'admin.php?page=vrts-alerts' ) ); ?>" method="post"></form>

<form method="post">
<?php
$list_table = $data['list_table'];
Expand Down
6 changes: 2 additions & 4 deletions includes/list-tables/class-alerts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ public function column_title( $item ) {

return sprintf(
'<strong>%1$s</strong> %2$s',
/* translators: %s: the title of the alert. */
sprintf( __( 'Alert %s', 'visual-regression-tests' ), $item->title ),
sprintf( $item->title ),
$this->row_actions( $actions )
);

Expand Down Expand Up @@ -172,8 +171,7 @@ public function column_title( $item ) {
'<strong><a class="row-title" href="%1$s" title="%2$s">%3$s</a></strong> %4$s',
$base_link . '&action=edit&alert_id=' . $item->id,
__( 'Edit', 'visual-regression-tests' ),
/* translators: %s: the title of the alert. */
sprintf( __( 'Alert %s', 'visual-regression-tests' ), $item->title ),
sprintf( $item->title ),
$this->row_actions( $actions )
);
}//end if
Expand Down
3 changes: 1 addition & 2 deletions includes/list-tables/class-test-runs-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ public function column_title( $item ) {

$row_actions = sprintf(
'<strong><span class="row-title">%1$s</span></strong> %2$s %3$s',
// translators: %s: Test run number.
sprintf( __( 'Run #%s', 'visual-regression-tests' ), $item->id ),
sprintf( $item->title ),
$this->row_actions( $actions, true ),
$this->test_run_details( $item )
);
Expand Down
37 changes: 35 additions & 2 deletions includes/models/class-alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Vrts\Tables\Alerts_Table;
use Vrts\Services\Test_Service;
use Vrts\Tables\Test_Runs_Table;

/**
* Model Alert Page.
Expand All @@ -20,6 +21,7 @@ public static function get_items( $args = [] ) {
global $wpdb;

$alerts_table = Alerts_Table::get_table_name();
$test_runs_table = Test_Runs_Table::get_table_name();

$defaults = [
's' => '',
Expand All @@ -46,7 +48,8 @@ public static function get_items( $args = [] ) {

if ( ! empty( $args['s'] ) ) {
$where .= $wpdb->prepare(
' AND title LIKE %s',
' AND ( title LIKE %s OR test_run_title LIKE %s )',
'%' . $wpdb->esc_like( $args['s'] ) . '%',
'%' . $wpdb->esc_like( $args['s'] ) . '%'
);
}
Expand Down Expand Up @@ -82,8 +85,38 @@ public static function get_items( $args = [] ) {
$limit
);

$alert_title = sprintf(
"CONCAT( '%s', alert.id ) as title",
esc_html__( 'Alert #', 'visual-regression-tests' )
);

$run_title = sprintf(
"CONCAT( '%s', run.id ) as test_run_title",
esc_html__( 'Run #', 'visual-regression-tests' )
);

$query = "
SELECT * FROM $alerts_table
SELECT
*
FROM (
SELECT
alert.id,
$alert_title,
alert.post_id,
alert.screenshot_test_id,
alert.target_screenshot_url,
alert.target_screenshot_finish_date,
alert.base_screenshot_url,
alert.base_screenshot_finish_date,
alert.comparison_screenshot_url,
alert.comparison_id,
alert.differences,
alert.alert_state,
alert.test_run_id,
$run_title
FROM $alerts_table as alert
LEFT JOIN $test_runs_table as run ON run.id = alert.test_run_id
) alerts
$where
$orderby
$limits
Expand Down
20 changes: 13 additions & 7 deletions includes/models/class-test-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ public static function get_items( $args = [], $return_count = false ) {
);
}

$run_title = $wpdb->prepare(
"CONCAT( '%s', runs.id ) as title",
esc_html__( 'Run #', 'visual-regression-tests' )
);

$query = "
$select
FROM (
SELECT
runs.id,
$run_title,
runs.tests,
runs.alerts,
runs.trigger,
Expand Down Expand Up @@ -370,15 +376,15 @@ public static function get_status_data( $test_run ) {
$alerts_count = count( maybe_unserialize( $test_run->alerts ) );
$class = 'paused';
$text = esc_html__( 'Changes detected', 'visual-regression-tests' );
$base_link = admin_url( 'admin.php?page=vrts-alerts&test_run_id=' . $test_run->id );
$instructions = Date_Time_Helpers::get_formatted_relative_date_time( $test_run->finished_at );
$instructions .= sprintf(
/* translators: %1$s and %2$s: link wrapper. */
esc_html( _n( '%1$s%2$s View Alert (%4$s)%3$s', '%1$s%2$s View Alerts (%4$s)%3$s', $alerts_count, 'visual-regression-tests' ) ),
'<a href="' . $base_link . '" title="' . esc_attr__( 'View Alert', 'visual-regression-tests' ) . '">',
'<i class="dashicons dashicons-image-flip-horizontal"></i>',
'</a>',
$alerts_count
'<button type="submit" name="s" value="%1$s" form="vrts-filter-alerts-form" class="button-link vrts-test-run-view-alerts"><i class="dashicons dashicons-image-flip-horizontal"></i> %2$s</button>',
esc_attr( $test_run->title ),
sprintf(
// translators: %s: number of alerts.
esc_html( _n( 'View Alert (%s)', 'View Alerts (%s)', $alerts_count, 'visual-regression-tests' ) ),
$alerts_count
)
);
break;
case 'running':
Expand Down
Loading