File size: 10,536 Bytes
1e92f2d |
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
/**
* @jest-environment jsdom
*/
import { GOOGLE_WORKSPACE_PRODUCT_TYPE, GSUITE_PRODUCT_TYPE } from 'calypso/lib/gsuite/constants';
import {
domainsManagementPrefix,
emailManagementAllSitesPrefix,
getAddEmailForwardsPath,
getAddGSuiteUsersPath,
getManageTitanAccountPath,
getManageTitanMailboxesPath,
getNewTitanAccountPath,
getTitanSetUpMailboxPath,
getTitanControlPanelRedirectPath,
getEmailManagementPath,
getForwardingPath,
getPurchaseNewEmailAccountPath,
getEmailInDepthComparisonPath,
getProfessionalEmailCheckoutUpsellPath,
getMailboxesPath,
isUnderEmailManagementAll,
getEmailCheckoutPath,
} from '../paths';
const siteName = 'hello.wordpress.com';
const domainName = 'hello.com';
jest.mock( '@automattic/calypso-config', () => ( { isEnabled: () => true } ) );
describe( 'path helper functions', () => {
it( 'getAddEmailForwardsPath', () => {
expect( getAddEmailForwardsPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/forwarding/add/${ siteName }`
);
expect( getAddEmailForwardsPath( ':site', ':domain', emailManagementAllSitesPrefix ) ).toEqual(
'/email/all/:domain/forwarding/add/:site'
);
expect( getAddEmailForwardsPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/forwarding/add/:site'
);
expect( getAddEmailForwardsPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getAddEmailForwardsPath( null, null ) ).toEqual( '/email' );
expect( getAddEmailForwardsPath( ':site', ':domain', domainsManagementPrefix ) ).toEqual(
'/domains/manage/all/email/:domain/forwarding/add/:site'
);
const relativeTo = '/overview/site-domain/email';
expect( getAddEmailForwardsPath( siteName, domainName, relativeTo ) ).toEqual(
`/overview/site-domain/email/${ domainName }/forwarding/add/${ siteName }`
);
} );
it( 'getAddGSuiteUsersPath', () => {
const productTypePlaceholder = `:productType(${ GOOGLE_WORKSPACE_PRODUCT_TYPE }|${ GSUITE_PRODUCT_TYPE })`;
expect( getAddGSuiteUsersPath( siteName, domainName, 'google-workspace' ) ).toEqual(
`/email/${ domainName }/google-workspace/add-users/${ siteName }`
);
expect( getAddGSuiteUsersPath( ':site', ':domain', productTypePlaceholder ) ).toEqual(
`/email/:domain/${ productTypePlaceholder }/add-users/:site`
);
expect( getAddGSuiteUsersPath( ':site', ':domain', 'google-workspace' ) ).toEqual(
'/email/:domain/google-workspace/add-users/:site'
);
expect( getAddGSuiteUsersPath( siteName, null, 'google-workspace' ) ).toEqual(
`/email/google-workspace/add-users/${ siteName }`
);
expect( getAddGSuiteUsersPath( null, null, 'google-workspace' ) ).toEqual( '/email' );
} );
it( 'getManageTitanAccountPath', () => {
expect( getManageTitanAccountPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/titan/manage/${ siteName }`
);
expect( getManageTitanAccountPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/titan/manage/:site'
);
expect( getManageTitanAccountPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getManageTitanAccountPath( null, null ) ).toEqual( '/email' );
} );
it( 'getManageTitanMailboxesPath', () => {
expect( getManageTitanMailboxesPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/titan/manage-mailboxes/${ siteName }`
);
expect(
getManageTitanMailboxesPath( ':site', ':domain', emailManagementAllSitesPrefix )
).toEqual( '/email/all/:domain/titan/manage-mailboxes/:site' );
expect( getManageTitanMailboxesPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/titan/manage-mailboxes/:site'
);
expect( getManageTitanMailboxesPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getManageTitanMailboxesPath( null, null ) ).toEqual( '/email' );
} );
it( 'getNewTitanAccountPath', () => {
expect( getNewTitanAccountPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/titan/new/${ siteName }`
);
expect( getNewTitanAccountPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/titan/new/:site'
);
expect( getNewTitanAccountPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getNewTitanAccountPath( null, null ) ).toEqual( '/email' );
} );
it( 'getTitanSetUpMailboxPath', () => {
expect( getTitanSetUpMailboxPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/titan/set-up-mailbox/${ siteName }`
);
expect( getTitanSetUpMailboxPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/titan/set-up-mailbox/:site'
);
expect( getTitanSetUpMailboxPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getTitanSetUpMailboxPath( null, null ) ).toEqual( '/email' );
} );
it( 'getTitanControlPanelRedirectPath', () => {
expect( getTitanControlPanelRedirectPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/titan/control-panel/${ siteName }`
);
expect(
getTitanControlPanelRedirectPath( ':site', ':domain', emailManagementAllSitesPrefix )
).toEqual( '/email/all/:domain/titan/control-panel/:site' );
expect( getTitanControlPanelRedirectPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/titan/control-panel/:site'
);
expect( getTitanControlPanelRedirectPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getTitanControlPanelRedirectPath( null, null ) ).toEqual( '/email' );
} );
it( 'getEmailManagementPath', () => {
expect( getEmailManagementPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/manage/${ siteName }`
);
expect( getEmailManagementPath( ':site', ':domain', emailManagementAllSitesPrefix ) ).toEqual(
'/email/all/:domain/manage/:site'
);
expect( getEmailManagementPath( ':site', ':domain' ) ).toEqual( '/email/:domain/manage/:site' );
expect( getEmailManagementPath( ':site' ) ).toEqual( '/email/:site' );
expect( getEmailManagementPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getEmailManagementPath( null, null ) ).toEqual( '/email' );
const relativeTo = '/domains/manage/all/email';
expect( getEmailManagementPath( siteName, domainName, relativeTo ) ).toEqual(
`/domains/manage/all/email/${ domainName }/${ siteName }`
);
const inSiteContext = true;
expect( getEmailManagementPath( siteName, domainName, relativeTo, {}, inSiteContext ) ).toEqual(
`/overview/site-domain/email/${ domainName }/${ siteName }`
);
} );
it( 'getForwardingPath', () => {
expect( getForwardingPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/forwarding/${ siteName }`
);
expect( getForwardingPath( ':site', ':domain', emailManagementAllSitesPrefix ) ).toEqual(
'/email/all/:domain/forwarding/:site'
);
expect( getForwardingPath( ':site', ':domain' ) ).toEqual( '/email/:domain/forwarding/:site' );
expect( getForwardingPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getForwardingPath( null, null ) ).toEqual( '/email' );
} );
it( 'getPurchaseNewEmailAccountPath', () => {
expect( getPurchaseNewEmailAccountPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/purchase/${ siteName }`
);
expect(
getPurchaseNewEmailAccountPath( ':site', ':domain', emailManagementAllSitesPrefix )
).toEqual( '/email/all/:domain/purchase/:site' );
expect( getPurchaseNewEmailAccountPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/purchase/:site'
);
expect( getPurchaseNewEmailAccountPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getPurchaseNewEmailAccountPath( null, null ) ).toEqual( '/email' );
} );
it( 'getEmailInDepthComparisonPath', () => {
expect( getEmailInDepthComparisonPath( siteName, domainName ) ).toEqual(
`/email/${ domainName }/compare/${ siteName }`
);
expect( getEmailInDepthComparisonPath( ':site', ':domain' ) ).toEqual(
'/email/:domain/compare/:site'
);
expect( getEmailInDepthComparisonPath( siteName, null ) ).toEqual( `/email/${ siteName }` );
expect( getEmailInDepthComparisonPath( null, null ) ).toEqual( '/email' );
const relativeTo = '/domains/manage/all/email';
expect( getEmailInDepthComparisonPath( siteName, domainName, relativeTo ) ).toEqual(
`/domains/manage/all/email/${ domainName }/compare/${ siteName }?referrer=${ encodeURIComponent(
relativeTo
) }`
);
const relativeToSiteDomain = '/overview/site-domain/email';
expect( getEmailInDepthComparisonPath( siteName, domainName, relativeToSiteDomain ) ).toEqual(
`/overview/site-domain/email/${ domainName }/compare/${ siteName }?referrer=${ encodeURIComponent(
relativeToSiteDomain
) }`
);
} );
it( 'getMailboxesPath', () => {
expect( getMailboxesPath( siteName ) ).toEqual( `/mailboxes/${ siteName }` );
expect( getMailboxesPath( ':site' ) ).toEqual( '/mailboxes/:site' );
expect( getMailboxesPath() ).toEqual( '/mailboxes' );
} );
it( 'getProfessionalEmailCheckoutUpsellPath', () => {
expect( getProfessionalEmailCheckoutUpsellPath( siteName, domainName, 1234 ) ).toEqual(
`/checkout/offer-professional-email/${ domainName }/1234/${ siteName }`
);
expect( getProfessionalEmailCheckoutUpsellPath( ':site', ':domain', ':receiptId' ) ).toEqual(
'/checkout/offer-professional-email/:domain/:receiptId/:site'
);
} );
it( 'getEmailCheckoutPath', () => {
const email = 'hi@example.com';
const relativeToDomainManagement = '/domains/manage/all/email';
const relativeToSiteDomain = '/overview/site-domain/email';
expect( getEmailCheckoutPath( siteName, domainName ) ).toEqual( `/checkout/${ siteName }` );
expect( getEmailCheckoutPath( siteName, domainName, relativeToDomainManagement ) ).toEqual(
`/checkout/${ siteName }?redirect_to=${ encodeURIComponent(
`${ relativeToDomainManagement }/${ domainName }/${ siteName }`
) }`
);
expect(
getEmailCheckoutPath( siteName, domainName, relativeToDomainManagement, email )
).toEqual(
`/checkout/${ siteName }?redirect_to=${ encodeURIComponent(
`${ relativeToDomainManagement }/${ domainName }/${ siteName }?new-email=${ email }`
) }`
);
expect( getEmailCheckoutPath( siteName, domainName, relativeToSiteDomain, email ) ).toEqual(
`/checkout/${ siteName }?redirect_to=${ encodeURIComponent(
`${ relativeToSiteDomain }/${ domainName }/${ siteName }?new-email=${ email }`
) }`
);
} );
it.each( [
[ '/domains', false ],
[ '/email', false ],
[ '/email/all', false ],
[ '/email/all/', true ],
] )( 'isUnderEmailManagement %s', ( path, expectedResult ) => {
expect( isUnderEmailManagementAll( path ) ).toEqual( expectedResult );
} );
} );
|