Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,20 @@ describe( 'PolicyViolationNotification', () => {

expect( isActive ).toBe( false );
} );

it( 'extremeNotification.checkRequirements should return false when the extreme notification is in the dismissed items list', async () => {
setupRegistry( CONTENT_POLICY_ORGANIZATION_VIOLATION_ACTIVE_IMMEDIATE );

registry
.dispatch( CORE_USER )
.receiveGetDismissedItems( [
RRM_POLICY_VIOLATION_EXTREME_NOTIFICATION_ID,
] );

const isActive = await extremeNotification.checkRequirements(
registry
);

expect( isActive ).toBe( false );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ const PolicyViolation: FC< PolicyViolationProps > = ( {

const { dismissItem } = useDispatch( CORE_USER );

const onDismiss = useCallback( () => {
dismissNotice();

// Proactively dismiss the policy violation notification for the next 24 hours.
// Proactively dismiss the policy violation notification for the next 24 hours.
const onView = useCallback( () => {
dismissItem(
isExtremeViolation
? RRM_POLICY_VIOLATION_EXTREME_NOTIFICATION_ID
Expand All @@ -86,7 +84,7 @@ const PolicyViolation: FC< PolicyViolationProps > = ( {
expiresInSeconds: DAY_IN_SECONDS,
}
);
}, [ dismissItem, dismissNotice, isExtremeViolation ] );
}, [ dismissItem, isExtremeViolation ] );

const description =
policyViolationType === 'PENDING_POLICY_VIOLATION'
Expand All @@ -100,7 +98,10 @@ const PolicyViolation: FC< PolicyViolationProps > = ( {
);

return (
<Notification gaTrackingEventArgs={ gaTrackingEventArgs }>
<Notification
gaTrackingEventArgs={ gaTrackingEventArgs }
onView={ onView }
>
{ /* @ts-expect-error - The `NoticeNotification` component is not typed yet. */ }
<NoticeNotification
type={ isExtremeViolation ? TYPES.ERROR : TYPES.WARNING }
Expand All @@ -112,7 +113,7 @@ const PolicyViolation: FC< PolicyViolationProps > = ( {
) }
description={ description }
dismissButton={ {
onClick: onDismiss,
onClick: dismissNotice,
} }
ctaButton={ {
label: isExtremeViolation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ describe( 'RRMSetupSuccessSubtleNotification', () => {
expect( setValueMock ).toHaveBeenCalledWith( undefined );
} );

it( 'should proactively dismiss the respective policy violation notification when dismiss button is clicked', async () => {
it( 'should proactively dismiss the respective policy violation notification when the notification is viewed', async () => {
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.receiveGetSettings( {
Expand Down Expand Up @@ -617,31 +617,29 @@ describe( 'RRMSetupSuccessSubtleNotification', () => {
'dismissItem'
);

const { getByRole } = render(
<NotificationWithComponentProps />,
{
registry,
viewContext: VIEW_CONTEXT_MAIN_DASHBOARD,
}
);

fireEvent.click(
getByRole( 'button', {
name: 'Got it',
} )
);
// Mark the notification as viewed so the Notification component invokes onView on mount.
registry
.dispatch( CORE_UI )
.setValue( `notification/${ id }/viewed`, true );

const expectedNotificationID =
contentPolicyState ===
CONTENT_POLICY_STATES.CONTENT_POLICY_ORGANIZATION_VIOLATION_ACTIVE_IMMEDIATE
? RRM_POLICY_VIOLATION_EXTREME_NOTIFICATION_ID
: RRM_POLICY_VIOLATION_MODERATE_HIGH_NOTIFICATION_ID;
render( <NotificationWithComponentProps />, {
registry,
viewContext: VIEW_CONTEXT_MAIN_DASHBOARD,
} );

expect( dismissItemSpy ).toHaveBeenCalledTimes( 1 );
expect( dismissItemSpy ).toHaveBeenCalledWith(
expectedNotificationID,
{ expiresInSeconds: DAY_IN_SECONDS }
);
await waitFor( () => {
const expectedNotificationID =
contentPolicyState ===
CONTENT_POLICY_STATES.CONTENT_POLICY_ORGANIZATION_VIOLATION_ACTIVE_IMMEDIATE
? RRM_POLICY_VIOLATION_EXTREME_NOTIFICATION_ID
: RRM_POLICY_VIOLATION_MODERATE_HIGH_NOTIFICATION_ID;

expect( dismissItemSpy ).toHaveBeenCalledTimes( 1 );
expect( dismissItemSpy ).toHaveBeenCalledWith(
expectedNotificationID,
{ expiresInSeconds: DAY_IN_SECONDS }
);
} );
} );

it( `should open the policy info URL when the "${ expectedCTALabel }" CTA is clicked`, () => {
Expand Down
14 changes: 14 additions & 0 deletions assets/js/modules/reader-revenue-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ export const NOTIFICATIONS = {
return false;
}

await resolveSelect( CORE_USER ).getDismissedItems();

const isItemDismissed = select( CORE_USER ).isItemDismissed(
RRM_POLICY_VIOLATION_EXTREME_NOTIFICATION_ID
);

// Due to the addition of the `dismissRetries` property, the notification dismissal
// logic uses prompts instead of items to track the dismissal status.
// However, it is possible that the notification is dismissed using dismissed items
// at the setup success notification stage.
if ( isItemDismissed ) {
return false;
}

await resolveSelect(
MODULES_READER_REVENUE_MANAGER
).getSettings();
Expand Down
Loading