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-1244 P2 video promos have no heading semantics #11735

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
565 changes: 413 additions & 152 deletions data/pidgin/homePage/index.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/app/components/Curation/CurationGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { CurationGridProps } from '../types';

const CurationGrid = ({
summaries,
headingLevel,
isFirstCuration,
headingLevel,
}: CurationGridProps) => {
const hasMultiplePromos = summaries.length > 1;
const firstPromo = summaries[0];
Expand All @@ -27,8 +27,8 @@ const CurationGrid = ({
<li css={styles.item} key={promo.id}>
<CurationPromo
{...promo}
headingLevel={headingLevel}
lazy={lazyLoadImages}
headingLevel={headingLevel}
/>
</li>
);
Expand All @@ -38,8 +38,8 @@ const CurationGrid = ({
<div css={styles.item}>
<CurationPromo
{...firstPromo}
headingLevel={headingLevel}
lazy={!isFirstCuration}
headingLevel={headingLevel}
/>
</div>
)}
Expand Down
112 changes: 112 additions & 0 deletions src/app/components/Curation/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,117 @@ describe('Curation', () => {

expect(document.querySelectorAll('section h2').length).toBe(1);
});

it('should have h3 summary titles when page has multiple curations and a curation title', () => {
const { summaries } = mundoFixture.data.curations[1];

render(
<Curation
title="2nd Curation"
visualProminence={NORMAL}
visualStyle={NONE}
position={1}
summaries={summaries}
curationLength={2}
/>,
);
expect(document.querySelectorAll('h3').length).toBe(4);
});

it('should have h3 summary titles when page has multiple curations and no curation title and is the first curation - simple curation', () => {
const { summaries } = mundoFixture.data.curations[0];

render(
<Curation
visualProminence={NORMAL}
visualStyle={NONE}
position={0}
summaries={summaries}
curationLength={2}
/>,
);
expect(document.querySelectorAll('h3').length).toBe(8);
});

it('should have h3 summary titles when page has multiple curations and no curation title and is the first curation - hierarchical curation', () => {
const { summaries } = mundoFixture.data.curations[0];

render(
<Curation
visualProminence={HIGH}
visualStyle={NONE}
position={0}
summaries={summaries}
curationLength={2}
/>,
);
expect(document.querySelectorAll('h3').length).toBe(8);
});

it('should have h2 summary titles when page has one curation - somple curation', () => {
const { summaries } = fixture.data.curations[0];

render(
<Curation
visualProminence={NORMAL}
visualStyle={NONE}
position={0}
summaries={summaries}
curationLength={1}
/>,
);
expect(document.querySelectorAll('h2').length).toBe(24);
expect(document.querySelectorAll('h3').length).toBe(0);
});

it('should have h2 summary titles when page has one curation - hierarchical curation', () => {
const { summaries } = fixture.data.curations[0];

render(
<Curation
visualProminence={HIGH}
visualStyle={NONE}
position={0}
summaries={summaries}
curationLength={1}
/>,
);
expect(document.querySelectorAll('h2').length).toBe(12);
expect(document.querySelectorAll('h3').length).toBe(0);
});

it('should have visually hidden title text as h2 if it is the first curation of multiple and has a title - simple curation', () => {
const { summaries } = mundoFixture.data.curations[0];

render(
<Curation
title="First Curation"
visualProminence={NORMAL}
visualStyle={NONE}
position={0}
summaries={summaries}
curationLength={6}
/>,
);
expect(document.querySelectorAll('h2').length).toBe(1); // the visually hidden h2 heading
expect(document.querySelectorAll('h3').length).toBe(8); // the visible h3 promos
});

it('should have visually hidden title text as h2 if it is the first curation of multiple and has a title - hierarchial curation', () => {
const { summaries } = mundoFixture.data.curations[0];

render(
<Curation
title="First Curation"
visualProminence={HIGH}
visualStyle={NONE}
position={0}
summaries={summaries}
curationLength={6}
/>,
);
expect(document.querySelectorAll('h2').length).toBe(1); // the visually hidden h2 heading
expect(document.querySelectorAll('h3').length).toBe(8); // the visible h3 promos
});
});
});
46 changes: 22 additions & 24 deletions src/app/components/Curation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default ({
title = '',
topStoriesTitle = '',
link = '',
headingLevel = 2,
LilyL0u marked this conversation as resolved.
Show resolved Hide resolved
position = 0,
curationLength = 0,
mostRead,
Expand All @@ -63,7 +62,6 @@ export default ({
radioSchedule,
embed,
});

const GridComponent = getGridComponent(componentName);

const isFirstCuration = position === 0;
Expand Down Expand Up @@ -143,31 +141,31 @@ export default ({
case SIMPLE_CURATION_GRID:
case HIERARCHICAL_CURATION_GRID:
default:
return curationLength > 1 &&
summaries.length > 0 &&
(title || isFirstCuration) ? (
<section aria-labelledby={id} role="region">
{isFirstCuration ? (
<VisuallyHiddenText id={id} as="h2">
{curationSubheading}
</VisuallyHiddenText>
) : (
<Subheading id={id} link={link}>
{curationSubheading}
</Subheading>
)}
if (summaries.length > 0) {
return curationLength > 1 && (title || isFirstCuration) ? (
<section aria-labelledby={id} role="region">
{isFirstCuration ? (
<VisuallyHiddenText id={id} as="h2">
{curationSubheading}
</VisuallyHiddenText>
) : (
<Subheading id={id} link={link}>
{curationSubheading}
</Subheading>
)}
<GridComponent
summaries={summaries}
headingLevel={3} // if there are multiple curations, each curation's heading will be h2 and the promos within will be h3
/>
</section>
) : (
<GridComponent
summaries={summaries}
headingLevel={isFirstCuration ? 3 : headingLevel}
headingLevel={2} // if there is only one curation, all promos should be h2
isFirstCuration={isFirstCuration}
/>
</section>
) : (
<GridComponent
summaries={summaries}
headingLevel={headingLevel}
isFirstCuration={isFirstCuration}
/>
);
);
}
return null;
}
};
1 change: 0 additions & 1 deletion src/app/models/types/curationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export interface BaseCuration {
}

export interface Curation extends BaseCuration {
headingLevel?: number;
topStoriesTitle?: string;
curationLength?: number;
nthCurationByStyleAndProminence?: number;
Expand Down
1 change: 0 additions & 1 deletion src/app/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ const HomePage = ({ pageData }: HomePageProps) => {
return (
<React.Fragment key={`${curationId}-${position}`}>
<HomeCuration
headingLevel={curationTitle ? 3 : 2}
visualStyle={visualStyle as VisualStyle}
visualProminence={visualProminence as VisualProminence}
summaries={summaries || []}
Expand Down
12 changes: 12 additions & 0 deletions src/app/pages/HomePage/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BrowserRouter } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import { data as kyrgyzHomePageData } from '#data/kyrgyz/homePage/index.json';
import { data as afriqueHomePageDataFixture } from '#data/afrique/homePage/index.json';
import { data as pidginHomePageDataFixture } from '#data/pidgin/homePage/index.json';
import { render } from '../../components/react-testing-library-with-providers';
import HomePage from './HomePage';
import { suppressPropWarnings } from '../../legacy/psammead/psammead-test-helpers/src';
Expand Down Expand Up @@ -49,6 +50,17 @@ describe('Home Page', () => {
);
});

it('should have h2s for curation heading levels and h3 for summary heading levels', () => {
const { container } = render(
<HomePage pageData={pidginHomePageDataFixture} />,
{
service: 'pidgin',
},
);
expect(container.querySelectorAll('h2').length).toBe(5);
expect(container.querySelectorAll('h3').length).toBe(27);
});

it('should apply provided margin size to the main element', () => {
// @ts-expect-error suppress pageData prop type conflicts due to missing imageAlt on selected historical test data for curations
const { getByRole } = render(<HomePage pageData={homePageData} />, {
Expand Down
2 changes: 0 additions & 2 deletions src/app/pages/TopicPage/TopicPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ const TopicPage = ({ pageData }) => {
visualStyle,
visualProminence,
});

return (
<React.Fragment key={`${curationId}-${position}`}>
<Curation
headingLevel={curationTitle && 3}
visualStyle={visualStyle}
visualProminence={visualProminence}
summaries={summaries}
Expand Down
Loading
Loading