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
23 changes: 23 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,22 @@ export const selectors = {
utm_source: 'sitekit',
} );
},

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

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

const store = {
Expand Down
26 changes: 26 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,30 @@ describe( 'module/pagespeed-insights service store', () => {
} );
} );
} );

describe( 'getDetailsLinkURL', () => {
it( 'should return the service report URL for the reference site', () => {
const referenceSiteURL = 'https://example.com/';

registry.dispatch( CORE_SITE ).receiveSiteInfo( {
referenceSiteURL,
} );

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

const expectedURL = registry
.select( MODULES_PAGESPEED_INSIGHTS )
.getServiceURL( {
path: 'report',
query: { url: referenceSiteURL },
} );

expect( new URL( detailsLinkURL ) ).toEqual(
new URL( expectedURL )
);
} );
} );
} );
} );