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

WSTEAMA-1129 Unordered list items in the footer component should not render empty li elements, or have a role="listitem" #12286

Merged
merged 12 commits into from
Jan 20, 2025
Merged
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
4 changes: 1 addition & 3 deletions src/app/components/Footer/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export default ({
)}
{elements.map((elem, index) => (
// eslint-disable-next-line react/no-array-index-key
<li key={index} role="listitem">
{elem}
</li>
<li key={index}>{elem}</li>
))}
</ul>
);
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/Footer/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ describe('Footer', () => {
'#',
);
});

it('should not render an empty list item when the "Do not share or sell my info" link is not present', () => {
render(<Footer />, { showAdsBasedOnLocation: false });
const listItems = screen.getAllByRole('listitem');
listItems.forEach(listItem => {
expect(listItem).not.toBeEmptyDOMElement();
});
});
});

describe('Collective News Text', () => {
Expand Down
58 changes: 30 additions & 28 deletions src/app/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,38 @@ export default () => {
collectiveNewsroomText,
} = footer;

const elements = links?.map(({ id, text, href, lang }) => {
if (id === 'COOKIE_SETTINGS') {
if (isAmp) {
return (
// @ts-expect-error we do not have a className
<AmpCookieSettingsButton
lang={lang}
css={styles.ampCookieSettingButton}
>
{text}
</AmpCookieSettingsButton>
);
}
const elements = links
?.map(({ id, text, href, lang }) => {
if (id === 'COOKIE_SETTINGS') {
if (isAmp) {
return (
// @ts-expect-error we do not have a className
<AmpCookieSettingsButton
lang={lang}
css={styles.ampCookieSettingButton}
>
{text}
</AmpCookieSettingsButton>
);
}

if (showAdsBasedOnLocation) {
return (
<Link
text={text}
href={href}
lang={lang}
onClick={openPrivacyManagerModal}
onlyShowIfJSenabled
/>
);
if (showAdsBasedOnLocation) {
return (
<Link
text={text}
href={href}
lang={lang}
onClick={openPrivacyManagerModal}
onlyShowIfJSenabled
/>
);
}
} else {
return <Link text={text} href={href} lang={lang} />;
}
} else {
return <Link text={text} href={href} lang={lang} />;
}
return null;
});
return null;
})
.filter(Boolean);
Copy link
Contributor Author

@LilyL0u LilyL0u Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is the only code change here in this file. The rest is formatting.


return (
<div css={styles.siteWideLinksWrapper}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,13 +1006,13 @@ exports[`PageLayoutWrapper should render default page wrapper with children 1`]

@media (min-width: 15rem) and (max-width: 37.4375rem) {
.emotion-151 {
grid-template-rows: repeat(5, auto);
grid-template-rows: repeat(4, auto);
}
}

@media (min-width: 37.5rem) and (max-width: 62.9375rem) {
.emotion-151 {
grid-template-rows: repeat(4, auto);
grid-template-rows: repeat(3, auto);
}
}

Expand Down Expand Up @@ -1637,69 +1637,54 @@ exports[`PageLayoutWrapper should render default page wrapper with children 1`]
Why you can trust the BBC
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-153"
href="https://www.bbc.com/terms"
>
Terms of Use
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-153"
href="https://www.bbc.co.uk/aboutthebbc/"
>
About the BBC
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-153"
href="https://www.bbc.com/privacy/"
>
Privacy Policy
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-153"
href="https://www.bbc.com/usingthebbc/cookies/"
>
Cookies
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-153"
href="https://www.bbc.com/accessibility/"
>
Accessibility Help
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-153"
href="https://www.bbc.com/contact/"
>
Contact the BBC
</a>
</li>
<li
role="listitem"
/>
</ul>
<p
class="emotion-160"
Expand Down
31 changes: 8 additions & 23 deletions src/app/legacy/containers/Footer/__snapshots__/index.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ exports[`FooterContainer snapshots should render correctly 1`] = `

@media (min-width: 15rem) and (max-width: 37.4375rem) {
.emotion-14 {
grid-template-rows: repeat(5, auto);
grid-template-rows: repeat(4, auto);
}
}

@media (min-width: 37.5rem) and (max-width: 62.9375rem) {
.emotion-14 {
grid-template-rows: repeat(4, auto);
grid-template-rows: repeat(3, auto);
}
}

Expand Down Expand Up @@ -415,69 +415,54 @@ exports[`FooterContainer snapshots should render correctly 1`] = `
Why you can trust the BBC
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-16"
href="https://www.bbc.com/terms"
>
Terms of Use
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-16"
href="https://www.bbc.co.uk/aboutthebbc/"
>
About the BBC
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-16"
href="https://www.bbc.com/privacy/"
>
Privacy Policy
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-16"
href="https://www.bbc.com/usingthebbc/cookies/"
>
Cookies
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-16"
href="https://www.bbc.com/accessibility/"
>
Accessibility Help
</a>
</li>
<li
role="listitem"
>
<li>
<a
class="focusIndicatorInvert emotion-16"
href="https://www.bbc.com/contact/"
>
Contact the BBC
</a>
</li>
<li
role="listitem"
/>
</ul>
<p
class="emotion-23"
Expand Down
Loading