@@ -42,8 +42,10 @@ import {
4242 NOTIFICATION_GROUPS ,
4343} from '@/js/googlesitekit/notifications/constants' ;
4444import {
45+ ACTIVE_POLICY_VIOLATION_STATES ,
4546 CONTENT_POLICY_STATES ,
4647 MODULES_READER_REVENUE_MANAGER ,
48+ PENDING_POLICY_VIOLATION_STATES ,
4749 PUBLICATION_ONBOARDING_STATES ,
4850} from '@/js/modules/reader-revenue-manager/datastore/constants' ;
4951import { MODULE_SLUG_READER_REVENUE_MANAGER } from '@/js/modules/reader-revenue-manager/constants' ;
@@ -664,135 +666,174 @@ describe( 'RRMSetupSuccessSubtleNotification', () => {
664666 . setValue ( `notification/${ id } /viewed` , true ) ;
665667 } ) ;
666668
667- it ( 'should track the events when the notification is dismissed' , async ( ) => {
668- registry
669- . dispatch ( MODULES_READER_REVENUE_MANAGER )
670- . receiveGetSettings ( {
671- publicationOnboardingState : ONBOARDING_COMPLETE ,
672- paymentOption : 'subscriptions' ,
673- productID : 'basic' ,
674- } ) ;
675-
676- const { getByRole, waitForRegistry } = render (
677- < NotificationWithComponentProps /> ,
678- {
679- registry,
680- viewContext : VIEW_CONTEXT_MAIN_DASHBOARD ,
681- }
682- ) ;
683-
684- await waitForRegistry ( ) ;
669+ describe . each ( [
670+ undefined ,
671+ ...Object . values ( CONTENT_POLICY_STATES ) ,
672+ ] ) ( 'with contentPolicyState %s' , ( contentPolicyState ) => {
673+ const contentPolicyStatus = contentPolicyState
674+ ? {
675+ contentPolicyState,
676+ policyInfoLink : 'https://example.com/policy' ,
677+ }
678+ : undefined ;
679+
680+ const expectedLabelSuffix = contentPolicyState
681+ ? `:${ contentPolicyState } `
682+ : '' ;
683+
684+ const hasPolicyViolation =
685+ contentPolicyState &&
686+ ( PENDING_POLICY_VIOLATION_STATES . includes (
687+ contentPolicyState
688+ ) ||
689+ ACTIVE_POLICY_VIOLATION_STATES . includes (
690+ contentPolicyState
691+ ) ) ;
692+
693+ it ( 'should track the events when the notification is dismissed' , async ( ) => {
694+ registry
695+ . dispatch ( MODULES_READER_REVENUE_MANAGER )
696+ . receiveGetSettings ( {
697+ publicationOnboardingState : ONBOARDING_COMPLETE ,
698+ paymentOption : 'subscriptions' ,
699+ productID : 'basic' ,
700+ contentPolicyStatus,
701+ } ) ;
685702
686- expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
687- 1 ,
688- 'mainDashboard_setup-success-notification-rrm' ,
689- 'view_notification' ,
690- 'ONBOARDING_COMPLETE:subscriptions:yes' ,
691- undefined
692- ) ;
703+ const { getByRole , waitForRegistry } = render (
704+ < NotificationWithComponentProps /> ,
705+ {
706+ registry ,
707+ viewContext : VIEW_CONTEXT_MAIN_DASHBOARD ,
708+ }
709+ ) ;
693710
694- // eslint-disable-next-line require-await
695- await act ( async ( ) => {
696- fireEvent . click ( getByRole ( 'button' , { name : / G o t i t / i } ) ) ;
697- } ) ;
711+ await waitForRegistry ( ) ;
698712
699- expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
700- 2 ,
701- 'mainDashboard_setup-success-notification-rrm' ,
702- 'dismiss_notification ',
703- 'ONBOARDING_COMPLETE:subscriptions:yes' ,
704- undefined
705- ) ;
706- } ) ;
713+ expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
714+ 1 ,
715+ 'mainDashboard_setup-success-notification-rrm' ,
716+ 'view_notification ',
717+ 'ONBOARDING_COMPLETE:subscriptions:yes' +
718+ expectedLabelSuffix ,
719+ undefined
720+ ) ;
707721
708- it ( 'should track the event when the "Learn more" link is clicked' , async ( ) => {
709- registry
710- . dispatch ( MODULES_READER_REVENUE_MANAGER )
711- . receiveGetSettings ( {
712- publicationOnboardingState : ONBOARDING_COMPLETE ,
713- paymentOption : 'noPayment' ,
714- productID : 'advanced' ,
722+ // eslint-disable-next-line require-await
723+ await act ( async ( ) => {
724+ fireEvent . click (
725+ getByRole ( 'button' , { name : / G o t i t / i } )
726+ ) ;
715727 } ) ;
716728
717- const { getByText, waitForRegistry } = render (
718- < NotificationWithComponentProps /> ,
719- {
720- registry,
721- viewContext : VIEW_CONTEXT_MAIN_DASHBOARD ,
722- }
723- ) ;
729+ expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
730+ 2 ,
731+ 'mainDashboard_setup-success-notification-rrm' ,
732+ 'dismiss_notification' ,
733+ 'ONBOARDING_COMPLETE:subscriptions:yes' +
734+ expectedLabelSuffix ,
735+ undefined
736+ ) ;
737+ } ) ;
724738
725- await waitForRegistry ( ) ;
739+ it ( 'should track the event when the CTA button is clicked' , async ( ) => {
740+ registry
741+ . dispatch ( MODULES_READER_REVENUE_MANAGER )
742+ . receiveGetSettings ( {
743+ publicationOnboardingState : ONBOARDING_COMPLETE ,
744+ paymentOption : 'noPayment' ,
745+ productID : 'basic' ,
746+ contentPolicyStatus,
747+ } ) ;
726748
727- expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
728- 1 ,
729- 'mainDashboard_setup-success-notification-rrm' ,
730- 'view_notification' ,
731- 'ONBOARDING_COMPLETE:noPayment:yes' ,
732- undefined
733- ) ;
749+ const { getByText , waitForRegistry } = render (
750+ < NotificationWithComponentProps /> ,
751+ {
752+ registry ,
753+ viewContext : VIEW_CONTEXT_MAIN_DASHBOARD ,
754+ }
755+ ) ;
734756
735- // "Learn more" link should be present.
736- const learnMoreLink = getByText ( 'Learn more' ) ;
737- expect ( learnMoreLink ) . toBeInTheDocument ( ) ;
757+ await waitForRegistry ( ) ;
738758
739- // eslint-disable-next-line require-await
740- await act ( async ( ) => {
741- fireEvent . click ( learnMoreLink ) ;
742- } ) ;
759+ expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
760+ 1 ,
761+ 'mainDashboard_setup-success-notification-rrm' ,
762+ 'view_notification' ,
763+ 'ONBOARDING_COMPLETE:noPayment:yes' + expectedLabelSuffix ,
764+ undefined
765+ ) ;
743766
744- expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
745- 2 ,
746- 'mainDashboard_setup-success-notification-rrm' ,
747- 'click_learn_more_link' ,
748- 'ONBOARDING_COMPLETE:noPayment:yes' ,
749- undefined
750- ) ;
751- } ) ;
767+ // CTA button should be present.
768+ const ctaButton = hasPolicyViolation
769+ ? getByText ( 'View violations' )
770+ : getByText ( 'Get started' ) ;
752771
753- it ( 'should track the event when the CTA button is clicked' , async ( ) => {
754- registry
755- . dispatch ( MODULES_READER_REVENUE_MANAGER )
756- . receiveGetSettings ( {
757- publicationOnboardingState : ONBOARDING_COMPLETE ,
758- paymentOption : 'noPayment' ,
759- productID : 'basic' ,
772+ expect ( ctaButton ) . toBeInTheDocument ( ) ;
773+
774+ // eslint-disable-next-line require-await
775+ await act ( async ( ) => {
776+ fireEvent . click ( ctaButton ) ;
760777 } ) ;
761778
762- const { getByText, waitForRegistry } = render (
763- < NotificationWithComponentProps /> ,
764- {
765- registry,
766- viewContext : VIEW_CONTEXT_MAIN_DASHBOARD ,
767- }
768- ) ;
779+ expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
780+ 2 ,
781+ 'mainDashboard_setup-success-notification-rrm' ,
782+ 'confirm_notification' ,
783+ 'ONBOARDING_COMPLETE:noPayment:yes' + expectedLabelSuffix ,
784+ undefined
785+ ) ;
786+ } ) ;
769787
770- await waitForRegistry ( ) ;
788+ if ( ! hasPolicyViolation ) {
789+ it ( 'should track the event when the "Learn more" link is clicked' , async ( ) => {
790+ registry
791+ . dispatch ( MODULES_READER_REVENUE_MANAGER )
792+ . receiveGetSettings ( {
793+ publicationOnboardingState : ONBOARDING_COMPLETE ,
794+ paymentOption : 'noPayment' ,
795+ productID : 'advanced' ,
796+ contentPolicyStatus,
797+ } ) ;
798+
799+ const { getByText, waitForRegistry } = render (
800+ < NotificationWithComponentProps /> ,
801+ {
802+ registry,
803+ viewContext : VIEW_CONTEXT_MAIN_DASHBOARD ,
804+ }
805+ ) ;
771806
772- expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
773- 1 ,
774- 'mainDashboard_setup-success-notification-rrm' ,
775- 'view_notification' ,
776- 'ONBOARDING_COMPLETE:noPayment:yes' ,
777- undefined
778- ) ;
807+ await waitForRegistry ( ) ;
779808
780- // CTA button should be present.
781- const ctaButton = getByText ( 'Get started' ) ;
782- expect ( ctaButton ) . toBeInTheDocument ( ) ;
809+ expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
810+ 1 ,
811+ 'mainDashboard_setup-success-notification-rrm' ,
812+ 'view_notification' ,
813+ 'ONBOARDING_COMPLETE:noPayment:yes' +
814+ expectedLabelSuffix ,
815+ undefined
816+ ) ;
783817
784- // eslint-disable-next-line require-await
785- await act ( async ( ) => {
786- fireEvent . click ( ctaButton ) ;
787- } ) ;
818+ // "Learn more" link should be present.
819+ const learnMoreLink = getByText ( 'Learn more' ) ;
820+ expect ( learnMoreLink ) . toBeInTheDocument ( ) ;
788821
789- expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
790- 2 ,
791- 'mainDashboard_setup-success-notification-rrm' ,
792- 'confirm_notification' ,
793- 'ONBOARDING_COMPLETE:noPayment:yes' ,
794- undefined
795- ) ;
822+ // eslint-disable-next-line require-await
823+ await act ( async ( ) => {
824+ fireEvent . click ( learnMoreLink ) ;
825+ } ) ;
826+
827+ expect ( mockTrackEvent ) . toHaveBeenNthCalledWith (
828+ 2 ,
829+ 'mainDashboard_setup-success-notification-rrm' ,
830+ 'click_learn_more_link' ,
831+ 'ONBOARDING_COMPLETE:noPayment:yes' +
832+ expectedLabelSuffix ,
833+ undefined
834+ ) ;
835+ } ) ;
836+ }
796837 } ) ;
797838 } ) ;
798839} ) ;
0 commit comments