Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor/6651-repl…
Browse files Browse the repository at this point in the history
…ace-direct-usage-of-textfield-with-md-textfield.
  • Loading branch information
10upsimon committed Jun 29, 2023
2 parents eb213b5 + d9723a9 commit dfc5c61
Show file tree
Hide file tree
Showing 41 changed files with 1,216 additions and 118 deletions.
2 changes: 1 addition & 1 deletion assets/js/components/KeyMetrics/MetricTileTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function MetricTileTable( props ) {
} else if ( !! ZeroState ) {
tileBody = (
<div className="googlesitekit-table__body-row googlesitekit-table__body-row--no-data">
<div className="googlesitekit-table__body-item">
<div className="googlesitekit-table__body-zero-data">
<ZeroState />
</div>
</div>
Expand Down
18 changes: 11 additions & 7 deletions assets/js/googlesitekit/datastore/user/user-input-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const baseActions = {
}

if ( ! error ) {
yield registry.dispatch( CORE_USER ).maybeTriggerUserInputSurvey();
yield baseActions.maybeTriggerUserInputSurvey();
}

yield {
Expand Down Expand Up @@ -157,13 +157,17 @@ const baseActions = {
/**
* Triggers user input survey if any of the answers is "Other".
*
* @since n.e.x.t
* @since 1.104.0
*
* @return {Object} Object with `response` and `error`.
*/
*maybeTriggerUserInputSurvey() {
const registry = yield Data.commonActions.getRegistry();
const settings = registry.select( CORE_USER ).getUserInputSettings();
const { __experimentalResolveSelect, dispatch } =
yield commonActions.getRegistry();

const settings = yield commonActions.await(
__experimentalResolveSelect( CORE_USER ).getUserInputSettings()
);

const settingsAnsweredOther = Object.keys( settings ).filter( ( key ) =>
settings[ key ].values.includes( 'other' )
Expand All @@ -177,9 +181,9 @@ const baseActions = {
'_'
) }`;

const { response, error } = yield registry
.dispatch( CORE_USER )
.triggerSurvey( triggerID );
const { response, error } = yield commonActions.await(
dispatch( CORE_USER ).triggerSurvey( triggerID )
);

return { response, error };
},
Expand Down
30 changes: 4 additions & 26 deletions assets/js/googlesitekit/datastore/user/user-input-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,6 @@ describe( 'core/user user-input-settings', () => {
registry.select( CORE_USER ).getUserInputSettings()
).toEqual( settingsResponse );

await subscribeUntil( registry, () =>
registry
.select( CORE_USER )
.hasFinishedResolution( 'getSurveyTimeouts' )
);

await subscribeUntil( registry, () =>
registry
.select( CORE_USER )
.hasFinishedResolution( 'getUserInputSettings' )
);

expect( fetchMock ).toHaveFetched( surveyTriggerEndpoint, {
body: {
data: {
Expand Down Expand Up @@ -305,7 +293,7 @@ describe( 'core/user user-input-settings', () => {
expect( fetchMock ).not.toHaveFetched( surveyTriggerEndpoint );
} );

it( 'should trigger survey if answers conatin "Other"', async () => {
it( 'should trigger survey if answers contain "Other"', async () => {
muteFetch( surveyTriggerEndpoint );

registry.dispatch( CORE_USER ).receiveGetSurveyTimeouts( [] );
Expand All @@ -314,19 +302,9 @@ describe( 'core/user user-input-settings', () => {
.dispatch( CORE_USER )
.setUserInputSetting( 'goals', [ 'other' ] );

registry.dispatch( CORE_USER ).maybeTriggerUserInputSurvey();

await subscribeUntil( registry, () =>
registry
.select( CORE_USER )
.hasFinishedResolution( 'getSurveyTimeouts' )
);

await subscribeUntil( registry, () =>
registry
.select( CORE_USER )
.hasFinishedResolution( 'getUserInputSettings' )
);
await registry
.dispatch( CORE_USER )
.maybeTriggerUserInputSurvey();

expect( fetchMock ).toHaveFetched( surveyTriggerEndpoint, {
body: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ export default function AdBlockingRecoveryCTA() {
const siteStatus = useSelect( ( select ) =>
select( MODULES_ADSENSE ).getSiteStatus()
);
const hasExistingAdBlockingRecoveryTag = useSelect( ( select ) =>
select( MODULES_ADSENSE ).hasExistingAdBlockingRecoveryTag()
);
const recoveryPageURL = useSelect( ( select ) =>
select( CORE_SITE ).getAdminURL( 'googlesitekit-ad-blocking-recovery' )
);

if (
hasExistingAdBlockingRecoveryTag ||
adBlockingRecoverySetupStatus !== '' ||
accountStatus !== ACCOUNT_STATUS_READY ||
siteStatus !== SITE_STATUS_READY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
/**
* Internal dependencies
*/
import { provideModules } from '../../../../../../tests/js/utils';
import {
provideModules,
provideSiteInfo,
} from '../../../../../../tests/js/utils';
import WithRegistrySetup from '../../../../../../tests/js/WithRegistrySetup';
import { MODULES_ADSENSE } from '../../datastore/constants';
import { ACCOUNT_STATUS_READY, SITE_STATUS_READY } from '../../util';
Expand Down Expand Up @@ -54,6 +57,7 @@ export default {
slug: 'adsense',
},
] );
provideSiteInfo( registry );

registry
.dispatch( MODULES_ADSENSE )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ describe( 'AdBlockingRecoveryCTA', () => {
ACCOUNT_STATUS_READY,
SITE_STATUS_ADDED,
ENUM_AD_BLOCKING_RECOVERY_SETUP_STATUS.SETUP_CONFIRMED,
true,
],
[
'an existing ad blocker recovery tag is detected',
ACCOUNT_STATUS_READY,
SITE_STATUS_ADDED,
ENUM_AD_BLOCKING_RECOVERY_SETUP_STATUS.SETUP_CONFIRMED,
'pub-3467161886473746',
],
] )(
'should not render the CTA when %s',
(
testName,
accountStatus,
siteStatus,
adBlockingRecoverySetupStatus
adBlockingRecoverySetupStatus,
existingAdBlockingRecoveryTag = null
) => {
const { container } = render( <AdBlockingRecoveryCTA />, {
setupRegistry: ( registry ) => {
Expand All @@ -75,6 +82,11 @@ describe( 'AdBlockingRecoveryCTA', () => {
siteStatus,
adBlockingRecoverySetupStatus,
} );
registry
.dispatch( MODULES_ADSENSE )
.receiveGetExistingAdBlockingRecoveryTag(
existingAdBlockingRecoveryTag
);
},
} );

Expand Down Expand Up @@ -105,6 +117,9 @@ describe( 'AdBlockingRecoveryCTA', () => {
siteStatus: SITE_STATUS_READY,
adBlockingRecoverySetupStatus: '',
} );
registry
.dispatch( MODULES_ADSENSE )
.receiveGetExistingAdBlockingRecoveryTag( null );
},
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from '../../../../components/AdminMenuTooltip';
import { CORE_MODULES } from '../../../../googlesitekit/modules/datastore/constants';
import { MODULES_ADSENSE } from '../../datastore/constants';
import { WEEK_IN_SECONDS } from '../../../../util';
import { WEEK_IN_SECONDS, stringToDate } from '../../../../util';
import { ACCOUNT_STATUS_READY, SITE_STATUS_READY } from '../../util';
import useViewOnly from '../../../../hooks/useViewOnly';
import {
Expand Down Expand Up @@ -97,6 +97,9 @@ export default function AdBlockingRecoveryWidget( { Widget, WidgetNull } ) {
}
return select( MODULES_ADSENSE ).getSiteStatus();
} );
const hasExistingAdBlockingRecoveryTag = useSelect( ( select ) =>
select( MODULES_ADSENSE ).hasExistingAdBlockingRecoveryTag()
);
const learnMoreURL = useSelect( ( select ) =>
select( CORE_SITE ).getGoogleSupportURL( {
path: '/adsense/answer/11576589',
Expand All @@ -105,6 +108,9 @@ export default function AdBlockingRecoveryWidget( { Widget, WidgetNull } ) {
const recoveryPageURL = useSelect( ( select ) =>
select( CORE_SITE ).getAdminURL( 'googlesitekit-ad-blocking-recovery' )
);
const referenceDate = useSelect( ( select ) =>
select( CORE_USER ).getReferenceDate()
);

const { dismissItem } = useDispatch( CORE_USER );
const dismissCallback = async () => {
Expand All @@ -128,18 +134,21 @@ export default function AdBlockingRecoveryWidget( { Widget, WidgetNull } ) {
);
}

const threeWeeksInSeconds = WEEK_IN_SECONDS * 3;
const nowInSeconds = Math.floor( Date.now() / 1000 );
const nowInMilliseconds = stringToDate( referenceDate ).getTime();
const completionTimeInMilliseconds = setupCompletedTimestamp * 1000;
const threeWeeksInMilliseconds = WEEK_IN_SECONDS * 3 * 1000;

const shouldShowWidget =
! viewOnlyDashboard &&
adSenseModuleConnected &&
! hasExistingAdBlockingRecoveryTag &&
isDismissed === false &&
adBlockingRecoverySetupStatus !== '' &&
accountStatus === ACCOUNT_STATUS_READY &&
siteStatus === SITE_STATUS_READY &&
( ! setupCompletedTimestamp ||
nowInSeconds - setupCompletedTimestamp >= threeWeeksInSeconds );
nowInMilliseconds - completionTimeInMilliseconds >=
threeWeeksInMilliseconds );

if ( ! shouldShowWidget ) {
return <WidgetNull />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ import {
SITE_STATUS_READY,
} from '../../util';
import { getWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
import { WEEK_IN_SECONDS, DAY_IN_SECONDS } from '../../../../util';
import { stringToDate } from '../../../../util';

describe( 'AdSenseConnectCTA', () => {
describe( 'AdBlockingRecoveryWidget', () => {
let registry;
const timestampThreeWeeksAgo =
Math.floor( Date.now() / 1000 ) - WEEK_IN_SECONDS * 3;
const timestampLessThanThreeWeeksAgo =
timestampThreeWeeksAgo + DAY_IN_SECONDS;
const referenceDate = '2023-06-22';
const timestampThreeWeeksPrior =
stringToDate( '2023-06-01' ).getTime() / 1000;
const timestampLessThanThreeWeeksPrior =
stringToDate( '2023-06-02' ).getTime() / 1000;
const validSettings = {
accountID: 'pub-12345678',
clientID: 'ca-pub-12345678',
Expand All @@ -74,6 +75,7 @@ describe( 'AdSenseConnectCTA', () => {
slug: 'adsense',
},
] );
registry.dispatch( CORE_USER ).setReferenceDate( referenceDate );
registry.dispatch( CORE_USER ).receiveGetDismissedItems( [] );
} );

Expand All @@ -90,7 +92,7 @@ describe( 'AdSenseConnectCTA', () => {
'',
false,
false,
timestampThreeWeeksAgo,
timestampThreeWeeksPrior,
],
[
'notification is dismissed',
Expand All @@ -99,7 +101,7 @@ describe( 'AdSenseConnectCTA', () => {
'',
true,
true,
timestampThreeWeeksAgo,
timestampThreeWeeksPrior,
],
[
'the Adsense account status is not ready',
Expand All @@ -108,7 +110,7 @@ describe( 'AdSenseConnectCTA', () => {
'',
true,
false,
timestampThreeWeeksAgo,
timestampThreeWeeksPrior,
],
[
'the Adsense site status is not ready',
Expand All @@ -117,7 +119,7 @@ describe( 'AdSenseConnectCTA', () => {
'',
true,
false,
timestampThreeWeeksAgo,
timestampThreeWeeksPrior,
],
[
'the Ad blocking recovery status is an empty string',
Expand All @@ -126,7 +128,7 @@ describe( 'AdSenseConnectCTA', () => {
'',
true,
false,
timestampThreeWeeksAgo,
timestampThreeWeeksPrior,
],
[
'the setup completed timestamp is less than three weeks',
Expand All @@ -135,7 +137,17 @@ describe( 'AdSenseConnectCTA', () => {
ENUM_AD_BLOCKING_RECOVERY_SETUP_STATUS.SETUP_CONFIRMED,
true,
false,
timestampLessThanThreeWeeksAgo,
timestampLessThanThreeWeeksPrior,
],
[
'an existing ad blocker recovery tag is detected',
ACCOUNT_STATUS_READY,
SITE_STATUS_READY,
ENUM_AD_BLOCKING_RECOVERY_SETUP_STATUS.SETUP_CONFIRMED,
true,
false,
timestampThreeWeeksAgo,

Check failure on line 149 in assets/js/modules/adsense/components/dashboard/AdBlockingRecoveryWidget.test.js

View workflow job for this annotation

GitHub Actions / JS + CSS

'timestampThreeWeeksAgo' is not defined
'pub-3467161886473746',
],
] )(
'should not render the widget when %s',
Expand All @@ -146,7 +158,8 @@ describe( 'AdSenseConnectCTA', () => {
adBlockingRecoverySetupStatus,
isModuleConnected,
isNotificationDismissed,
setupCompletedTimestamp
setupCompletedTimestamp,
existingAdBlockingRecoveryTag = null
) => {
provideModules( registry, [
{
Expand All @@ -163,6 +176,11 @@ describe( 'AdSenseConnectCTA', () => {
adBlockingRecoverySetupStatus,
setupCompletedTimestamp,
} );
registry
.dispatch( MODULES_ADSENSE )
.receiveGetExistingAdBlockingRecoveryTag(
existingAdBlockingRecoveryTag
);
registry
.dispatch( CORE_USER )
.receiveGetDismissedItems( [
Expand Down Expand Up @@ -207,7 +225,7 @@ describe( 'AdSenseConnectCTA', () => {
it( 'should render the widget for the site with a setup completion time of more than three weeks', () => {
registry.dispatch( MODULES_ADSENSE ).receiveGetSettings( {
...validSettings,
setupCompletedTimestamp: timestampThreeWeeksAgo,
setupCompletedTimestamp: timestampThreeWeeksPrior,
} );

const { container } = render(
Expand All @@ -231,6 +249,9 @@ describe( 'AdSenseConnectCTA', () => {
registry
.dispatch( MODULES_ADSENSE )
.receiveGetSettings( validSettings );
registry
.dispatch( MODULES_ADSENSE )
.receiveGetExistingAdBlockingRecoveryTag( null );

container = render(
<div>
Expand Down
Loading

0 comments on commit dfc5c61

Please sign in to comment.