-
Notifications
You must be signed in to change notification settings - Fork 143
Implement customizable transition animation duration setting #2321
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
Open
sarthak-19
wants to merge
16
commits into
WordPress:trunk
Choose a base branch
from
sarthak-19:Feat/custom_animation_duration
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+463
−4
Open
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4970c8d
Implement transition animation duration setting with validation and r…
07de264
Addressed feedback changes and added unit test for better coverage
58eee13
Fixed phpstan errors
e3e18c4
Removed seconds option from view transition duration
384c1ef
Add real-time CSS selector validation to View Transitions settings
1004171
Fix js lint error
f9fba52
Fix issue of failing unit test case
cc845d8
Merge branch 'trunk' into Feat/custom_animation_duration
westonruter 988d662
Skip tests where view transitions are already in the admin (on trunk)
westonruter 0269071
Use CSS.supports for returning valid css selector
6b831ac
fix js linting error
3aab50e
fix linting error
6ace88b
Fix linting issues
7742237
Ignore linting error since wp is already available in global script
fd64beb
Fix JS lint error
defe0f9
Merge branch 'trunk' into Feat/custom_animation_duration
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
| <?php | ||
| /** | ||
| * Tests for the View Transitions plugin includes/admin.php file. | ||
| * | ||
| * @package view-transitions | ||
| * @group view-transitions | ||
| */ | ||
|
|
||
| class Test_ViewTransitions_Admin extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * @covers ::plvt_print_view_transitions_admin_style | ||
| */ | ||
| public function test_plvt_print_view_transitions_admin_style_disabled(): void { | ||
| update_option( 'plvt_view_transitions', array( 'enable_admin_transitions' => false ) ); | ||
|
|
||
| ob_start(); | ||
| plvt_print_view_transitions_admin_style(); | ||
| $output = ob_get_clean(); | ||
|
|
||
| $this->assertEmpty( $output ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_print_view_transitions_admin_style | ||
| */ | ||
| public function test_plvt_print_view_transitions_admin_style_enabled(): void { | ||
| update_option( | ||
| 'plvt_view_transitions', | ||
| array( | ||
| 'enable_admin_transitions' => true, | ||
| 'default_transition_animation_duration' => 500, | ||
| ) | ||
| ); | ||
|
|
||
| ob_start(); | ||
| plvt_print_view_transitions_admin_style(); | ||
| $output = ob_get_clean(); | ||
|
|
||
| $this->assertStringContainsString( '@view-transition { navigation: auto; }', $output ); | ||
| $this->assertStringContainsString( 'animation-duration: 0.5s', $output ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_print_view_transitions_admin_style | ||
| */ | ||
| public function test_plvt_print_view_transitions_admin_style_uses_default_duration(): void { | ||
| update_option( | ||
| 'plvt_view_transitions', | ||
| array( 'enable_admin_transitions' => true ) | ||
| ); | ||
|
|
||
| ob_start(); | ||
| plvt_print_view_transitions_admin_style(); | ||
| $output = ob_get_clean(); | ||
|
|
||
| // Default duration is 400ms = 0.4s. | ||
| $this->assertStringContainsString( 'animation-duration: 0.4s', $output ); | ||
| } | ||
| } |
This file contains hidden or 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,89 @@ | ||
| <?php | ||
| /** | ||
| * Tests for the View Transitions plugin includes/settings.php file. | ||
| * | ||
| * @package view-transitions | ||
| * @group view-transitions | ||
| */ | ||
|
|
||
| class Test_ViewTransitions_Settings extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * @covers ::plvt_sanitize_setting | ||
| */ | ||
| public function test_plvt_sanitize_setting_returns_defaults_for_invalid_input(): void { | ||
| $this->assertSame( plvt_get_setting_default(), plvt_sanitize_setting( null ) ); | ||
| $this->assertSame( plvt_get_setting_default(), plvt_sanitize_setting( 'string' ) ); | ||
| $this->assertSame( plvt_get_setting_default(), plvt_sanitize_setting( 123 ) ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_sanitize_setting | ||
| */ | ||
| public function test_plvt_sanitize_setting_clamps_duration_minimum(): void { | ||
| $input = array( 'default_transition_animation_duration' => 50 ); | ||
| $result = plvt_sanitize_setting( $input ); | ||
| $this->assertSame( PLVT_MIN_ANIMATION_DURATION, $result['default_transition_animation_duration'] ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_sanitize_setting | ||
| */ | ||
| public function test_plvt_sanitize_setting_clamps_duration_maximum(): void { | ||
| $input = array( 'default_transition_animation_duration' => 10000 ); | ||
| $result = plvt_sanitize_setting( $input ); | ||
| $this->assertSame( PLVT_MAX_ANIMATION_DURATION, $result['default_transition_animation_duration'] ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_sanitize_setting | ||
| */ | ||
| public function test_plvt_sanitize_setting_accepts_valid_duration(): void { | ||
| $input = array( 'default_transition_animation_duration' => 500 ); | ||
| $result = plvt_sanitize_setting( $input ); | ||
| $this->assertSame( 500, $result['default_transition_animation_duration'] ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_sanitize_setting | ||
| */ | ||
| public function test_plvt_sanitize_setting_handles_negative_duration(): void { | ||
| $input = array( 'default_transition_animation_duration' => -500 ); | ||
| $result = plvt_sanitize_setting( $input ); | ||
| // absint converts negative to positive, then clamps. | ||
| $this->assertSame( 500, $result['default_transition_animation_duration'] ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_sanitize_setting | ||
| */ | ||
| public function test_plvt_sanitize_setting_handles_string_duration(): void { | ||
| $input = array( 'default_transition_animation_duration' => '750' ); | ||
| $result = plvt_sanitize_setting( $input ); | ||
| $this->assertSame( 750, $result['default_transition_animation_duration'] ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_get_setting_default | ||
| */ | ||
| public function test_plvt_get_setting_default_has_valid_duration(): void { | ||
| $defaults = plvt_get_setting_default(); | ||
| $this->assertArrayHasKey( 'default_transition_animation_duration', $defaults ); | ||
| $this->assertIsInt( $defaults['default_transition_animation_duration'] ); | ||
| $this->assertGreaterThanOrEqual( PLVT_MIN_ANIMATION_DURATION, $defaults['default_transition_animation_duration'] ); | ||
| $this->assertLessThanOrEqual( PLVT_MAX_ANIMATION_DURATION, $defaults['default_transition_animation_duration'] ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers ::plvt_sanitize_setting | ||
| */ | ||
| public function test_plvt_sanitize_setting_validates_animation_type(): void { | ||
| $input = array( 'default_transition_animation' => 'invalid-animation' ); | ||
| $result = plvt_sanitize_setting( $input ); | ||
| $this->assertSame( 'fade', $result['default_transition_animation'] ); | ||
|
|
||
| $input = array( 'default_transition_animation' => 'slide-from-right' ); | ||
| $result = plvt_sanitize_setting( $input ); | ||
| $this->assertSame( 'slide-from-right', $result['default_transition_animation'] ); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.