Skip to content

Commit 02173c6

Browse files
authored
Fix Blaze Traffic card for coming-soon sites (#112463)
1 parent 29113d2 commit 02173c6

2 files changed

Lines changed: 110 additions & 4 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { getBlazeAdvertisingUrl, shouldShowBlazeAdvertisingOption } from '../traffic';
2+
3+
const siteId = 123;
4+
5+
const getState = ( {
6+
canBlaze,
7+
isComingSoon = false,
8+
isSiteKnown = true,
9+
siteSettingsComingSoon = false,
10+
} ) => {
11+
const site = {
12+
ID: siteId,
13+
URL: 'https://example.wordpress.com',
14+
is_coming_soon: isComingSoon,
15+
options: {
16+
can_blaze: canBlaze,
17+
is_wpcom_simple: true,
18+
},
19+
};
20+
21+
return {
22+
sites: {
23+
items: isSiteKnown ? { [ siteId ]: site } : {},
24+
},
25+
siteSettings: {
26+
items: {
27+
[ siteId ]: {
28+
wpcom_coming_soon: siteSettingsComingSoon ? 1 : 0,
29+
},
30+
},
31+
},
32+
};
33+
};
34+
35+
describe( 'shouldShowBlazeAdvertisingOption', () => {
36+
test( 'returns true when the site can use Blaze', () => {
37+
const state = getState( { canBlaze: true } );
38+
39+
expect( shouldShowBlazeAdvertisingOption( state, siteId ) ).toBe( true );
40+
} );
41+
42+
test( 'returns true when the site is coming soon', () => {
43+
const state = getState( { canBlaze: false, isComingSoon: true } );
44+
45+
expect( shouldShowBlazeAdvertisingOption( state, siteId ) ).toBe( true );
46+
} );
47+
48+
test( 'returns true when site settings identify the site as coming soon', () => {
49+
const state = getState( {
50+
canBlaze: false,
51+
isSiteKnown: false,
52+
siteSettingsComingSoon: true,
53+
} );
54+
55+
expect( shouldShowBlazeAdvertisingOption( state, siteId ) ).toBe( true );
56+
} );
57+
58+
test( 'returns false when the site cannot use Blaze and is not coming soon', () => {
59+
const state = getState( { canBlaze: false } );
60+
61+
expect( shouldShowBlazeAdvertisingOption( state, siteId ) ).toBe( false );
62+
} );
63+
} );
64+
65+
describe( 'getBlazeAdvertisingUrl', () => {
66+
test( 'returns the Calypso Advertising route when the site slug is available', () => {
67+
expect(
68+
getBlazeAdvertisingUrl( {
69+
siteSlug: 'example.wordpress.com',
70+
wpAdminAdvertisingUrl: 'https://example.wordpress.com/wp-admin/tools.php?page=advertising',
71+
} )
72+
).toBe( '/advertising/example.wordpress.com' );
73+
} );
74+
75+
test( 'returns the wp-admin Advertising URL as a fallback', () => {
76+
const wpAdminAdvertisingUrl =
77+
'https://example.wordpress.com/wp-admin/tools.php?page=advertising';
78+
79+
expect(
80+
getBlazeAdvertisingUrl( {
81+
siteSlug: null,
82+
wpAdminAdvertisingUrl,
83+
} )
84+
).toBe( wpAdminAdvertisingUrl );
85+
} );
86+
} );

client/sites/marketing/traffic/traffic.jsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import Sitemaps from 'calypso/my-sites/site-settings/sitemaps';
2525
import wrapSettingsForm from 'calypso/my-sites/site-settings/wrap-settings-form';
2626
import { canCurrentUser } from 'calypso/state/selectors/can-current-user';
2727
import isBlazeEnabled from 'calypso/state/selectors/is-blaze-enabled';
28-
import { isJetpackSite } from 'calypso/state/sites/selectors';
28+
import isSiteComingSoon from 'calypso/state/selectors/is-site-coming-soon';
29+
import { getSiteSlug, isJetpackSite } from 'calypso/state/sites/selectors';
2930
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
3031

3132
import './style.scss';
@@ -35,6 +36,18 @@ const loadForm = () =>
3536
/* webpackChunkName: "async-load-calypso-my-sites-site-settings-seo-settings-form" */ 'calypso/my-sites/site-settings/seo-settings/form'
3637
);
3738

39+
export const shouldShowBlazeAdvertisingOption = ( state, siteId ) => {
40+
return isBlazeEnabled( state, siteId ) || isSiteComingSoon( state, siteId );
41+
};
42+
43+
export const getBlazeAdvertisingUrl = ( { siteSlug, wpAdminAdvertisingUrl } ) => {
44+
if ( siteSlug ) {
45+
return `/advertising/${ siteSlug }`;
46+
}
47+
48+
return wpAdminAdvertisingUrl;
49+
};
50+
3851
const SiteSettingsTraffic = ( {
3952
fields,
4053
handleAutosavingRadio,
@@ -46,6 +59,7 @@ const SiteSettingsTraffic = ( {
4659
isSavingSettings,
4760
setFieldValue,
4861
siteId,
62+
siteSlug,
4963
shouldShowAdvertisingOption,
5064
translate,
5165
} ) => {
@@ -57,6 +71,10 @@ const SiteSettingsTraffic = ( {
5771
}, [] );
5872

5973
const advertisingUrl = useAdvertisingUrl();
74+
const blazeAdvertisingUrl = getBlazeAdvertisingUrl( {
75+
siteSlug,
76+
wpAdminAdvertisingUrl: advertisingUrl,
77+
} );
6078

6179
return (
6280
// eslint-disable-next-line wpcalypso/jsx-classname-namespace
@@ -95,7 +113,7 @@ const SiteSettingsTraffic = ( {
95113
) }
96114
ctaText={ translate( 'Get started' ) }
97115
image={ blazeIllustration }
98-
href={ advertisingUrl }
116+
href={ blazeAdvertisingUrl }
99117
/>
100118
) }
101119
{ isAdmin && (
@@ -142,14 +160,16 @@ const connectComponent = connect( ( state ) => {
142160
const isAdmin = canCurrentUser( state, siteId, 'manage_options' );
143161
const isJetpack = isJetpackSite( state, siteId );
144162
const isJetpackAdmin = isJetpack && isAdmin;
145-
const shouldShowAdvertisingOption = isBlazeEnabled( state, siteId );
163+
const siteSlug = getSiteSlug( state, siteId );
164+
const showAdvertisingOption = shouldShowBlazeAdvertisingOption( state, siteId );
146165

147166
return {
148167
siteId,
149168
isAdmin,
150169
isJetpack,
151170
isJetpackAdmin,
152-
shouldShowAdvertisingOption,
171+
siteSlug,
172+
shouldShowAdvertisingOption: showAdvertisingOption,
153173
};
154174
} );
155175

0 commit comments

Comments
 (0)