Skip to content

Commit 15ced7a

Browse files
authored
My Jetpack: show the Overview v1 Welcome heading above notices and banners (#54098)
1 parent 3742cec commit 15ced7a

5 files changed

Lines changed: 46 additions & 5 deletions

File tree

‎projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/overview/content.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import OverviewSections from '../../product-cards-section/overview-sections';
1111
import SeoOptInCard from '../../seo-opt-in-card';
1212
import { A4AUpsell } from './a4a-upsell';
1313
import styles from './styles.module.scss';
14+
import type { ReactNode } from 'react';
1415

1516
/**
1617
* The Overview content component. The full-width footer band (Plans +
1718
* Connection), when shown, lives in `OverviewFooter`, rendered by `TabContent`.
1819
*
20+
* @param {object} props - Component props.
21+
* @param {ReactNode} props.beforeContent - Notices, shown below the Welcome heading.
1922
* @return The rendered component.
2023
*/
21-
export function OverviewContent() {
24+
export function OverviewContent( { beforeContent }: { beforeContent?: ReactNode } ) {
2225
const { overviewV1 = false } = getMyJetpackWindowInitialState( 'myJetpackFlags' );
2326
// Loads the plans the header's plan summary shows, so they're ready when it opens.
2427
useSitePurchases( { enabled: isHeaderControlsEnabled() } );
@@ -43,6 +46,7 @@ export function OverviewContent() {
4346
: __( 'Welcome to Jetpack', 'jetpack-my-jetpack' ) }
4447
</Text>
4548
</div>
49+
{ beforeContent }
4650
<OverviewSections />
4751
<OverviewBlogPosts />
4852
</>

‎projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/overview/test/content.test.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,14 @@ describe( 'OverviewContent', () => {
3333
expect( screen.getByRole( 'heading', { level: 2, name: heading } ) ).toBeInTheDocument();
3434
}
3535
);
36+
37+
it( 'shows the notices below the Welcome heading', () => {
38+
render( <OverviewContent beforeContent={ <div>Notice</div> } /> );
39+
40+
expect(
41+
screen
42+
.getByRole( 'heading', { level: 2 } )
43+
.compareDocumentPosition( screen.getByText( 'Notice' ) )
44+
).toBe( Node.DOCUMENT_POSITION_FOLLOWING );
45+
} );
3646
} );

‎projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/tab-content.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import clsx from 'clsx';
2+
import { getMyJetpackWindowInitialState } from '../../data/utils/get-my-jetpack-window-state';
23
import { isHeaderControlsEnabled } from '../header-controls/slot';
34
import { FeaturesContent } from './features/content';
45
import { FullWidthSeparator } from './full-width-separator';
@@ -15,7 +16,7 @@ export type TabContentProps = {
1516
beforeContent?: ReactNode;
1617
};
1718

18-
const componentMap: Record< MyJetpackSection, ComponentType > = {
19+
const componentMap: Record< MyJetpackSection, ComponentType< { beforeContent?: ReactNode } > > = {
1920
overview: OverviewContent,
2021
features: FeaturesContent,
2122
help: HelpContent,
@@ -44,6 +45,8 @@ export function TabContent( { name, beforeContent }: TabContentProps ) {
4445
// The header's connection control shows the plan and the connection, so the Overview's band would repeat them.
4546
const dropsOverviewFooter = name === 'overview' && isHeaderControlsEnabled();
4647
const FooterComponent = dropsOverviewFooter ? undefined : footerMap[ name ];
48+
const { overviewV1 = false } = getMyJetpackWindowInitialState( 'myJetpackFlags' );
49+
const noticesBelowWelcome = name === 'overview' && overviewV1;
4750

4851
if ( ! ContentComponent ) {
4952
return null;
@@ -53,8 +56,8 @@ export function TabContent( { name, beforeContent }: TabContentProps ) {
5356
<>
5457
<div className={ styles[ 'my-jetpack-tab-panel-inner' ] }>
5558
<div className={ clsx( styles[ 'tab-content-wrapper' ] ) }>
56-
{ beforeContent }
57-
<ContentComponent />
59+
{ ! noticesBelowWelcome && beforeContent }
60+
<ContentComponent beforeContent={ noticesBelowWelcome ? beforeContent : undefined } />
5861
</div>
5962
</div>
6063
{ FooterComponent && (

‎projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/test/tab-content.test.tsx‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import { TabContent } from '../tab-content';
66
jest.mock( '../features/content', () => ( {
77
FeaturesContent: () => jest.requireActual( 'react' ).createElement( 'div', null, 'Features' ),
88
} ) );
9-
jest.mock( '../overview/content', () => ( { OverviewContent: () => null } ) );
9+
jest.mock( '../overview/content', () => ( {
10+
OverviewContent: ( { beforeContent } ) =>
11+
jest.requireActual( 'react' ).createElement( 'section', null, beforeContent ),
12+
} ) );
13+
let mockOverviewV1 = false;
14+
jest.mock( '../../../data/utils/get-my-jetpack-window-state', () => ( {
15+
getMyJetpackWindowInitialState: () => ( { overviewV1: mockOverviewV1 } ),
16+
} ) );
1017
jest.mock( '../overview/footer', () => ( {
1118
OverviewFooter: () =>
1219
jest.requireActual( 'react' ).createElement( 'div', null, 'Plan and Connection' ),
@@ -31,6 +38,19 @@ describe( 'TabContent', () => {
3138
expect( notice.compareDocumentPosition( section ) ).toBe( Node.DOCUMENT_POSITION_FOLLOWING );
3239
} );
3340

41+
it.each( [ false, true ] )(
42+
'with Overview v1 on: %s, leaves the notices to the Overview only when on',
43+
overviewV1 => {
44+
mockOverviewV1 = overviewV1;
45+
render(
46+
<TabContent name={ MY_JETPACK_SECTION_OVERVIEW } beforeContent={ <div>Notice</div> } />
47+
);
48+
49+
// eslint-disable-next-line testing-library/no-node-access -- The Overview content has no role or text to query by.
50+
expect( screen.getByText( 'Notice' ).closest( 'section' ) !== null ).toBe( overviewV1 );
51+
}
52+
);
53+
3454
it.each( [
3555
[ false, 1 ],
3656
[ true, 0 ],
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Overview: Show the Welcome heading above notices and banners, behind the Overview v1 feature flag.

0 commit comments

Comments
 (0)