Randomize the sections in the recommended marketing extensions (#33851)

This commit is contained in:
Adrian Duffell 2022-07-14 13:41:18 +08:00 committed by GitHub
parent 9d6bf48964
commit 4ab95678ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -54,7 +54,11 @@ export const getMarketingExtensionLists = (
): [ PluginProps[], PluginListProps[] ] => {
const installed: PluginProps[] = [];
const lists: PluginListProps[] = [];
freeExtensions.forEach( ( list ) => {
const freeExtensionsRandomized: ExtensionList[] = freeExtensions.sort(
() => Math.random() - 0.5
); // Randomize the order sections appear.
freeExtensionsRandomized.forEach( ( list ) => {
if ( ! ALLOWED_PLUGIN_LISTS.includes( list.key ) ) {
return;
}
@ -133,6 +137,9 @@ const Marketing: React.FC< MarketingProps > = ( { onComplete } ) => {
installed_extensions: installedExtensions.map(
( extension ) => extension.slug
),
section_order: pluginLists
.map( ( list ) => list.key )
.join( ', ' ),
} );
createNoticesFromResponse( response );

View File

@ -117,10 +117,11 @@ describe( 'getMarketingExtensionLists', () => {
[],
[]
);
const listKeys = lists.map( ( list ) => list.key );
expect( lists.length ).toBe( 2 );
expect( lists[ 0 ].key ).toBe( 'task-list/reach' );
expect( lists[ 1 ].key ).toBe( 'task-list/grow' );
expect( listKeys ).toContain( 'task-list/reach' );
expect( listKeys ).toContain( 'task-list/grow' );
} );
test( 'should separate installed plugins', () => {

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Randomize the order of sections in Recommended Marketing Extensions