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