Fix RIN Display Logic for Banner Alert Notifications (#47167)

* Fix RIN Display Logic for Banner Alert Notifications

* Add tests

* Add changelog

* Update test

* Add test

* chore: fix unactioned note status check in EvaluateAndGetStatus.php
This commit is contained in:
Chi-Hsuan Huang 2024-05-10 09:58:09 +08:00 committed by GitHub
parent 14018bec62
commit 66c57693c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Fix RIN Display Logic for Banner Alert Notifications

View File

@ -114,7 +114,7 @@ class SpecRunner {
$matching_wp_locales = array_values(
array_filter(
$locales,
function( $l ) use ( $wp_locale ) {
function ( $l ) use ( $wp_locale ) {
return $wp_locale === $l->locale;
}
)
@ -128,7 +128,7 @@ class SpecRunner {
$en_us_locales = array_values(
array_filter(
$locales,
function( $l ) {
function ( $l ) {
return $l->locale === 'en_US';
}
)
@ -168,7 +168,7 @@ class SpecRunner {
$en_us_locales = array_values(
array_filter(
$action_locales,
function( $l ) {
function ( $l ) {
return $l->locale === 'en_US';
}
)

View File

@ -46,6 +46,13 @@ class EvaluateAndGetStatus {
: Note::E_WC_ADMIN_NOTE_PENDING;
}
// If the spec is an alert type and the note is unactioned, set to pending if the spec no longer applies.
if ( isset( $spec->type ) && in_array( $spec->type, array( 'error', 'update' ), true )
&& Note::E_WC_ADMIN_NOTE_UNACTIONED === $current_status
&& ! $evaluated_result ) {
return Note::E_WC_ADMIN_NOTE_PENDING;
}
// When allow_redisplay isn't set, just leave the note alone.
if ( ! isset( $spec->allow_redisplay ) || ! $spec->allow_redisplay ) {
return $current_status;

View File

@ -212,4 +212,55 @@ class WC_Admin_Tests_RemoteInboxNotifications_EvaluateAndGetStatus extends WC_Un
$this->assertEquals( 'unactioned', $result );
}
/**
* Tests that for an alert note that is unactioned and eval to true,
* The pending status is returned.
*
* @group fast
*/
public function test_unactioned_alert_note_return_pending_when_eval_to_false() {
$spec = json_decode(
'{
"slug": "test",
"type": "error",
"rules": []
}'
);
$result = EvaluateAndGetStatus::evaluate(
$spec,
'unactioned',
new stdClass(),
new FailingRuleEvaluator()
);
$this->assertEquals( 'pending', $result );
}
/**
* Tests that for an alert note that is unactioned and eval to true,
* The current status is returned.
*
* @group fast
*/
public function test_unactioned_info_note_return_current_status_when_eval_to_false() {
$spec = json_decode(
'{
"slug": "test",
"type": "info",
"rules": []
}'
);
$current_status = 'unactioned';
$result = EvaluateAndGetStatus::evaluate(
$spec,
$current_status,
new stdClass(),
new FailingRuleEvaluator()
);
$this->assertEquals( $current_status, $result );
}
}