diff --git a/scripts/bundleSize/bundleSizeConfig.js b/scripts/bundleSize/bundleSizeConfig.js
index bf46927739f..55fec86d739 100644
--- a/scripts/bundleSize/bundleSizeConfig.js
+++ b/scripts/bundleSize/bundleSizeConfig.js
@@ -8,4 +8,4 @@
*/
export const MIN_SIZE = 635 - 5;
-export const MAX_SIZE = 1175 + 5;
+export const MAX_SIZE = 1181 + 5;
diff --git a/src/app/components/JumpTo/index.stories.tsx b/src/app/components/JumpTo/index.stories.tsx
index 265b0ca4884..7e9cd7b5caf 100644
--- a/src/app/components/JumpTo/index.stories.tsx
+++ b/src/app/components/JumpTo/index.stories.tsx
@@ -4,8 +4,16 @@ import JumpTo, { JumpToProps } from '.';
import metadata from './metadata.json';
import readme from './README.md';
-const Component = ({ jumpToHeadings = [] }: JumpToProps) => {
- return ;
+const Component = ({
+ jumpToHeadings = [],
+ showRelatedContentLink = false,
+}: JumpToProps) => {
+ return (
+
+ );
};
export default {
@@ -23,5 +31,14 @@ export const Example = () => {
block => block.type === 'jumpTo',
)?.model.jumpToHeadings;
- return ;
+ const showRelatedContentLink =
+ !!pidginArticleFixtureWithJumpToBlock.data.article.content.model.blocks.find(
+ block => block.type === 'relatedContent',
+ );
+ return (
+
+ );
};
diff --git a/src/app/components/JumpTo/index.test.tsx b/src/app/components/JumpTo/index.test.tsx
index 974a1f46f41..191360c4e8d 100644
--- a/src/app/components/JumpTo/index.test.tsx
+++ b/src/app/components/JumpTo/index.test.tsx
@@ -20,7 +20,8 @@ describe('JumpTo Component', () => {
jest.clearAllMocks();
});
- const jumpToHeadings = jumpToBlock?.model.jumpToHeadings ?? [];
+ const jumpToHeadings: Array<{ heading: string; sanitisedId?: string }> =
+ jumpToBlock?.model.jumpToHeadings ?? [];
describe('Render jumpTo', () => {
it('renders the Jump To title', () => {
@@ -29,19 +30,23 @@ describe('JumpTo Component', () => {
expect(title).toBeInTheDocument();
});
- it('renders the correct number of headings', () => {
+ it('renders the correct number of headings without related content link', () => {
render();
const headings = screen.getAllByRole('listitem');
expect(headings.length).toBe(jumpToHeadings.length);
});
+ it('renders the correct number of headings with related content link', () => {
+ render();
+ const headings = screen.getAllByRole('listitem');
+ expect(headings.length).toBe(jumpToHeadings.length);
+ });
it('renders each item with a link to the corresponding subheading on the same page', () => {
- render();
- const listItems = screen.getAllByRole('listitem');
- listItems.forEach((item, index) => {
- const link = item.querySelector('a');
- const sanitisedHeading = idSanitiser(jumpToHeadings[index].heading);
- const expectedHref = `#${sanitisedHeading}`;
+ render();
+ jumpToHeadings.forEach(({ heading, sanitisedId }) => {
+ const id = sanitisedId || idSanitiser(heading);
+ const link = screen.getByTestId(`jump-to-link-${id}`);
+ const expectedHref = `#${id}`;
expect(link).toHaveAttribute('href', expectedHref);
});
});
@@ -76,9 +81,9 @@ describe('JumpTo Component', () => {
render();
- jumpToHeadings.forEach(({ heading }) => {
- const sanitisedId = idSanitiser(heading);
- const link = screen.getByTestId(`jump-to-link-${sanitisedId}`);
+ jumpToHeadings.forEach(({ heading, sanitisedId }) => {
+ const id = sanitisedId || idSanitiser(heading);
+ const link = screen.getByTestId(`jump-to-link-${id}`);
fireEvent.click(link);
expect(link.onclick).toBeTruthy();
diff --git a/src/app/components/JumpTo/index.tsx b/src/app/components/JumpTo/index.tsx
index cfe9b629c2a..d98682b3b99 100644
--- a/src/app/components/JumpTo/index.tsx
+++ b/src/app/components/JumpTo/index.tsx
@@ -12,24 +12,24 @@ import idSanitiser from '../../lib/utilities/idSanitiser';
import styles from './index.styles';
export interface JumpToProps {
- jumpToHeadings?: Array<{ heading: string }>;
+ jumpToHeadings?: Array<{ heading: string; sanitisedId?: string }>;
+ showRelatedContentLink?: boolean;
}
const eventTrackingData: EventTrackingMetadata = {
componentName: 'jumpto',
};
-const JumpTo = ({ jumpToHeadings }: JumpToProps) => {
+const JumpTo = ({ jumpToHeadings, showRelatedContentLink }: JumpToProps) => {
// TODO: Remove for release
if (isLive()) return null;
const { translations } = useContext(ServiceContext);
const [hash, setHash] = useState('');
const { jumpTo = 'Jump to' } = translations?.articlePage || {};
-
+ const relatedContent = translations?.relatedContent || 'Related content';
const viewRef = useViewTracker(eventTrackingData);
const clickTrackerHandler = useClickTrackerHandler(eventTrackingData);
-
useEffect(() => {
setHash(window.location.hash);
}, []);
@@ -43,7 +43,15 @@ const JumpTo = ({ jumpToHeadings }: JumpToProps) => {
};
const titleId = 'jump-to-heading';
-
+ if (
+ showRelatedContentLink &&
+ !jumpToHeadings?.some(({ heading }) => heading === relatedContent)
+ ) {
+ jumpToHeadings?.push({
+ heading: relatedContent,
+ sanitisedId: 'section-label-heading-related-content-heading',
+ });
+ }
return (