Skip to content

Commit 2d4d2ab

Browse files
committed
Merge remote-tracking branch 'origin/main' into TestRuns
2 parents 454e729 + e22dcb1 commit 2d4d2ab

28 files changed

+349
-270
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push]
44

55
jobs:
66
lint:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-24.04
88
steps:
99
- uses: actions/checkout@v3
1010
- name: Use Node.js v20
@@ -28,7 +28,7 @@ jobs:
2828
npm i
2929
- name: Install composer
3030
run: |
31-
php7.4 $(which composer) install
31+
php8.3 $(which composer) install
3232
- name: Run lint
3333
run: |
3434
npm run lint

.wordpress-org/banner-1544x500.png

724 Bytes
Loading

.wordpress-org/banner-772x250.png

-425 Bytes
Loading

assets/scripts/onboarding.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ if ( window.vrts_admin_vars.onboarding ) {
6868
onCloseClick: () => {
6969
onboarding.destroy();
7070
},
71+
onDestroyed: () => {
72+
window.removeEventListener( 'keyup', onKeyup );
73+
},
7174
steps: window.vrts_admin_vars.onboarding.steps.map( ( step ) => {
7275
return {
7376
element: step.element,
@@ -81,6 +84,14 @@ if ( window.vrts_admin_vars.onboarding ) {
8184
} ),
8285
} );
8386

87+
const onKeyup = ( event ) => {
88+
if ( event.key === 'Escape' ) {
89+
onboarding.destroy();
90+
}
91+
};
92+
93+
window.addEventListener( 'keyup', onKeyup );
94+
8495
onboarding.drive();
8596
saveOnboarding();
8697
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Vrts\Features;
4+
5+
use Vrts\Models\Test_Run;
6+
7+
class Deactivate {
8+
9+
/**
10+
* Constructor.
11+
*/
12+
public function __construct() {
13+
register_deactivation_hook( vrts()->get_plugin_file(), [ $this, 'deactivate' ] );
14+
}
15+
16+
/**
17+
* Deactivate plugin.
18+
*/
19+
public function deactivate() {
20+
Test_Run::delete_all_not_finished();
21+
Service::disconnect_service();
22+
}
23+
}

includes/features/class-enqueue-scripts.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ public function enqueue_block_editor_assets() {
100100
wp_enqueue_script( 'vrts-editor' );
101101

102102
// Localize scripts.
103-
$test = (object) Test::get_item_by_post_id( $post->ID );
103+
$test_id = Test::get_item_id( $post->ID );
104+
$test = (object) Test::get_item( $test_id );
104105

105106
wp_localize_script(
106107
'vrts-editor',
107108
'vrts_editor_vars',
108109
[
109110
'plugin_name' => vrts()->get_plugin_info( 'name' ),
110111
'rest_url' => esc_url_raw( rest_url() ),
111-
'has_post_alert' => Test::has_post_alert( $post->ID ),
112+
'has_post_alert' => isset( $test->current_alert_id ) ? ! is_null( $test->current_alert_id ) : false,
112113
'base_screenshot_url' => Image_Helpers::get_screenshot_url( $test, 'base' ),
113114
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ?? null ),
114115
'remaining_tests' => Subscription::get_remaining_tests(),

includes/features/class-metaboxes.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,15 @@ public function add_rest_actions() {
109109
*/
110110
public function render_metabox() {
111111
global $post;
112+
112113
$post_id = $post->ID ? $post->ID : 0;
113-
$run_tests_checked = ! empty( Test::get_item_id( $post_id ) );
114+
$test_id = Test::get_item_id( $post_id );
115+
$test = (object) Test::get_item( $test_id );
114116

115-
$alert_id = Test::get_alert_id( $post_id );
117+
$run_tests_checked = ! is_null( $test_id );
118+
$alert_id = $test->current_alert_id ?? null;
116119
$testing_status_instructions = '';
120+
117121
if ( $alert_id ) {
118122
$alert_link = Url_Helpers::get_alert_page( $alert_id );
119123
$testing_status_instructions .= sprintf(
@@ -124,18 +128,15 @@ public function render_metabox() {
124128
);
125129
}
126130

127-
$test_id = Test::get_item_id( $post_id );
128-
$test = (object) Test::get_item( $test_id );
129-
130131
vrts()->component('metabox-classic-editor', [
131132
'post_id' => $post_id,
132133
'nonce' => $this->nonce,
133134
'plugin_url' => Url_Helpers::get_page_url( 'tests' ),
134135
'run_tests_checked' => $run_tests_checked,
135136
'field_test_status_key' => self::$field_test_status_key,
136-
'has_post_alert' => Test::has_post_alert( $post_id ),
137+
'has_post_alert' => isset( $test->current_alert_id ) ? ! is_null( $test->current_alert_id ) : false,
137138
'base_screenshot_url' => Image_Helpers::get_screenshot_url( $test, 'base' ),
138-
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ),
139+
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( $test->base_screenshot_date ?? null ),
139140
'testing_status_instructions' => $testing_status_instructions,
140141
'is_new_test' => self::is_new_test( $post_id ),
141142
'remaining_tests' => Subscription::get_remaining_tests(),

includes/features/class-service.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function retry_connection() {
4848
* @return bool
4949
*/
5050
private static function create_site() {
51-
if ( ! empty( get_option( 'vrts_project_id' ) ) || ! empty( get_option( 'vrts_project_token' ) ) ) {
51+
if ( static::is_connected() ) {
5252
return;
5353
}
5454
$time = current_time( 'mysql' );
@@ -63,9 +63,17 @@ private static function create_site() {
6363
'requested_at' => $time,
6464
];
6565

66+
if ( ! empty( get_option( 'vrts_project_id' ) ) && ! empty( get_option( 'vrts_project_token' ) ) ) {
67+
$parameters['project_id'] = get_option( 'vrts_project_id' );
68+
$parameters['project_token'] = get_option( 'vrts_project_token' );
69+
$parameters['project_secret'] = get_option( 'vrts_project_secret' );
70+
$parameters['tests'] = Test::get_all_service_test_ids();
71+
}
72+
6673
$service_request = self::rest_service_request( $service_api_route, $parameters, 'post' );
6774

68-
if ( 201 === $service_request['status_code'] ) {
75+
delete_option( 'vrts_disconnected' );
76+
if ( 201 === $service_request['status_code'] || 200 === $service_request['status_code'] ) {
6977
$data = $service_request['response'];
7078

7179
update_option( 'vrts_project_id', $data['id'] );
@@ -77,6 +85,8 @@ private static function create_site() {
7785
self::add_homepage_test();
7886

7987
return true;
88+
} else {
89+
update_option( 'vrts_disconnected', 1 );
8090
}
8191
return false;
8292
}
@@ -204,6 +214,15 @@ public static function update_test( $service_test_id, $data ) {
204214
return 200 === $response['status_code'];
205215
}
206216

217+
/**
218+
* Send request to server to resume tests.
219+
*/
220+
public static function resume_tests() {
221+
$service_project_id = get_option( 'vrts_project_id' );
222+
$service_api_route = 'sites/' . $service_project_id;
223+
self::rest_service_request( $service_api_route . '/resume', [], 'post' );
224+
}
225+
207226
/**
208227
* Add homepage as a default test.
209228
*/
@@ -296,13 +315,28 @@ public static function fetch_updates() {
296315
return self::rest_service_request( $service_api_route, [], 'get' );
297316
}
298317

318+
/**
319+
* Get test runs from the service.
320+
*
321+
* @param string[] $test_run_ids the test run ids.
322+
*/
323+
public static function fetch_test_runs( $test_run_ids ) {
324+
$service_project_id = get_option( 'vrts_project_id' );
325+
$service_api_route = 'sites/' . $service_project_id . '/runs';
326+
$service_api_route = add_query_arg( 'ids', implode( ',', $test_run_ids ), $service_api_route );
327+
return self::rest_service_request( $service_api_route, [], 'get' );
328+
}
329+
299330
/**
300331
* Delete project from the service.
301332
*/
302333
public static function disconnect_service() {
303334
$service_project_id = get_option( 'vrts_project_id' );
304335
$service_api_route = 'sites/' . $service_project_id;
305-
self::rest_service_request( $service_api_route, [], 'delete' );
336+
$response = self::rest_service_request( $service_api_route, [], 'delete' );
337+
if ( 200 === $response['status_code'] ) {
338+
update_option( 'vrts_disconnected', 1 );
339+
}
306340
}
307341

308342
/**
@@ -324,7 +358,7 @@ public static function delete_option() {
324358
* Check if external service was able to connect
325359
*/
326360
public static function is_connected() {
327-
return (bool) get_option( 'vrts_project_id' ) && (bool) get_option( 'vrts_project_token' );
361+
return ! (bool) get_option( 'vrts_disconnected' ) && (bool) get_option( 'vrts_project_id' ) && (bool) get_option( 'vrts_project_token' );
328362
}
329363

330364
/**

includes/features/class-settings-page.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Vrts\Core\Utilities\Sanitization;
66
use Vrts\Core\Utilities\Url_Helpers;
77
use Vrts\Features\Subscription;
8+
use Vrts\Services\Test_Service;
89

910
class Settings_Page {
1011
/**
@@ -18,6 +19,7 @@ class Settings_Page {
1819
* Constructor.
1920
*/
2021
public function __construct() {
22+
add_action( 'init', [ $this, 'add_settings' ] );
2123
add_action( 'admin_menu', [ $this, 'add_submenu_page' ] );
2224
add_action( 'admin_init', [ $this, 'settings_migration' ] );
2325
add_action( 'add_option_vrts_click_selectors', [ $this, 'do_after_update_click_selectors' ], 10, 2 );
@@ -26,8 +28,6 @@ public function __construct() {
2628
add_action( 'pre_update_option_vrts_email_update_notification_address', [ $this, 'do_before_updating_email_address' ], 10 );
2729
add_action( 'pre_update_option_vrts_email_api_notification_address', [ $this, 'do_before_updating_email_address' ], 10 );
2830
add_action( 'update_option_vrts_automatic_comparison', [ $this, 'do_after_update_vrts_automatic_comparison' ], 10, 2 );
29-
30-
$this->add_settings();
3131
}
3232

3333
/**
@@ -297,11 +297,14 @@ public function do_after_update_click_selectors( $old, $new ) {
297297

298298
$parameters = [
299299
'screenshot_options' => [
300-
'clickSelectors' => $new,
300+
'clickSelectors' => $new,
301301
],
302302
];
303303

304304
$response = Service::rest_service_request( $service_api_route, $parameters, 'put' );
305+
306+
$service = new Test_Service();
307+
$service->resume_tests();
305308
}
306309
}
307310

includes/features/class-test-runs-page.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ public function render_page() {
9393
$run = Test_Run::get_item( $run_id );
9494

9595
if ( $run ) {
96-
$service = new Test_Run_Service();
97-
$service->update_latest_alert_for_all_tests( $run );
98-
9996
$tests = $this->prepare_tests( maybe_unserialize( $run->tests ) );
10097
$alerts = $this->prepare_alerts( $run_id, $tests );
10198

0 commit comments

Comments
 (0)