Skip to content

Commit

Permalink
feat(TestRuns): implement more overview feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Sep 13, 2024
1 parent 575a6e4 commit e3af3f6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 52 deletions.
11 changes: 7 additions & 4 deletions assets/admin.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@import "@wordpress/base-styles/colors.native"; // stylelint-disable-line scss/at-import-partial-extension

.vrts-list-table-page {
tbody {
background-color: #F6F7FB;
}
th, td {
border-bottom: 1px solid #CCCCCC;
border-bottom: 1px solid #ddd;
}

.vrts-testing-status {
Expand Down Expand Up @@ -35,14 +38,14 @@
}

.vrts-test-runs-list-table:not(.vrts-test-runs-list-queue-table) {
.test-run-row:not([data-has-alerts]) {
background-color: #F6F7F7;
.test-run-row[data-has-alerts] {
background-color: #FFF;
}
td {
cursor: pointer;

> * {
cursor: default;
cursor: initial;
}

> div, strong {
Expand Down
23 changes: 9 additions & 14 deletions includes/list-tables/class-test-runs-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function column_trigger( $item ) {
'<span class="vrts-test-run-trigger vrts-test-run-trigger--%s">%s</span>%s',
esc_attr( $item->trigger ),
esc_html( $trigger_title ),
empty( $trigger_note ) ? '' : sprintf('<p class="vrts-test-run-trigger-notes">%s</p>',
empty( $trigger_note ) ? '' : sprintf('<p class="vrts-test-run-trigger-notes" title="%1$s">%1$s</p>',
$trigger_note
)
);
Expand All @@ -351,22 +351,17 @@ public function column_status( $item ) {
$tests_count = count(maybe_unserialize($item->tests) ?? []);
if ( $alerts_count > 0 ) {
$status_class = 'paused';
$status_text = esc_html__( 'Changes detected', 'visual-regression-tests' );
$status_instructions = sprintf(
// translators: %s: number of alerts, %s: number of tests.
esc_html( _n( '%s of %s Test Failed', '%s of %s Tests Failed', $tests_count, 'visual-regression-tests' ) ),
$alerts_count,
$tests_count
);
$status_text = esc_html__( 'Changes detected ', 'visual-regression-tests' ) . sprintf( '(%s)', $alerts_count );

} else {
$status_class = 'running';
$status_text = esc_html__( 'Passed', 'visual-regression-tests' );
$status_instructions = sprintf(
// translators: %s: number of tests.
esc_html( _n( '%s Test Successfull', '%s Tests Successfull', $tests_count, 'visual-regression-tests' ) ),
$tests_count
);
$status_text = esc_html__( 'No changes', 'visual-regression-tests' );
}
$status_instructions = sprintf(
// translators: %s: number of alerts, %s: number of tests.
esc_html( _n( '%s Test', '%s Tests', $tests_count, 'visual-regression-tests' ) ),
$tests_count
);

return sprintf(
'<div class="vrts-testing-status-wrapper"><p class="vrts-testing-status"><span class="%s">%s</span></p><p class="vrts-testing-status">%s</p></div>',
Expand Down
2 changes: 1 addition & 1 deletion includes/list-tables/class-test-runs-queue-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function column_trigger( $item ) {
$trigger_note = Test_Run::get_trigger_note( $item );

return sprintf(
'<span class="vrts-test-run-trigger vrts-test-run-trigger--%s">%s</span><p class="vrts-test-run-trigger-notes">%s</p>',
'<span class="vrts-test-run-trigger vrts-test-run-trigger--%s">%s</span><p class="vrts-test-run-trigger-notes" title="%3$s">%3$s</p>',
esc_attr( $item->trigger ),
esc_html( $trigger_title ),
$trigger_note
Expand Down
2 changes: 1 addition & 1 deletion includes/list-tables/class-tests-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct() {
* Get table classes.
*/
public function get_table_classes() {
return [ 'widefat', 'fixed', 'striped', $this->_args['plural'] ];
return [ 'widefat', 'fixed', $this->_args['plural'] ];
}

/**
Expand Down
43 changes: 11 additions & 32 deletions includes/models/class-test-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static function get_trigger_title( $test_run ) {
'manual' => __( 'Manual', 'visual-regression-tests' ),
'scheduled' => __( 'Scheduled', 'visual-regression-tests' ),
'api' => __( 'API', 'visual-regression-tests' ),
'update' => __( 'WordPress Updates', 'visual-regression-tests' ),
'update' => __( 'WordPress', 'visual-regression-tests' ),
];

return $trigger_titles[ $test_run->trigger ] ?? __( 'Unknown', 'visual-regression-tests' );
Expand Down Expand Up @@ -512,41 +512,20 @@ public static function delete_by_service_test_run_id( $test_run_id ) {
}

public static function get_trigger_note( $test_run ) {
if ( $test_run->trigger ?? null === 'update' ) {
if ( ( $test_run->trigger ?? null ) === 'update' ) {
$updates = maybe_unserialize( $test_run->trigger_meta ) ?? [];
$updates = array_merge(...$updates);
// print_r($updates);
$types = ['core', 'plugin', 'theme', 'translation'];
$trigger_notes = '';
foreach ($types as $type) {
$updates_by_type = array_filter($updates, function($update) use ($type) {
// var_dump($update);
return $update['type'] === $type;
});
if (empty($updates_by_type)) {
continue;
}
$trigger_notes .= sprintf( '<strong>%s:</strong> ', ucfirst( $type ) );
$trigger_notes .= implode(', ', array_map(function($update) use ($type) {

$trigger_notes = implode(', ', array_map(function ($update) {
if ( $update['type'] === 'core' ) {
$updateName = 'WordPress';
} else {
$updateName = $update['name'] ?? $update['slug'] ?? null;
if ($type === 'translation') {
return '\'' . $updateName . ' (' . $update['language'] . ')' . '\'';
} elseif ($type === 'core') {
return $update['version'] ?? $update['language'] ?? '-';
} else {
if ( $update['version'] ?? false ) {
return $updateName . ' (' . $update['version'] . ')';
} elseif ( $update['language'] ?? false ) {
return $updateName . ' (' . $update['language'] . ')';
} else {
return $updateName ?? '';
}
}
}, $updates_by_type));
if ( ! empty( $trigger_notes ) ) {
$trigger_notes .= '. ';
}
}
$updateInfo = $update['version'] ?? $update['language'] ?? null;

return $updateName . ( empty( $updateInfo ) ? '' : ' (' . $updateInfo . ')' );
}, $updates));
return $trigger_notes;
} else {
return $test_run->trigger_notes ?? '';
Expand Down

0 comments on commit e3af3f6

Please sign in to comment.