Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions assets/js/modules/pagespeed-insights/datastore/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
*/
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { createRegistrySelector } from 'googlesitekit-data';
import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants';
import { MODULES_PAGESPEED_INSIGHTS } from './constants';

export const selectors = {
/**
* Gets a URL to the service.
Expand All @@ -47,6 +54,24 @@ export const selectors = {
utm_source: 'sitekit',
} );
},

/**
* Gets the details link URL for the module.
*
* @since n.e.x.t
*
* @return {string} Details link URL.
*/
getDetailsLinkURL: createRegistrySelector( ( select ) => () => {
const siteURL = select( CORE_SITE ).getReferenceSiteURL();

return select( MODULES_PAGESPEED_INSIGHTS ).getServiceURL( {
path: 'report',
query: {
url: siteURL,
},
} );
} ),
};

const store = {
Expand Down
20 changes: 20 additions & 0 deletions assets/js/modules/pagespeed-insights/datastore/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* Internal dependencies
*/
import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants';
import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants';
import { createTestRegistry } from '@tests/js/utils';
import { MODULES_PAGESPEED_INSIGHTS } from './constants';
Expand Down Expand Up @@ -97,5 +98,24 @@ describe( 'module/pagespeed-insights service store', () => {
} );
} );
} );

describe( 'getDetailsLinkURL', () => {
it( 'returns the PageSpeed report URL for the reference site', () => {
const referenceSiteURL = 'https://example.com/test-page/';
registry.dispatch( CORE_SITE ).receiveSiteInfo( {
referenceSiteURL,
} );

const detailsLinkURL = registry
.select( MODULES_PAGESPEED_INSIGHTS )
.getDetailsLinkURL();

expect( new URL( detailsLinkURL ).pathname ).toBe( '/report' );
expect( detailsLinkURL ).toMatchQueryParameters( {
url: referenceSiteURL,
utm_source: 'sitekit',
} );
} );
} );
} );
} );