Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/#8786 - Implement JS entry point for RRM #8948

Merged
merged 44 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
78579b3
Add Reader Revenue Manager Settings components.
hussain-t Jul 1, 2024
0dd60bd
Add Reader Revenue Manager module entrypoint.
hussain-t Jul 1, 2024
cb85d3f
Add Settings constants.
hussain-t Jul 1, 2024
2bebd7f
Add new badge for RRM in SetupModule.
hussain-t Jul 1, 2024
cb5cb2b
Add new badge for RRM in SettingsActiveModule Header.
hussain-t Jul 1, 2024
3c8bfdb
Add Reader Revenue Manager module initialization.
hussain-t Jul 1, 2024
35e600b
Add Reader Revenue Manager SettingsEdit component.
hussain-t Jul 1, 2024
5968db2
Add Reader Revenue Manager SettingsView component.
hussain-t Jul 1, 2024
cc32f18
Add Reader Revenue Manager SetupMain component.
hussain-t Jul 1, 2024
45a3be2
Add RRM base data store.
hussain-t Jul 1, 2024
2a9f3b4
Add RRM data store constants.
hussain-t Jul 1, 2024
e175967
Add RRM registerStore.
hussain-t Jul 1, 2024
e56ecf5
Add RRM setup_assets method.
hussain-t Jul 1, 2024
c64fd97
Add RRM settings datastore.
hussain-t Jul 1, 2024
74b9219
Add RRM Validation utilities..
hussain-t Jul 1, 2024
82c4cdb
Add RRM svg logo.
hussain-t Jul 1, 2024
b2a4e60
Add RRM module entry in webpack config.
hussain-t Jul 1, 2024
71cbe5a
Add Reader Revenue Manager Setup components.
hussain-t Jul 1, 2024
27c1822
Merge branch 'develop' into enhance/#8786-add-rrm-js-entry-point.
ankitrox Jul 2, 2024
d3b1623
Add rrm base data store tests.
hussain-t Jul 2, 2024
ef74274
Add rrm index test base.
hussain-t Jul 2, 2024
127dfaa
Merge branch 'enhance/#8786-add-rrm-js-entry-point' of github.com:goo…
hussain-t Jul 2, 2024
f941c7d
Add rrm settings test base file.
hussain-t Jul 2, 2024
c556ad5
Add Validation function tests.
hussain-t Jul 2, 2024
306e1a6
Add SettingsEdit storybook.
hussain-t Jul 2, 2024
d0c8886
Add SettingsEdit test file.
hussain-t Jul 2, 2024
712ed3d
Add SettingsView storybook.
hussain-t Jul 2, 2024
1653114
Add SettingsView test file.
hussain-t Jul 2, 2024
d1a9dde
Add SetupMain storybook.
hussain-t Jul 2, 2024
741087e
Add SetupMain test file.
hussain-t Jul 2, 2024
1640fd2
Add todo comment in the registerModule features.
hussain-t Jul 2, 2024
35ab985
Add modulesReaderRevenueManager in tests/js/utils.
hussain-t Jul 2, 2024
328ca75
Fix settings test.
hussain-t Jul 2, 2024
cbf8f7e
Order imports.
hussain-t Jul 2, 2024
2761f76
Improve isURLUsingHTTPS fn.
hussain-t Jul 2, 2024
861a464
Improve isURLUsingHTTPS tests.
hussain-t Jul 2, 2024
9143609
Ensure the site info is resolved to get the home URL.
hussain-t Jul 2, 2024
fff0ef4
Address review feedback.
hussain-t Jul 2, 2024
e1f755b
Update publication ID validation to match base64 characters.
hussain-t Jul 3, 2024
3fbfd99
Fix tests for the updated validation.
hussain-t Jul 3, 2024
361f573
Merge branch 'develop' into enhance/#8786-add-rrm-js-entry-point.
hussain-t Jul 3, 2024
c802cad
Improve isURLUsingHTTPS logic.
hussain-t Jul 3, 2024
0be6bd6
Improve isURLUsingHTTPS tests.
hussain-t Jul 3, 2024
180e164
Remove datastore-forms and modules-data from RRM assets.
hussain-t Jul 3, 2024
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Reader Revenue Manager SettingsEdit component stories.
*
* Site Kit by Google, Copyright 2022 Google LLC
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Reader Revenue Manager SettingsView component stories.
*
* Site Kit by Google, Copyright 2022 Google LLC
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Reader Revenue Manager SetupMain component stories.
*
* Site Kit by Google, Copyright 2022 Google LLC
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function validateCanSubmitChanges( select ) {
const { haveSettingsChanged, isDoingSubmitChanges, getPublicationID } =
strictSelect( MODULES_READER_REVENUE_MANAGER );

// Note: these error messages are referenced in test assertions.
invariant( ! isDoingSubmitChanges(), INVARIANT_DOING_SUBMIT_CHANGES );
invariant( haveSettingsChanged(), INVARIANT_SETTINGS_NOT_CHANGED );

Expand Down
6 changes: 4 additions & 2 deletions assets/js/modules/reader-revenue-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ export const registerModule = isRrmModuleEnabled( ( modules ) => {
// TODO: Implement the features as part of #8845.
],
checkRequirements: async ( registry ) => {
const homeURL = await registry
// Ensure the site info is resolved to get the home URL.
await registry
.__experimentalResolveSelect( CORE_SITE )
.getHomeURL();
.getSiteInfo();
const homeURL = registry.select( CORE_SITE ).getHomeURL();

if ( isURLUsingHTTPS( homeURL ) ) {
return;
Expand Down
13 changes: 11 additions & 2 deletions assets/js/modules/reader-revenue-manager/utils/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
export function isValidPublicationID( publicationID ) {
return (
typeof publicationID === 'string' &&
/^[A-Za-z0-9_.-]+$/.test( publicationID )
/^[A-Za-z0-9_-]+$/.test( publicationID )
);
}

Expand All @@ -41,9 +41,18 @@ export function isValidPublicationID( publicationID ) {
*/
export const isURLUsingHTTPS = ( url ) => {
try {
if ( typeof url !== 'string' || ! url ) {
throw new TypeError( `Invalid URL: ${ url }` );
}

const parsedURL = new URL( url );
return parsedURL.protocol === 'https:';
if ( parsedURL.protocol !== 'https:' ) {
throw new TypeError( `Invalid URL: ${ url }` );
techanvil marked this conversation as resolved.
Show resolved Hide resolved
}

return true;
} catch ( error ) {
global.console.warn( 'Invalid URL:', error );
return false;
techanvil marked this conversation as resolved.
Show resolved Hide resolved
}
};
23 changes: 21 additions & 2 deletions assets/js/modules/reader-revenue-manager/utils/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { isValidPublicationID, isURLUsingHTTPS } from './validation';
describe( 'utility functions', () => {
describe( 'isValidPublicationID', () => {
it( 'should return TRUE when a valid publication ID is passed', () => {
expect( isValidPublicationID( 'valid-publication_123.ID' ) ).toBe(
expect( isValidPublicationID( 'valid_publication-123' ) ).toBe(
true
);
} );
Expand All @@ -33,15 +33,32 @@ describe( 'utility functions', () => {
[ 'false', false ],
[ 'an integer', 12345 ],
[ 'an empty string', '' ],
[ 'a string with invalid characters', 'invalid-publication!ID' ],
[ 'a string with invalid characters', 'invalid.publication!ID' ],
[ 'a string with periods', 'invalid.publication.ID' ],
] )( 'should return FALSE when %s is passed', ( _, publicationID ) => {
expect( isValidPublicationID( publicationID ) ).toBe( false );
} );
} );

describe( 'isURLUsingHTTPS', () => {
beforeAll( () => {
jest.spyOn( console, 'warn' ).mockImplementation( () => {} );
} );

afterAll( () => {
// eslint-disable-next-line no-console
console.warn.mockRestore();
} );

afterEach( () => {
// eslint-disable-next-line no-console
console.warn.mockClear();
} );

techanvil marked this conversation as resolved.
Show resolved Hide resolved
it( 'should return TRUE when a URL with HTTPS is passed', () => {
expect( isURLUsingHTTPS( 'https://example.com' ) ).toBe( true );
// eslint-disable-next-line no-console
expect( console.warn ).not.toHaveBeenCalled();
techanvil marked this conversation as resolved.
Show resolved Hide resolved
} );

it.each( [
Expand All @@ -52,6 +69,8 @@ describe( 'utility functions', () => {
[ 'false', false ],
] )( 'should return FALSE when %s is passed', ( _, url ) => {
expect( isURLUsingHTTPS( url ) ).toBe( false );
// eslint-disable-next-line no-console
expect( console.warn ).toHaveBeenCalled();
techanvil marked this conversation as resolved.
Show resolved Hide resolved
} );
} );
} );
Loading