-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In Likes and Comment Likes modules, prevent blocking page load… (#14841)
* Prevent blocking page load with 2 scripts in Like module These both depend on jquery, so this could remove even another script from blocking rendering. * Don't enqueue script if the Likes module isn't visible As Dan raised, this should not enqueue this JS if this isn't in the document. * [not verified] Apply a similar change to the Comment Likes module Don't enqueue scripts if likes aren't enabled, and move the dependencies to the footer, as the script that depends on them, 'jetpack_likes_queuehandler', is in the footer. It doesn't seem necessary for these to be above the footer. * Fix a unit test that asserted the opposite It should ensure that the styles are present, not that they aren't.
- Loading branch information
Showing
5 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/php/modules/comment-likes/test-class.comment-likes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Tests for the WP_Test_Comment_Likes class. | ||
* | ||
* @package Jetpack | ||
* @since 8.4.0 | ||
*/ | ||
|
||
require dirname( __FILE__ ) . '/../../../../modules/comment-likes.php'; | ||
|
||
/** | ||
* Test class for Jetpack_Comment_Likes. | ||
* | ||
* @since 8.4.0 | ||
*/ | ||
class WP_Test_Comment_Likes extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test that the assets are not enqueued if likes are not visible. | ||
* | ||
* @since 8.4.0 | ||
*/ | ||
public function test_load_styles_register_scripts_likes_not_visible() { | ||
$instance = Jetpack_Comment_Likes::init(); | ||
$instance->load_styles_register_scripts(); | ||
|
||
$this->assertFalse( wp_style_is( 'jetpack_likes' ) ); | ||
$this->assertFalse( wp_script_is( 'postmessage' ) ); | ||
} | ||
|
||
/** | ||
* Test that the assets are enqueued if likes are visible. | ||
* | ||
* @since 8.4.0 | ||
*/ | ||
public function test_load_styles_register_scripts_likes_visible() { | ||
add_filter( 'wpl_is_likes_visible', '__return_true' ); | ||
$instance = Jetpack_Comment_Likes::init(); | ||
$instance->load_styles_register_scripts(); | ||
|
||
$this->assertTrue( wp_style_is( 'jetpack_likes' ) ); | ||
$this->assertTrue( wp_script_is( 'postmessage' ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters