Skip to content

Commit

Permalink
Add test cases for the consent mode setup CTA check requirements call…
Browse files Browse the repository at this point in the history
…back.
  • Loading branch information
jimmymadon committed Jan 29, 2025
1 parent feb3c16 commit 4d5d3ad
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import {
provideUserAuthentication,
} from '../../../../tests/js/test-utils';
import ConsentModeSetupCTAWidget from './ConsentModeSetupCTAWidget';
import { VIEW_CONTEXT_MAIN_DASHBOARD } from '../../googlesitekit/constants';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import { CORE_USER } from '../../googlesitekit/datastore/user/constants';
import { CONSENT_MODE_SETUP_CTA_WIDGET_SLUG } from './constants';
import { withNotificationComponentProps } from '../../googlesitekit/notifications/util/component-props';
import { DEFAULT_NOTIFICATIONS } from '../../googlesitekit/notifications/register-defaults';
import { mockSurveyEndpoints } from '../../../../tests/js/mock-survey-endpoints';

describe( 'ConsentModeSetupCTAWidget', () => {
Expand All @@ -35,6 +37,9 @@ describe( 'ConsentModeSetupCTAWidget', () => {
CONSENT_MODE_SETUP_CTA_WIDGET_SLUG
)( ConsentModeSetupCTAWidget );

const notification =
DEFAULT_NOTIFICATIONS[ CONSENT_MODE_SETUP_CTA_WIDGET_SLUG ];

beforeEach( () => {
registry = createTestRegistry();

Expand Down Expand Up @@ -89,4 +94,62 @@ describe( 'ConsentModeSetupCTAWidget', () => {

expect( container ).toBeEmptyDOMElement();
} );

describe( 'checkRequirements', () => {
it( 'is active when consent mode is not enabled and ads is connected', async () => {
registry.dispatch( CORE_SITE ).receiveGetConsentModeSettings( {
enabled: false,
adsConnected: true,
} );

const isActive = await notification.checkRequirements(
registry,
VIEW_CONTEXT_MAIN_DASHBOARD
);
expect( isActive ).toBe( true );
} );

it( 'is not active when consent mode is already enabled and ads is connected', async () => {
registry.dispatch( CORE_SITE ).receiveGetConsentModeSettings( {
enabled: true,
adsConnected: true,
} );

const isActive = await notification.checkRequirements(
registry,
VIEW_CONTEXT_MAIN_DASHBOARD
);
expect( isActive ).toBe( false );
} );

it( 'is not active when consent mode is not enabled but ads is not connected', async () => {
registry.dispatch( CORE_SITE ).receiveGetConsentModeSettings( {
enabled: false,
adsConnected: false,
} );

registry
.dispatch( CORE_SITE )
.receiveGetAdsMeasurementStatus( { connected: false } );

const isActive = await notification.checkRequirements(
registry,
VIEW_CONTEXT_MAIN_DASHBOARD
);
expect( isActive ).toBe( false );
} );

it( 'is not active when consent mode is enabled and ads is not connected', async () => {
registry.dispatch( CORE_SITE ).receiveGetConsentModeSettings( {
enabled: true,
adsConnected: false,
} );

const isActive = await notification.checkRequirements(
registry,
VIEW_CONTEXT_MAIN_DASHBOARD
);
expect( isActive ).toBe( false );
} );
} );
} );

0 comments on commit 4d5d3ad

Please sign in to comment.