Skip to content
Draft
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
3 changes: 3 additions & 0 deletions dotcom-rendering/src/components/ArticleTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
sectionUrl: string;
guardianBaseURL: string;
isMatch?: boolean;
ophanComponentLink?: string;
};

const sectionStyles = css`
Expand Down Expand Up @@ -85,13 +86,15 @@ export const ArticleTitle = ({
sectionUrl,
guardianBaseURL,
isMatch,
ophanComponentLink,
}: Props) => {
const hasImmersivePortraitTitleRule =
layoutType === 'immersivePortrait' &&
hasImmersiveGridTitleRule(format, tags);

return (
<div
data-link-name={ophanComponentLink}
css={[
[ArticleDesign.Gallery, ArticleDesign.HostedGallery].includes(
format.design,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export const SubNav = ({
data-src-focus-disabled={true}
css={subnavLinkStyles}
href={subNavSections.parent.url}
data-link-name={nestedOphanComponents(
'header',
'subnav',
subNavSections.parent.longTitle,
)}
>
{subNavSections.parent.title}
</a>
Expand Down
35 changes: 35 additions & 0 deletions dotcom-rendering/src/components/PuzzlesSupporting.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,38 @@ describe('PuzzlesUsefulLinks', () => {
description: 'News and clues',
};

it('tracks only configured Useful links, retaining displayed order and newsletter tracking', () => {
render(
<PuzzlesUsefulLinks
id="game"
title="Useful links"
links={supporting.usefulLinks}
ophanComponentName="puzzles-useful-links:puzzle-page"
newsletter={{
...newsletter,
exampleUrl: '/newsletter-preview',
}}
/>,
);
for (const [
index,
{ title, url },
] of supporting.usefulLinks.entries()) {
const link = screen.getByRole('link', { name: title });
expect(link).toHaveAttribute('href', url);
expect(link).toHaveAttribute(
'data-link-name',
`puzzles | useful-link | link-@${index + 1}`,
);
}
const preview = screen.getByRole('link', { name: 'Preview latest' });
expect(preview).not.toHaveAttribute('data-component');
expect(preview).toHaveAttribute(
'data-link-name',
'puzzles newsletter preview : cluesletter',
);
});

it('links to the latest edition when the newsletter has an example URL', () => {
render(
<PuzzlesUsefulLinks
Expand Down Expand Up @@ -164,6 +196,9 @@ describe('PuzzlesSupporting', () => {
expect(
screen.getByRole('link', { name: 'Help Centre' }),
).toHaveAttribute('href', 'https://help.theguardian.com');
expect(
screen.getByRole('link', { name: 'Help Centre' }),
).not.toHaveAttribute('data-link-name');
expect(
screen.getByRole('heading', {
level: 3,
Expand Down
10 changes: 9 additions & 1 deletion dotcom-rendering/src/components/PuzzlesSupporting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,31 @@ export const PuzzlesUsefulLinks = ({
title,
links,
newsletter,
ophanComponentName,
}: {
id: string;
title: string;
links: PuzzleLink[];
newsletter?: PuzzlesNewsletter;
ophanComponentName?: string;
}) => (
<section css={sectionStyles} aria-labelledby={`${id}-useful-links-title`}>
<h2 css={sectionTitleStyles} id={`${id}-useful-links-title`}>
{title}
</h2>
<div css={usefulContentStyles(newsletter !== undefined)}>
<div css={usefulGridStyles(newsletter !== undefined)}>
{links.map((link) => (
{links.map((link, index) => (
<a
css={usefulLinkStyles}
href={link.url}
key={`${link.title}-${link.url}`}
data-component={ophanComponentName}
data-link-name={
ophanComponentName !== undefined
? `puzzles | useful-link | link-@${index + 1}`
: undefined
}
{...externalProps(link.url)}
>
<h3 css={usefulLinkTitleStyles}>{link.title}</h3>
Expand Down
14 changes: 14 additions & 0 deletions dotcom-rendering/src/layouts/CrosswordLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ describe('CrosswordLayout useful links', () => {
'href',
'https://www.theguardian.com/crosswords/crossword-blog',
);
expect(
screen.getByRole('link', { name: 'Crossword blog' }),
).toHaveAttribute(
'data-component',
'puzzles-useful-links:crossword-page',
);
expect(screen.getByText('Sign up to Cluesletter')).toBeInTheDocument();
});

Expand Down Expand Up @@ -320,6 +326,14 @@ describe('CrosswordLayout Puzzle Page design (v1)', () => {
'href',
'/puzzles-and-games/crosswords/quick/archive',
);
const series = container.querySelector('a[data-component="series"]');
expect(series).toHaveAttribute('data-link-name', 'article series');
expect(
series?.parentElement?.closest('[data-link-name]'),
).toHaveAttribute(
'data-link-name',
'puzzles | in-page-nav | crossword-page',
);
});

it('points the title series link at the crosswords archive when frontend sends no archive page', () => {
Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/layouts/CrosswordLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export const CrosswordLayout = (props: Props) => {
<div data-print-layout="hide">
<ArticleTitle
format={format}
ophanComponentLink="puzzles | in-page-nav | crossword-page"
tags={titleTags}
sectionLabel={article.sectionLabel}
sectionUrl={
Expand Down Expand Up @@ -578,6 +579,7 @@ export const CrosswordLayout = (props: Props) => {
<div data-print-layout="hide">
<PuzzlesUsefulLinks
id="crossword"
ophanComponentName="puzzles-useful-links:crossword-page"
title="Useful links"
links={article.puzzlesSupporting.usefulLinks}
newsletter={article.puzzlesSupporting.newsletter}
Expand Down
44 changes: 44 additions & 0 deletions dotcom-rendering/src/layouts/PuzzlePageLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ describe('PuzzlePageLayout', () => {
expect(
container.querySelector('a[data-component="section"]'),
).toHaveAttribute('href', '/puzzles-and-games/logic-puzzles/archive');
for (const component of ['series', 'section']) {
const link = container.querySelector(
`a[data-component="${component}"]`,
);
expect(link).toHaveAttribute(
'data-link-name',
`article ${component}`,
);
expect(
link?.parentElement?.closest('[data-link-name]'),
).toHaveAttribute(
'data-link-name',
'puzzles | in-page-nav | puzzle-page',
);
}
});

/**
Expand All @@ -251,6 +266,14 @@ describe('PuzzlePageLayout', () => {
expect(
screen.getAllByRole('link', { name: 'Puzzles & games' }).length,
).toBeGreaterThan(0);
expect(
container.querySelector(
'[data-testid="sub-nav"] a[href="/puzzles-and-games"]',
),
).toHaveAttribute(
'data-link-name',
'header : subnav : Puzzles & games',
);

for (const href of Object.values(subNavChildHrefs)) {
expect(
Expand All @@ -261,6 +284,27 @@ describe('PuzzlePageLayout', () => {
}
});

it('attributes Useful links to the puzzle page', () => {
const page = createPuzzlePage('sudoku-easy');
renderPuzzlePageLayout('sudoku-easy', {
config: { ...page.config, edition: 'INT' },
instance: {
...page.instance,
puzzlesSupporting: {
usefulLinks: [
{
title: 'Puzzle help',
url: 'https://example.com/help',
},
],
},
},
});
expect(
screen.getByRole('link', { name: 'Puzzle help' }),
).toHaveAttribute('data-component', 'puzzles-useful-links:puzzle-page');
});

describe('sub-nav child links (Crosswords/Word games/Logic puzzles/Trivia & quizzes, v1-scoped feature)', () => {
it('does not render when v1 is not enabled', () => {
const { container } = renderPuzzlePageLayout('sudoku-easy', {
Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/layouts/PuzzlePageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ export const PuzzlePageLayout = ({
<GridItem area="title" element="aside">
<ArticleTitle
format={puzzlePageFormat}
ophanComponentLink="puzzles | in-page-nav | puzzle-page"
tags={puzzleFamilyTag}
sectionLabel={labelText}
sectionUrl={`puzzles-and-games/${puzzleGroupPath}/archive`}
Expand Down Expand Up @@ -884,6 +885,7 @@ export const PuzzlePageLayout = ({
<div data-print-layout="hide">
<PuzzlesUsefulLinks
id="puzzle-page"
ophanComponentName="puzzles-useful-links:puzzle-page"
title="Useful links"
links={instance.puzzlesSupporting.usefulLinks}
newsletter={instance.puzzlesSupporting.newsletter}
Expand Down
Loading