Plugin Directory

Changeset 2899063


Ignore:
Timestamp:
04/14/2023 09:19:44 AM (3 years ago)
Author:
bleechberlin
Message:

Tagging version 1.2.4

Location:
visual-regression-tests
Files:
7 edited
41 copied

Legend:

Unmodified
Added
Removed
  • visual-regression-tests/tags/1.2.4/editor/components/metabox/index.js

    r2836726 r2899063  
    2828        window.vrts_editor_vars.placeholder_image_data_url;
    2929
    30     const remainingTests = parseInt( window.vrts_editor_vars.remaining_tests );
    31     const totalTests = parseInt( window.vrts_editor_vars.total_tests );
     30    const [ remainingTests, setRemainingTests ] = useState(
     31        parseInt( window.vrts_editor_vars.remaining_tests )
     32    );
     33    const [ totalTests, setTotalTests ] = useState(
     34        parseInt( window.vrts_editor_vars.total_tests )
     35    );
     36
    3237    const upgradeUrl = window.vrts_editor_vars.upgrade_url;
    3338    const pluginUrl = window.vrts_editor_vars.plugin_url;
     
    4550        } );
    4651
    47         if ( value === true ) {
    48             window.vrts_editor_vars.remaining_tests--;
    49         } else {
    50             window.vrts_editor_vars.remaining_tests++;
    51         }
    52 
    5352        dispatch( 'core/editor' ).editPost( {
    5453            meta: {
     
    5857    };
    5958
     59    const { isSavingPost } = select( 'core/editor' );
     60    const [ showResults, setShowResults ] = useState( runTestsValue );
    6061    const [ isSavingProcess, setSavingProcess ] = useState( false );
    61     const { isSavingPost } = select( 'core/editor' );
     62    const updatePost = async function () {
     63        const postId = select( 'core/editor' ).getCurrentPostId();
     64        const testId = await getTestId( postId );
     65
     66        if ( true === runTestsIsChecked && null === testId ) {
     67            window.vrts_editor_vars.is_new_test = true;
     68            window.vrts_editor_vars.has_post_alert = false;
     69            window.vrts_editor_vars.test_status = true;
     70        } else {
     71            window.vrts_editor_vars.is_new_test = false;
     72        }
     73
     74        setTimeout( () => {
     75            setRemainingAndTotalTestsFromApi();
     76        }, 2000 ); // Set a delay of 2 seconds, to be sure that the data from api is updated.
     77
     78        setShowResults( runTestsIsChecked );
     79    };
     80
    6281    subscribe( () => {
    6382        if ( isSavingPost() ) {
     
    6887    } );
    6988
    70     useEffect( async () => {
     89    useEffect( () => {
    7190        if ( isSavingProcess ) {
    72             const postId = select( 'core/editor' ).getCurrentPostId();
    73             const response = await apiFetch( {
     91            updatePost();
     92        }
     93    }, [ isSavingProcess ] );
     94
     95    const getTestId = async ( postId ) => {
     96        try {
     97            const responseTestId = await apiFetch( {
    7498                path: `/vrts/v1/tests/post/${ postId }`,
    75             } ).catch( ( error ) => {
    76                 console.log( error ); // eslint-disable-line no-console
    7799            } );
    78             const testId = await response.test_id;
    79 
    80             if ( true === runTestsIsChecked && null === testId ) {
    81                 window.vrts_editor_vars.is_new_test = true;
    82             } else {
    83                 window.vrts_editor_vars.is_new_test = false;
    84             }
    85         }
    86     }, [ isSavingProcess ] );
     100            const testId = await responseTestId.test_id;
     101            return testId;
     102        } catch ( error ) {
     103            throw error;
     104        }
     105    };
     106
     107    const setRemainingAndTotalTestsFromApi = async () => {
     108        const responseRemainingTotalTests = await apiFetch( {
     109            path: `/vrts/v1/tests/`,
     110        } ).catch( ( error ) => {
     111            throw error;
     112        } );
     113        const restApiRemainingTests =
     114            await responseRemainingTotalTests.remaining_tests;
     115        const restApiTotalTests = await responseRemainingTotalTests.total_tests;
     116        if ( restApiRemainingTests !== null ) {
     117            setRemainingTests( parseInt( restApiRemainingTests ) );
     118        }
     119        if ( restApiTotalTests !== null ) {
     120            setTotalTests( parseInt( restApiTotalTests ) );
     121        }
     122    };
    87123
    88124    let metaboxNotification = null;
    89125    if ( true === isNewTest ) {
    90126        metaboxNotification = <NotificationNewTestAdded />;
    91     } else if ( remainingTests === 1 ) {
     127    } else if ( parseInt( remainingTests ) === 1 ) {
    92128        metaboxNotification = (
    93129            <NotificationUnlockMoreTests
     
    97133            />
    98134        );
    99     } else if ( remainingTests === 0 ) {
     135    } else if ( parseInt( remainingTests ) === 0 ) {
    100136        metaboxNotification = (
    101137            <NotificationUpgradeRequired upgradeUrl={ upgradeUrl } />
     
    129165                checked={ runTestsIsChecked }
    130166                onChange={ runTestsOnChange }
    131                 disabled={ remainingTests === 0 && runTestsIsChecked === false }
     167                disabled={
     168                    parseInt( remainingTests ) === 0 && ! runTestsIsChecked
     169                }
    132170            />
    133171
    134172            { metaboxNotification }
    135173
    136             { runTestsIsChecked && (
     174            { showResults && (
    137175                <>
    138176                    <div className="testing-status-wrapper">
     
    164202                </>
    165203            ) }
    166             { runTestsIsChecked && (
     204            { showResults && (
    167205                <Screenshot
    168206                    url={ targetScreenshotUrl }
  • visual-regression-tests/tags/1.2.4/includes/features/class-install.php

    r2829855 r2899063  
    1818        register_activation_hook( vrts()->get_plugin_file(), [ $this, 'set_activation_admin_notice_transient' ] );
    1919        add_action( 'admin_notices', [ $this, 'activation_admin_notice' ] );
     20
     21        add_action( 'upgrader_process_complete', [ $this, 'on_upgrade' ], 10, 2 );
     22        add_action( 'vrts_plugin_on_upgrade', [ $this, 'install' ], 10, 2 );
    2023    }
    2124
     
    3134            // Direct DB query and no caching are OK to use in this case.
    3235            // @codingStandardsIgnoreStart.
    33             $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
     36            $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
    3437            // @codingStandardsIgnoreEnd.
    3538
     
    7982        }
    8083    }
     84
     85    /**
     86     * On upgrade.
     87     *
     88     * @param object $upgrader WP_Upgrader instance.
     89     * @param array  $options  Array of bulk item update data.
     90     */
     91    public function on_upgrade( $upgrader, $options ) {
     92        if ( 'update' !== $options['action'] ) {
     93            return;
     94        }
     95
     96        if ( 'core' === $options['type'] ) {
     97            return;
     98        }
     99
     100        if ( 'plugin' === $options['type'] && isset( $options['plugins'] ) ) {
     101            foreach ( $options['plugins'] as $plugin ) {
     102                if ( plugin_basename( vrts()->get_plugin_file() ) === $plugin ) {
     103                    do_action( 'vrts_plugin_on_upgrade' );
     104                }
     105            }
     106        }
     107    }
    81108}
  • visual-regression-tests/tags/1.2.4/includes/rest-api/class-rest-tests-controller.php

    r2836726 r2899063  
    33namespace Vrts\Rest_Api;
    44
     5use Vrts\Features\Subscription;
    56use WP_REST_Request;
    67use WP_Error;
     
    2324     */
    2425    public function register_routes() {
     26        register_rest_route($this->namespace, $this->resource_name, [
     27            'methods' => WP_REST_Server::READABLE,
     28            'callback' => [ $this, 'tests_remaining_total_callback' ],
     29            'permission_callback' => '__return_true',
     30        ]);
     31
    2532        register_rest_route($this->namespace, $this->resource_name . '/post/(?P<post_id>\d+)', [
    2633            'methods' => WP_REST_Server::READABLE,
     
    3138
    3239    /**
    33      * Gets some data.
     40     * Gets some tests data.
    3441     *
    3542     * @param WP_REST_Request $request Current request.
     
    5158        }
    5259    }
     60
     61    /**
     62     * Get remaining and total tests.
     63     */
     64    public function tests_remaining_total_callback() {
     65
     66        return rest_ensure_response([
     67            'remaining_tests' => Subscription::get_remaining_tests(),
     68            'total_tests' => Subscription::get_total_tests(),
     69        ], 200);
     70    }
    5371}
  • visual-regression-tests/tags/1.2.4/readme.txt

    r2855832 r2899063  
    33Tags: vrts, visual regression, visual, regression, tests
    44Requires at least: 5.0
    5 Tested up to: 6.1
    6 Stable tag: 1.2.3
     5Tested up to: 6.2
     6Stable tag: 1.2.4
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    154154== Changelog ==
    155155
     156= 1.2.4 =
     157* Fixed an issue that crashes the Gutenberg editor after upgrading to WordPress 6.2
     158* Improved metabox behaviour inside the Gutenberg editor
     159
    156160= 1.2.3 =
    157161* Fixed tests and alerts search
  • visual-regression-tests/tags/1.2.4/visual-regression-tests.php

    r2855832 r2899063  
    44 * Plugin URI:        https://bleech.de/en/products/visual-regression-tests/
    55 * Description:       Test your website for unwanted visual changes. Run automatic tests and spot differences.
    6  * Version:           1.2.3
     6 * Version:           1.2.4
    77 * Requires at least: 5.0
    88 * Requires PHP:      7.0
  • visual-regression-tests/trunk/editor/components/metabox/index.js

    r2836726 r2899063  
    2828        window.vrts_editor_vars.placeholder_image_data_url;
    2929
    30     const remainingTests = parseInt( window.vrts_editor_vars.remaining_tests );
    31     const totalTests = parseInt( window.vrts_editor_vars.total_tests );
     30    const [ remainingTests, setRemainingTests ] = useState(
     31        parseInt( window.vrts_editor_vars.remaining_tests )
     32    );
     33    const [ totalTests, setTotalTests ] = useState(
     34        parseInt( window.vrts_editor_vars.total_tests )
     35    );
     36
    3237    const upgradeUrl = window.vrts_editor_vars.upgrade_url;
    3338    const pluginUrl = window.vrts_editor_vars.plugin_url;
     
    4550        } );
    4651
    47         if ( value === true ) {
    48             window.vrts_editor_vars.remaining_tests--;
    49         } else {
    50             window.vrts_editor_vars.remaining_tests++;
    51         }
    52 
    5352        dispatch( 'core/editor' ).editPost( {
    5453            meta: {
     
    5857    };
    5958
     59    const { isSavingPost } = select( 'core/editor' );
     60    const [ showResults, setShowResults ] = useState( runTestsValue );
    6061    const [ isSavingProcess, setSavingProcess ] = useState( false );
    61     const { isSavingPost } = select( 'core/editor' );
     62    const updatePost = async function () {
     63        const postId = select( 'core/editor' ).getCurrentPostId();
     64        const testId = await getTestId( postId );
     65
     66        if ( true === runTestsIsChecked && null === testId ) {
     67            window.vrts_editor_vars.is_new_test = true;
     68            window.vrts_editor_vars.has_post_alert = false;
     69            window.vrts_editor_vars.test_status = true;
     70        } else {
     71            window.vrts_editor_vars.is_new_test = false;
     72        }
     73
     74        setTimeout( () => {
     75            setRemainingAndTotalTestsFromApi();
     76        }, 2000 ); // Set a delay of 2 seconds, to be sure that the data from api is updated.
     77
     78        setShowResults( runTestsIsChecked );
     79    };
     80
    6281    subscribe( () => {
    6382        if ( isSavingPost() ) {
     
    6887    } );
    6988
    70     useEffect( async () => {
     89    useEffect( () => {
    7190        if ( isSavingProcess ) {
    72             const postId = select( 'core/editor' ).getCurrentPostId();
    73             const response = await apiFetch( {
     91            updatePost();
     92        }
     93    }, [ isSavingProcess ] );
     94
     95    const getTestId = async ( postId ) => {
     96        try {
     97            const responseTestId = await apiFetch( {
    7498                path: `/vrts/v1/tests/post/${ postId }`,
    75             } ).catch( ( error ) => {
    76                 console.log( error ); // eslint-disable-line no-console
    7799            } );
    78             const testId = await response.test_id;
    79 
    80             if ( true === runTestsIsChecked && null === testId ) {
    81                 window.vrts_editor_vars.is_new_test = true;
    82             } else {
    83                 window.vrts_editor_vars.is_new_test = false;
    84             }
    85         }
    86     }, [ isSavingProcess ] );
     100            const testId = await responseTestId.test_id;
     101            return testId;
     102        } catch ( error ) {
     103            throw error;
     104        }
     105    };
     106
     107    const setRemainingAndTotalTestsFromApi = async () => {
     108        const responseRemainingTotalTests = await apiFetch( {
     109            path: `/vrts/v1/tests/`,
     110        } ).catch( ( error ) => {
     111            throw error;
     112        } );
     113        const restApiRemainingTests =
     114            await responseRemainingTotalTests.remaining_tests;
     115        const restApiTotalTests = await responseRemainingTotalTests.total_tests;
     116        if ( restApiRemainingTests !== null ) {
     117            setRemainingTests( parseInt( restApiRemainingTests ) );
     118        }
     119        if ( restApiTotalTests !== null ) {
     120            setTotalTests( parseInt( restApiTotalTests ) );
     121        }
     122    };
    87123
    88124    let metaboxNotification = null;
    89125    if ( true === isNewTest ) {
    90126        metaboxNotification = <NotificationNewTestAdded />;
    91     } else if ( remainingTests === 1 ) {
     127    } else if ( parseInt( remainingTests ) === 1 ) {
    92128        metaboxNotification = (
    93129            <NotificationUnlockMoreTests
     
    97133            />
    98134        );
    99     } else if ( remainingTests === 0 ) {
     135    } else if ( parseInt( remainingTests ) === 0 ) {
    100136        metaboxNotification = (
    101137            <NotificationUpgradeRequired upgradeUrl={ upgradeUrl } />
     
    129165                checked={ runTestsIsChecked }
    130166                onChange={ runTestsOnChange }
    131                 disabled={ remainingTests === 0 && runTestsIsChecked === false }
     167                disabled={
     168                    parseInt( remainingTests ) === 0 && ! runTestsIsChecked
     169                }
    132170            />
    133171
    134172            { metaboxNotification }
    135173
    136             { runTestsIsChecked && (
     174            { showResults && (
    137175                <>
    138176                    <div className="testing-status-wrapper">
     
    164202                </>
    165203            ) }
    166             { runTestsIsChecked && (
     204            { showResults && (
    167205                <Screenshot
    168206                    url={ targetScreenshotUrl }
  • visual-regression-tests/trunk/includes/features/class-install.php

    r2829855 r2899063  
    1818        register_activation_hook( vrts()->get_plugin_file(), [ $this, 'set_activation_admin_notice_transient' ] );
    1919        add_action( 'admin_notices', [ $this, 'activation_admin_notice' ] );
     20
     21        add_action( 'upgrader_process_complete', [ $this, 'on_upgrade' ], 10, 2 );
     22        add_action( 'vrts_plugin_on_upgrade', [ $this, 'install' ], 10, 2 );
    2023    }
    2124
     
    3134            // Direct DB query and no caching are OK to use in this case.
    3235            // @codingStandardsIgnoreStart.
    33             $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
     36            $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
    3437            // @codingStandardsIgnoreEnd.
    3538
     
    7982        }
    8083    }
     84
     85    /**
     86     * On upgrade.
     87     *
     88     * @param object $upgrader WP_Upgrader instance.
     89     * @param array  $options  Array of bulk item update data.
     90     */
     91    public function on_upgrade( $upgrader, $options ) {
     92        if ( 'update' !== $options['action'] ) {
     93            return;
     94        }
     95
     96        if ( 'core' === $options['type'] ) {
     97            return;
     98        }
     99
     100        if ( 'plugin' === $options['type'] && isset( $options['plugins'] ) ) {
     101            foreach ( $options['plugins'] as $plugin ) {
     102                if ( plugin_basename( vrts()->get_plugin_file() ) === $plugin ) {
     103                    do_action( 'vrts_plugin_on_upgrade' );
     104                }
     105            }
     106        }
     107    }
    81108}
  • visual-regression-tests/trunk/includes/rest-api/class-rest-tests-controller.php

    r2836726 r2899063  
    33namespace Vrts\Rest_Api;
    44
     5use Vrts\Features\Subscription;
    56use WP_REST_Request;
    67use WP_Error;
     
    2324     */
    2425    public function register_routes() {
     26        register_rest_route($this->namespace, $this->resource_name, [
     27            'methods' => WP_REST_Server::READABLE,
     28            'callback' => [ $this, 'tests_remaining_total_callback' ],
     29            'permission_callback' => '__return_true',
     30        ]);
     31
    2532        register_rest_route($this->namespace, $this->resource_name . '/post/(?P<post_id>\d+)', [
    2633            'methods' => WP_REST_Server::READABLE,
     
    3138
    3239    /**
    33      * Gets some data.
     40     * Gets some tests data.
    3441     *
    3542     * @param WP_REST_Request $request Current request.
     
    5158        }
    5259    }
     60
     61    /**
     62     * Get remaining and total tests.
     63     */
     64    public function tests_remaining_total_callback() {
     65
     66        return rest_ensure_response([
     67            'remaining_tests' => Subscription::get_remaining_tests(),
     68            'total_tests' => Subscription::get_total_tests(),
     69        ], 200);
     70    }
    5371}
  • visual-regression-tests/trunk/readme.txt

    r2855832 r2899063  
    33Tags: vrts, visual regression, visual, regression, tests
    44Requires at least: 5.0
    5 Tested up to: 6.1
    6 Stable tag: 1.2.3
     5Tested up to: 6.2
     6Stable tag: 1.2.4
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    154154== Changelog ==
    155155
     156= 1.2.4 =
     157* Fixed an issue that crashes the Gutenberg editor after upgrading to WordPress 6.2
     158* Improved metabox behaviour inside the Gutenberg editor
     159
    156160= 1.2.3 =
    157161* Fixed tests and alerts search
  • visual-regression-tests/trunk/visual-regression-tests.php

    r2855832 r2899063  
    44 * Plugin URI:        https://bleech.de/en/products/visual-regression-tests/
    55 * Description:       Test your website for unwanted visual changes. Run automatic tests and spot differences.
    6  * Version:           1.2.3
     6 * Version:           1.2.4
    77 * Requires at least: 5.0
    88 * Requires PHP:      7.0
Note: See TracChangeset for help on using the changeset viewer.